环境:ubuntu22.04+ROS2 humble,事先已安装gazebo
一、准备工作
安装turtlebot3功能包
mkdir -p ~/turtlebot3_ws_my/src
cd ~/turtlebot3_ws_my/src/
git clone -b humble-devel https://github.com/ROBOTIS-GIT/DynamixelSDK.git
git clone -b humble-devel https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
git clone -b humble-devel https://github.com/ROBOTIS-GIT/turtlebot3.git
git clone -b humble-devel https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
编译
cd ..
colcon build --symlink-install
添加环境变量
echo 'source ~/turtlebot3_ws_my/install/setup.bash' >> ~/.bashrc
echo 'export ROS_DOMAIN_ID=30 #TURTLEBOT3' >> ~/.bashrc
echo 'export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/turtlebot3_ws_my/src/turtlebot3/turtlebot3_simulations/turtlebot3_gazebo/models' >> ~/.bashrc
echo 'export TURTLEBOT3_MODEL=burger' >> ~/.bashrc
source ~/.bashrc
二、建图
启动仿真环境
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
打开rviz2准备绘图
ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=True
启动键盘控制
ros2 run turtlebot3_teleop teleop_keyboard
保存地图
ros2 run nav2_map_server map_saver_cli -f ~/路径/地图名称
三、导航
启动仿真环境
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
导航(使用刚才保存的地图)
ros2 launch turtlebot3_navigation2 navigation2.launch.py use_sim_time:=true map:=路径/地图名称.yaml
在rviz2可视化界面,先用2D Pose Estimate进行位姿估计,然后用Nav2 Goal选择目标点的位姿进行导航。
-----------------------------------------------------------------------------------------------
注意:在建图或导航过程中,每新开一个终端都需要先编译,编译命令如下
colcon build --symlink-install