ROS与SLAM入门教程-cartographer在Turltlebot的应用3-构建地图
ROS与SLAM入门教程-cartographer在Turltlebot的应用3-构建地图
说明:
- 介绍在Turtlebot上实现cartographer slam算法的kinect 2d和雷达构建地图。
安装步骤:
- 安装cartographer_turltlebot
- 参考:turtlebot入门教程-cartographer在Turltlebot的应用1
测试kinect 2d建图
- 配置install_isolated/share/cartographer_turtlebot/launch/turtlebot.launch
- 在
</launch>
前增加如下代码:
<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer_turtlebot
)/configuration_files/demo_turtlebot.rviz" />
用于启动rviz,查看实时建图情况。
新终端启动turtlebot_depth_camera_2d.launch
$ roslaunch cartographer_turtlebot turtlebot_depth_camera_2d.launch
- 这个文件已经包含启动roscore等所需的文件。
- 移动建图,小房间就直接推着走一圈,完成建图。也可以启动远程控制建图。
- 新终端,完成建图后保存地图,实际路径是:/home/user/map/
$ mkdir -p ~/map
$ rosrun map_server map_saver -f ~/map/kinect_2d_carto
$ ls ~/map #查看内容,包含kinect_2d_carto.pgm kinect_2d_carto.yaml
- 效果图:
测试雷达建图
- 增加turtlebot_lidar.launch
cd ~/carto_ws/install_isolated/share/cartographer_turtlebot/launch
touch turtlebot_lidar.launch
vim turtlebot_lidar.launch
- 代码如下:
<launch>
<arg name="configuration_basename"/>
<include file="$(find turtlebot_bringup)/launch/minimal.launch" />
<node name="cartographer_node" pkg="cartographer_ros"
type="cartographer_node" args="
-configuration_directory
$(find cartographer_turtlebot)/configuration_files
-configuration_basename $(arg configuration_basename)"
output="screen">
<remap from="scan" to="/scan" />
</node>
<node name="flat_world_imu_node" pkg="cartographer_turtlebot"
type="cartographer_flat_world_imu_node" output="screen">
<remap from="imu_in" to="/mobile_base/sensors/imu_data_raw" />
<remap from="imu_out" to="/imu" />
</node>
<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer_turtlebot
)/configuration_files/demo_turtlebot.rviz" />
</launch>
- 增加雷达启动文件,测试使用F4雷达,代码如下:
<launch>
<node name="flashgo_node" pkg="flashgo" type="flashgo_node" output="screen">
<param name="serial_port" type="string" value="/dev/flashlidar"/>
<param name="serial_baudrate" type="int" value="115200"/>
<param name="frame_id" type="string" value="laser"/>
<param name="angle_compensate" type="bool" value="true"/>
<param name="ignore_array" type="string" value="" />
<param name="ignore_value" type="double" value="0" />
</node>
<node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.0 0.18 3.14 3.14 0.0 base_link laser 200"/>
</launch>
其他雷达类似,可以参考本站的专栏:ROS与激光雷达
新增启动文件turtlebot_flashlidar_2d.launch:
cd ~/carto_ws/install_isolated/share/cartographer_turtlebot/launch
touch turtlebot_lidar_2d.launch
vim turtlebot_lidar_2d.launch
- 代码如下:
<launch>
<include file="$(find cartographer_turtlebot)/launch/turtlebot_lidar.launch">
<arg name="configuration_basename" value="turtlebot_urg_lidar_2d.lua" />
</include>
</launch>
- 新终端,启动雷达:
$ roslaunch turtlebot_navigation flashlidar_laser.launch
- 新终端,启动建图:
$ roslaunch cartographer_turtlebot turtlebot_lidar_2d.launch
- 会自动打开RViz查看实时情况。
- 移动建图,移动turtlebot走圈完成建图,也可以远程控制
- 新终端,完成建图后保存地图,实际路径是:/home/user/map/
$ mkdir -p ~/map
$ rosrun map_server map_saver -f ~/map/lidar_2d_carto
$ ls ~/map #查看内容,包含lidar_2d_carto.pgm lidar_2d_carto.yaml
- 效果图:
参考:
- 官方安装:https://google-cartographer-ros-for-turtlebots.readthedocs.io/en/latest/
- http://blog.exbot.net/archives/2852
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号