Generating a map

In this tutorial we will be mapping an area by driving the TurtleBot 4 around and using SLAM. Start by making sure that the area you will be mapping is clear of unwanted obstacles. Ideally, you don't want people or animals moving around the area while creating the map.

Launch SLAM

First, make sure that the RPLIDAR and description nodes are running on the TurtleBot 4.

Then run SLAM. It is recommended to run synchronous SLAM on a remote PC to get a higher resolution map.

ros2 launch turtlebot4_navigation

Asynchronous SLAM can be used as well.

ros2 launch turtlebot4_navigation

Launch Rviz2

To visualise the map, launch Rviz2 with the view_robot launch file.

ros2 launch turtlebot4_viz
Rviz2 showing a map generate by SLAM

Drive the TurtleBot 4

Use any method to drive the robot around the area you wish to map. Check out the driving tutorial if you are unsure of how to drive the robot.

Keep watch of RVIZ as you drive the robot around the area to make sure that the map gets filled out properly.

Generating a map by driving the TurtleBot 4

Save the map

Once you are happy with your map, you can save it with the following command:

ros2 service call /slam_toolbox/save_map slam_toolbox/srv/SaveMap "name:
  data: 'map_name'"

This will save the map to your current directory.

View the map

Once the map is saved it will generate a map_name.pgm file which can be viewed in an image editor. A map_name.yaml file is also created. You can edit this file to adjust the map parameters.

Generated map image