Using SLAM algorithms on a bagfile
Kinetic, Linux 16.04
Goal
I've bagfiled an experiment of Gmapping with a turtlebot, and want to unleash the Cartographer algorithm on this bagfile.
Code
turtlebot_gmapping.launch, used in the experiment:
<?xml version="1.0"?>
<launch>
<arg name="record" default="False" doc="Record results in a bag file"/>
<arg name="play" default="False" doc="Play recorded bag file"/>
<arg name="bagfile" default="" doc="Play recorded bag file"/>
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find turtlebot3_slam)/rviz/turtlebot3_slam.rviz" />
<param name="use_sim_time" value="false"/>
<group unless="$(arg play)">
<include file="$(find turtlebot3_teleop)/launch/turtlebot3_teleop_key.launch"/>
<include file="$(find turtlebot3_slam)/launch/turtlebot3_slam.launch"/>
</group>
<group if="$(arg play)">
<node pkg="rosbag" type="play" name="rosbag_play" args="$(env HOME)/catkin_ws/src/thesis/$(arg bagfile) /cmd_vel:=/cmd_vel_dev_null"/>
<param name="use_sim_time" value="true"/>
</group>
<group if="$(arg record)">
<node pkg="rosbag" type="record" name="rosbag_record" args="record -a -o $(env HOME)/catkin_ws/src/thesis/bagfiles/"/>
<param name="use_sim_time" value="false"/>
</group>
</launch>
turtlebot_cartographer.launch, used on the bagfile of the gmapping experiment:
<?xml version="1.0"?>
<launch>
<arg name="record" default="False" doc="Record results in a bag file"/>
<arg name="play" default="False" doc="Play recorded bag file"/>
<arg name="bagfile" default="" doc="Play recorded bag file"/>
<include file="$(find turtlebot3_bringup)/launch/turtlebot3_remote.launch"/>
<node name="cartographer_offline_node" pkg="cartographer_ros"
type="cartographer_node" args="
-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename Turtlebot.lua"
output="screen">
</node>
<node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"
type="cartographer_occupancy_grid_node" args="-resolution 0.05" >
</node>
<param name="use_sim_time" value="true"/>
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find turtlebot3_slam)/rviz/turtlebot3_slam.rviz" />
<group if="$(arg record)">
<node pkg="rosbag" type="record" name="rosbag_record" args="record -a $(env HOME)/catkin_ws/src/thesis/bagfiles/"/>
<param name="use_sim_time" value="false"/>
</group>
<group if="$(arg play)">
<node pkg="rosbag" type="play" name="rosbag_play" args="$(env HOME)/catkin_ws/src/thesis/$(arg bagfile) /cmd_vel:=/cmd_vel_dev_null"/>
<param name="use_sim_time" value="true"/>
</group>
</launch>
I only want to keep the experiment's sensory data, not its map-making bits, so that Cartographer can use this, and produce its own map.
Filter the gmapping experiment bagfile
I use rosbag filter 2018-04-23-10-48-44.bag filter.bag "topic=='/joi
nt_states' or topic=='/imu' or topic=='/odom' or topic=='/scan' or topic=='/rpms' or topic=='/tf_static'"
Now it should have all the things it needs. Sensory data; /joint_states
which is a record of the wheels turning (and the transformation to them) and tf_static
, the static transforms. I copy the /tf_static
topic because, when I launch an algorithm with a bagfile, even though robot_state_publisher
node exists, it doesn't do anything. It doesn't produce a /tf_static
message, and so /tf
only contains the /joint_states transformations.
Playing the bagfile, launching the Cartographer.launch
Normally, I'd do:
$ roslaunch thesis turtlebot_cartographer.launch play:=True bag:=filter.bag
Now, the rqt_graph looks like this:
As you may notice: the /tf and /tf_static topics exist. Using a $ rostopic echo /tf
and .. /tf_static
confirm these aren't empty.
/scan has messages, /joint_states has messages, /tf contains all the ...
Can you please tell us the errors roslaunch gives you. Just saying it gives you errors is not going to help us, to help you.
@PeteBlackerThe3rd updated