Ask Your Question

How to test SLAM algorithms on a .bag file?

asked 2020-06-25 08:02:55 -0500

dhaour9x gravatar image

updated 2020-07-01 15:01:25 -0500

I have tried to execute different SLAM on .bag file, which I have already recorded ground.bag I have recorded bag file from simulation environment using the following commands:

  1. roslaunch turtlebot3_gazebo navibot_world.launch


  • roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
  • rosbag record -o ground /scan /tf /odom

I have used the Turtlebot3 GitHub repository from Robotis

You can download the bag file ground.bag)

After recording bag file I have tried to launch SLAM (gmapping, hector, karto, Cartographer) on this bag file to compare them using the following commands:


export TURTLEBOT3_MODEL=waffle

roslaunch turtlebot3_bringup turtlebot3_remote.launch

export TURTLEBOT3_MODEL=waffle

rosrun rviz rviz -d `rospack find turtlebot3_slam`/rviz/turtlebot3_slam.rviz

roscd turtlebot3_slam/bag

rosbag play ./ground.bag

roslaunch turtlebot3_slam turlebot3_slam

  <!-- Arguments -->
  <arg name="model" default="waffle" doc="model type [burger, waffle, waffle_pi]"/>
  <arg name="slam_methods" default="$(arg slam_methods)" doc="slam type [gmapping, cartographer, hector, karto, frontier_exploration]"/>
  <arg name="configuration_basename" default="turtlebot3_lds_2d.lua"/>
  <arg name="open_rviz" default="true"/>
<param name="use_sim_time" value="true"/>
  <!-- TurtleBot3 -->
  <include file="$(find turtlebot3_bringup)/launch/turtlebot3_remote.launch">
    <arg name="model" value="$(arg model)" />

  <!-- SLAM: Gmapping, Cartographer, Hector, Karto, Frontier_exploration, RTAB-Map -->
  <include file="$(find turtlebot3_slam)/launch/turtlebot3_$(arg slam_methods).launch">
    <arg name="model" value="$(arg model)"/>
    <arg name="configuration_basename" value="$(arg configuration_basename)"/>

  <!-- rviz -->
  <group if="$(arg open_rviz)"> 
    <node pkg="rviz" type="rviz" name="rviz" required="true"
          args="-d $(find turtlebot3_slam)/rviz/turtlebot3_$(arg slam_methods).rviz"/>
  • Copy and Paste your error message on terminal rvizerror

rosrun rviz rviz -d `rospack find turtlebot3_slam`/rviz/turtlebot3_slam.rviz

  1. Which TurtleBot3 you have?

    • [x ] Waffle
  2. Which ROS is working with TurtleBot3?

    • [ x] ROS 1 Kinetic Kame
  3. Which SBC(Single Board Computer) is working on TurtleBot3?

    • [ x] Raspberry Pi 3
  4. Which OS you installed in SBC?

    • [x ] Ubuntu MATE 16.04 or later
  5. Which OS you installed in Remote PC?

    • [ x] Ubuntu 16.04 LTS (Xenial Xerus)

I hope you can help me

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-06-28 13:04:47 -0500

renangm gravatar image

I replicated your setup and used the gmapping node for SLAM with your ground bag.

Not quite sure what your problem is, but one issue I can see is that to see the results of the SLAM algorithm running on your bag file in RVIZ, you need to add the map message in RVIZ (Add -> rviz/Map), and then select the /map topic. If you do this, you will see that gmapping (for example) is indeed generating a map from your bag file.

Another issue is the message timestamps on your bag are set to the beginning of UNIX time (Jan 1 1970). You can see the bag timestamps by running

rosbag info ground.bag

and looking at the "start" and "end" fields. This is why you cannot see the robot model in RVIZ even after including the "RobotModel" message, as ROS drops old TF messages. You can also see this in effect if you look at your TF frames with

rosrun tf view_frames

Apart from map->odom (provided by gmapping), all other transforms are 1593366155.891 seconds old.

This happens because the Raspberry Pi 3 updates its date and time according to a time server on the internet. If the Pi is not connected to the internet, then it cannot update its own time and thus defaults to the beginning of UNIX time. In that case, you need to set the date and time manually with the "date" command. Note that the "date" command does not persist over reboots (the Pi 3 does not have a battery backup for clock), so you have to do it every reboot.

I am not sure this is really a problem for you since the SLAM map is being generated regardless of the old transforms. Nevertheless, the easiest way to fix this would be to update the date and time on your raspberry and record the bag again. Another slightly less easy way to fix this is to use the ROSBAG API and update the timestamps manually.

edit flag offensive delete link more


Thank you @renangm How can I correct the timestamps? I'm trying to launch the .bag file in the same SLAM launch file, How can I do that in turtlebot3_slam launch file

dhaour9x gravatar image dhaour9x  ( 2020-07-01 15:01:51 -0500 )edit

You can correct the timestamps with the python rosbag API. Have a look here. To play a rosbag from the launch file, you can run it as any other node. For example: <node pkg="rosbag" type="play" name="rosbagPlayer" args="<your-rosbag-file> />.

renangm gravatar image renangm  ( 2020-07-02 23:35:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-06-25 08:02:55 -0500

Seen: 37 times

Last updated: Jul 01