워크스페이스 내에 필요한 리소스 가져오기
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>
워크스페이스 내 패키지 빌드
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
mememan_world.model
환경을 사용하기 위해 파일 수정
~/nav2_ws/src/neuronbot2/neuronbot2_gazebo/launch/**neuronbot2_world.launch.py**
...
world = os.path.join(
**get_package_share_directory('neuronbot2_gazebo'),**
'worlds',
**'mememan_world.model'**
)
...
~/nav2_ws/src/neuronbot2/neuronbot2_nav/launch/**bringup_launch.py**
...
**my_map_file = 'mememan.yaml'**
...
시뮬레이션 환경 열기
# terminal 1
ros2 launch neuronbot2_gazebo neuronbot2_world.launch.py
# terminal 2
ros2 launch neuronbot2_nav bringup_launch.py use_sim_time:=true
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>
# 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>