10. turtlebot仿真(利用cartographer_ros替换karto)
参考链接
https://blog.csdn.net/qq_34935373/article/details/111991920
https://www.freesion.com/article/9794248452/
10.1. 官方纯定位Pure localization仿真测试
10.1.1. 下载数据集
wget -P mnt/e/wsl/cartographer_demo/pureLoc/ https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/b2-2016-04-05-14-44-52.bag
wget -P mnt/e/wsl/cartographer_demo/pureLoc/ https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/b2-2016-04-27-12-31-41.bag
第一个用于建图,第二个用于定位。
10.1.2. 建图
自己的路径:
roslaunch cartographer_ros offline_backpack_2d.launch bag_filenames:=/mnt/e/wsl/cartographer_demo/pureLoc/b2-2016-04-05-14-44-52.bag
生成.pbstream
的地图文件.
10.1.3. 定位
自己的路径:
roslaunch cartographer_ros demo_backpack_2d_localization.launch \
load_state_filename:=/mnt/e/wsl/cartographer_demo/pureLoc/b2-2016-04-05-14-44-52.bag.pbstream \
bag_filename:=/mnt/e/wsl/cartographer_demo/pureLoc/b2-2016-04-27-12-31-41.bag
这里第一个参数是用的地图,第二个参数是下载的数据集进行定位测试。
10.2. turtlebot3仿真建图
-
首先修改
/opt/ros/melodic/share/turtlebot3_slam/config/turtlebot3_lds_2d.lua
中的tracking_frame = "base_footprint"
-
然后执行:
roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer
-
保存地图,参考https://google-cartographer-ros.readthedocs.io/en/latest/assets_writer.html:
rosservice call /write_state /mnt/e/wsl/maps/carto.pbstream 1
rosrun map_server map_saver -f /mnt/e/wsl/maps/carto
写的地图数据可以通过assets_writer_backpack_3d.lua
来进行配置。
- pbstream转pgm地图:
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=${HOME}/Downloads/mymap -pbstream_filename=${HOME}/Downloads/mymap.pbstream -resolution=0.05
10.3. turtlebot3仿真导航
[关键]上个步骤中实际已经启动了move_base节点,可以一边扫图一边导航控制。具体可查看turtlebot3_cartographer.launch文件。
10.3.1. turtlebot3_cartographer.launch最终文件
在建图和导航时,分别注释掉相关部分即可。
建图和导航的指令均为:roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer
<launch>
<!-- Arguments -->
<arg name="model" default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]"/>
<arg name="configuration_basename" default="turtlebot3_lds_2d.lua"/>
<arg name="map_file" default="/mnt/e/wsl/maps/carto.yaml"/>
<arg name="load_state_filename" default="/mnt/e/wsl/maps/carto.pbstream"/>
<!-- move_base -->
<include file="$(find turtlebot3_navigation)/launch/move_base.launch">
<arg name="model" value="$(arg model)" />
</include>
<!-- cartographer_node 只有在建图的时候打开-->
<node pkg="cartographer_ros" type="cartographer_node" name="cartographer_node"
args="-configuration_directory $(find turtlebot3_slam)/config
-configuration_basename $(arg configuration_basename)"
output="screen">
<remap from="/imu" to="/flat_imu"/>
</node>
<!-- cartographer_occupancy_grid_node 只有在建图的时候打开-->
<node pkg="cartographer_ros" type="cartographer_occupancy_grid_node"
name="cartographer_occupancy_grid_node"
args="-resolution 0.05" />
<!-- Map server 建图的时候屏蔽该节点,只在导航时候打开
<node pkg="map_server" name="map_server" type="map_server" args="$(arg map_file)"/>-->
<!-- cartographer_node 只在导航时候打开
<node pkg="cartographer_ros" type="cartographer_node" name="cartographer_node"
args="-configuration_directory $(find turtlebot3_slam)/config
-configuration_basename $(arg configuration_basename)
-load_state_filename $(arg load_state_filename)"
output="screen">
<remap from="/imu" to="/flat_imu"/>
</node>-->
<!-- flat_world_imu_node -->
<node pkg="turtlebot3_slam" type="flat_world_imu_node" name="flat_world_imu_node" output="screen">
<remap from="imu_in" to="/imu" />
<remap from="imu_out" to="/flat_imu" />
</node>
</launch>