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.
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 slam_sync.launch.py
Asynchronous SLAM can be used as well.
ros2 launch turtlebot4_navigation slam_async.launch.py
To visualise the map, launch Rviz2 with the
view_robot launch file.
ros2 launch turtlebot4_viz view_robot.launch.py
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.
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.