Creating a 2D map with GMapping (ROS)

In this tutorial, you will learn how to build a 2D map of an environment using the GMapping SLAM algorithm in ROS1. This process is fundamental for autonomous navigation as it allows the robot to understand and represent its surroundings.

 📝 Requirements 

  • – ROS1 installed (e.g., Noetic) 
    – `slam_gmapping` package 
    – Simulated robot with LIDAR sensor (e.g., TurtleBot3 in Gazebo) 
    RViz installed for visualization 

Step 1: Launch the GMapping Node

Launch the SLAM node with the following command:

rosrun gmapping slam_gmapping scan:=/scan 

🖥️Step 2: Move the Robot to Explore

To generate a meaningful map, the robot needs to explore the environment. You can use keyboard teleoperation with: 

roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch 

Step 3: Save the Map 

Once the robot has sufficiently explored the environment and a good map has been built, save it to your filesystem using: 

rosrun map_server map_saver -f ~/gmapping_map 

🛠️Step 3: Troubleshooting

– The map is empty:

check if the LIDAR is publishing correctly and the topic is set properly. 
– The map is not accurate:

move the robot slowly and ensure it explores all areas. 
– The robot doesn’t move:

verify that teleop commands are sent to the right topic. 

Want to learn more?

You can find a detailed explaination of the autonomous navigation in the "Self Driving and ROS - Learn by Doing! Odometry and Control" course
DISCOUNT
es_ES