cartographer仿真建图

进入cartographer安装的工作空间,激活环境

1
2
cd ~/catkin_cartographer/
source install_isolated/setup.bash

创建文件cartographer_demo_rplidar.launch

1
2
3
cd ~/catkin_cartographer/src/cartographer_ros/cartographer_ros/launch
cp demo_revo_lds.launch cartographer_demo_rplidar.launch
gedit cartographer_demo_rplidar.launch

并修改为以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<launch>  

<param name="/use_sim_time" value="true" />

<node name="cartographer_node" pkg="cartographer_ros"
type="cartographer_node" args="
-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename rplidar.lua"
output="screen">
<remap from="scan" to="scan" />
</node>

<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" />
</launch>

创建文件rplidar.lua

1
2
3
cd ~/catkin_cartographer/src/cartographer_ros/cartographer_ros/configuration_files
cp revo_lds.lua rplidar.lua
gedit rplidar.lua

修改字段如下:
tracking_frame = “laser_link”,
published_frame = “laser_link”,

配置文件修改后,需要重新编译cartographer

1
2
cd ~/catkin_cartographer
catkin_make_isolated --install --use-ninja

启动仿真平台

启动仿真平台

打开新的终端,启动Cartographer

1
2
3
cd ~/catkin_cartographer
source install_isolated/setup.bash
roslaunch cartographer_ros cartographer_demo_rplidar.launch

打开新的终端,启动键盘控制,控制机器人移动

键盘控制仿真机器人移动建图

打开新的终端,保存地图

建图完成,保存地图
停止地图构建

1
rosservice call /finish_trajectory 0

生成.pbstream文件,文件名及其路径可修改,以下代码是我个人目录
1
rosservice call /write_state /home/qiang/Documents/museum.pbstream false

使用catro提供文件,将.pbstream文件转为.yaml和.pgm文件
1
2
3
4
cd ~/catkin_cartographer
source install_isolated/setup.bash
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=/home/qiang/Documents/museum -pbstream_filename=/home/qiang/Documents/map/museum.pbstream -resolution=0.05


执行完成后,将在相应目录下生成 .yaml和.pgm文件
参考文章


cartographer仿真建图
https://qiangsun89.github.io/2023/03/16/cartographer仿真建图/
作者
Qiang Sun
发布于
2023年3月16日
许可协议