Advanced SLAM in ROS2: Mapping with Cartographer

In this tutorial, you’ll learn how to use Google’s Cartographer with ROS2 to perform advanced 2D SLAM (Simultaneous Localization and Mapping). Cartographer is a real-time SLAM algorithm that provides loop closure and accurate map construction in dynamic environments. We’ll use a simulated TurtleBot3, but the steps are adaptable to real robots. 

 📝 Requirements 

  • – ROS2 installed (e.g., Humble or Foxy) 
    – `cartographer_ros` installed and built in your workspace 
    – A robot simulation (e.g., TurtleBot3 in Gazebo) 
    – LIDAR sensor publishing on `/scan` 
    – TF tree properly set up between `base_link`, `odom`, and `laser` 

Step 1: Launch Simulation and Cartographer 

Start the robot simulation and the Cartographer SLAM launch file. Example with TurtleBot3: 

ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=true

🖥️Step 2: Move the Robot Around 

Use keyboard teleoperation or predefined waypoints to guide the robot around the map: 

ros2 run turtlebot3_teleop teleop_keyboard 

e42f1fb4-ce8d-4cd3-bfa4-27689f2c506f

Step 3: Save the Map 

Once the robot has explored enough, save the generated map using map_server: 

ros2 run nav2_map_server map_saver_cli -f ~/cartographer_map 

🛠️ Passaggio 4: Risoluzione dei problemi 

– Errori TF:

verificare che esistano i frame corretti (` base_link` , ` odom` , `laser`, ecc.) – i dati LIDAR non vengono visualizzati: 

assicurati che `/scan` stia pubblicando e che il sensore funzioni – La mappa si sta spostando o è deformata: 

controlla la messa a punto del modello di movimento nei parametri di Cartographer – Il file di avvio si blocca: 

assicurati che Cartographer sia correttamente costruito e reperito nel tuo spazio di lavoro 

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
en_US