실습 환경 구축 및 시뮬레이션 환경 열기


  1. 워크스페이스 내에 필요한 리소스 가져오기

    cd ~/nav2_ws/src
    git clone <https://github.com/Adlink-ROS/ros2_object_msgs.git>
    git clone <https://github.com/Adlink-ROS/BT_ros2.git>
    
  2. 워크스페이스 내 패키지 빌드

    cd ~/nav2_ws
    colcon build --symlink-install --packages-select object_msgs
    source ~/nav2_ws/install/local_setup.bash
    
    rosdep install --from-paths src/BT_ros2 --ignore-src -r -y
    colcon build --symlink-install --packages-select bt_ros2
    source ~/nav2_ws/install/local_setup.bash
    
  3. mememan_world.model 환경을 사용하기 위해 파일 수정

  4. 시뮬레이션 환경 열기

    # terminal 1
    ros2 launch neuronbot2_gazebo neuronbot2_world.launch.py
    
    # terminal 2
    ros2 launch neuronbot2_nav bringup_launch.py use_sim_time:=true
    

[실습 1] 정해진 경유지 반복하여 방문하기


ros2 launch bt_ros2 bt_ros2.launch.py
<root main_tree_to_execute = "MainTree">
    <BehaviorTree ID="MainTree">
        <Repeat num_cycles="3">
            <Sequence>
                <!-- The goal value="position-x;position-y;orientaion-z;orientation-w" -->
                <SetBlackboard output_key="Goal_a" value="-0.579;-1.341;0.0;1.0" />
                <SetBlackboard output_key="Goal_b" value="5.214;-1.533;0.0;1.0" />
                <SetBlackboard output_key="Goal_c" value="-1.588;1.253;0.0;1.0" />
                <Sequence>
                    <SubTree ID="MoveRobot" target="Goal_a" />
                    <SubTree ID="MoveRobot" target="Goal_b" />
                    <SubTree ID="MoveRobot" target="Goal_c" />
                </Sequence>
            </Sequence>
        </Repeat>
    </BehaviorTree>

    <BehaviorTree ID="MoveRobot">
        <Sequence name="SetGoal">
            <Nav2Client goal="{target}" />
        </Sequence>
    </BehaviorTree>
</root>

Untitled

[실습 2] InterruptEvent 활용


# terminal 1
ros2 run bt_ros2 bt_ros2 --ros-args -p bt_xml:=$HOME/nav2_ws/src/BT_ros2/bt_xml/bt_nav_mememan_interrupt.xml

# terminal 2
ros2 topic pub -1 /interrupt_event std_msgs/msg/String data:\\ \\'gohome\\'
<root main_tree_to_execute = "MainTree">
    <BehaviorTree ID="MainTree">
        <Sequence>
            <SetBlackboard output_key="Goal_a" value="-0.579;-1.341;0.0;1.0" />
            <SetBlackboard output_key="Goal_b" value="5.214;-1.533;0.0;1.0" />
            <SetBlackboard output_key="Goal_c" value="-1.588;1.253;0.0;1.0" />
            <Fallback>
                <ReactiveSequence>
                    <InterruptEvent event="gohome"/>
                    <Repeat num_cycles="10">
                        <Sequence>
                            <SubTree ID="MoveRobot" target="Goal_a" />
                            <SubTree ID="MoveRobot" target="Goal_b" />
                        </Sequence>
                    </Repeat>
                </ReactiveSequence>
                <Sequence>
                    <SubTree ID="MoveRobot" target="Goal_c" />
                </Sequence>
            </Fallback>
        </Sequence>
    </BehaviorTree>

    <BehaviorTree ID="MoveRobot">
        <Sequence name="SetGoal">
            <Nav2Client goal="{target}" />
        </Sequence>
    </BehaviorTree>
</root>