Turtlebot SLAM from rosbag

In the following I will explain (1) how to record a rosbag that is suitable for gmapping SLAM and (2) how to use that rosbag to build a map using ROS’s gmapping. It makes sense to split the process of mapping an environment into these two steps, since you can then easily tweak the parameters of gmapping until you obtain a satisfying map without having to drive the Turtlebot through the whole environment over and over again. Additionally, you can just move the rosbag to some powerful desktop computer for processing (this allows gmapping to create better maps since it can be run with more particles). This description was tested for ROS groovy with a Turtlebot V2.0.

Recording the rosbag

Switch your Turtlebot base and its laptop on. Make sure the Kinect and the base USB connectors are plugged in. In separate terminals run the following commands to start the Turtlebot up, switch the Kinect on, start the teleoperation node (here I am using a standard keybord), and start recording.

# terminal 1 
roslaunch turtlebot_bringup turtlebot.launch
# terminal 2
roslaunch turtlebot_bringup 3dsensor.launch 
# terminal 3
roslaunch turtlebot_teleop keyboard_teleop.launch 
# terminal 4
rosbag record /scan /tf

As you can see we are recording only the two ROS topics /scan and /tf. These are the two topics, that will later be used by gmapping to perform SLAM. If you need additional data for your experiment you can just add the respective topics to the list behind rostopic record.

To steer your Turtlebot around click on the teleop terminal and use the keyboard keys as described in that terminal.

Once you are done and want to stop recording, just terminate the rosbag record using Ctrl+c. You will  find a rosbag named according to the time of bag creation in the current folder.

Obtaining the map

To obtain the map we are going to run gmapping on the recorded rosbag. Make sure to close all nodes and the roscore we started to record the rosbag. Then run the following commands in the respective terminals to start a new roscore, set the clock to simulation time, launch gmapping (pure Рwithout navigation)  and start playback of the previously recorded rosbag.

# terminal 1
# terminal 2
rosparam set use_sim_time true
roslaunch turtlebot_navigation _gmapping.launch
# terminal 4
rosbag play --clock TIME.bag

When playing back the rosbag with use_sim_time=true it is important to specify the --clock option to make the rosbag play publish the /clock topic which tells the other nodes about the time in the rosbag.

Once the mapping has finished save the map using

rosrun map_server map_saver -f $(pwd)/name
turtlebot two loops

turtlebot two loops

Leave a Reply