本文记录在之前已经安装完毕cartographer的workspace的基础上安装turtlebot3完整开发仿真环境的过程。
已经按照https://blog.csdn.net/m0_71775106/article/details/127707299文章的说明安装完成了相应的ros环境配置和cartographer。
cd ~/carto_ws/src
git clone https://github.com/ROBOTIS-GIT/turtlebot3.git
git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
cd ..
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
catkin_make_isolated
echo “export SVGA_VGPU10=0” >> ~/.bashrc
source ~/.bashrc
新建一个Terminal窗口,输入如下命令:
source ~/carto_ws/devel_isolated/setup.bash
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_gazebo turtlebot3_state_4.launch
新建一个Terminal窗口,运行如下命令
source ~/carto_ws/devel_isolated/setup.bash
export TURTLEBOT3_MODEL=burger
roslaucn turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer configuration_basename:=turtlebot3_lds_2d_gazebo.lua
在使用gazebo仿真环境的时候,算法配置文件需要使用turtlebot3_lds_2d_gazebo.lua,而非turtlebot3_lds_2d.lua文件,两者区别如下:
22c22
< tracking_frame = "imu_link", -- imu_link, If you are using gazebo, use 'base_footprint' (libgazebo_ros_imu's bug)
---
> tracking_frame = "base_footprint", -- imu_link, If you are using gazebo, use 'base_footprint' (libgazebo_ros_imu's bug)
39c39
< odometry_sampling_ratio = 0.1,
---
> odometry_sampling_ratio = 1.,
41c41
< imu_sampling_ratio = 0.1,
---
> imu_sampling_ratio = 1.,
新建一个Terminal窗口,运行如下命令打开键盘控制界面,可以通过键盘控制机器人进行移动,从而完成建图。
source ~/carto_ws/devel_isolated/setup.bash
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
当地图建立完整后,新建一个Terminal串口,运行如下命令,保存地图:
source ~/carto_ws/devel_isolated/setup.bash
export TURTLEBOT3_MODEL=burger
# Finish the trajectory before saving the map
rosservice call /finish_trajectory 0
# Save the pbstream to a local file
rosservice call /write_state "{filename: '/home//turtlebot3_cartographer_stage_4.pbstream', include_unfinished_submaps: true}"
# Convert the pbstream format to ros map format (pgm and yaml)
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=/home/<username>/turtlebot3_cartographer_stage_4 -pbstream_filename=/home/<username>/turtlebot3_cartographer_stage_4.pbstream -resolution=0.05
新建文件,~/carto_ws/src/turtlebot3/turtlebot3_slam/config/turtlebot3_lds_2d_gazebo_localization.lua,输入如下内容:
include "turtlebot3_lds_2d_gazebo.lua"
--TRAJECTORY_BUILDER.pure_localization = true
TRAJECTORY_BUILDER.pure_localization_trimmer = {
max_submaps_to_keep = 3,
}
POSE_GRAPH.optimize_every_n_nodes = 50
return options
新建文件,~/carto_ws/src/turtlebot3/turtlebot3_slam/launch/turtlebot3_cartographer_localization.launch,输入如下内容(将其中
新建一个Terminal,输入如下命令:
source ~/carto_ws/devel_isolated/setup.bash
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_slam turtlebot3_cartographer_localization.launch slam_methods:=cartographer
运行如下命令,可以打开节点关系图进行查看。
rqt_graph
在目前的ros开发环境,可以轻松的安装其他算法包,这里简单列出几个。
cd ~/carto_ws/src
git clone -b melodic-devel https://github.com/husky/husky.git
cd ..
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
catkin_make_isolated
echo “export SVGA_VGPU10=0” >> ~/.bashrc
source ~/.bashrc
cd ~/carto_ws/src
git clone -b melodic-devel https://github.com/husky/husky-cartographer.git
cd ..
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
catkin_make_isolated
source ~/carto_ws/devel_isolated/setup.bash
export HUSKY_URDF_EXTRAS=$(rospack find husky_description)/urdf/empty.urdf
roslaunch husky_gazebo husky_empty_world.launch
roslaunch teleop_twist_joy teleop.launch
cd ~/carto_ws/src
git clone https://github.com/HKUST-Aerial-Robotics/gnss_comm.git
git clone https://github.com/HKUST-Aerial-Robotics/GVINS.git
cd ..
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
catkin_make_isolated
source ~/carto_ws/devel_isolated/setup.bash
roslaunch gvins visensor_f9p.launch
rviz -d ~/carto_ws/src/GVINS/config/gvins_rviz_config.rviz
rosbag play sports_field.bag
上述命令中,rosbag回放文件可以从https://github.com/HKUST-Aerial-Robotics/GVINS-Dataset下载。