LiDAR-based SLAM with gmapping and cartographer in ROS
📖 Scenario: You are building a robot navigation system that uses LiDAR sensors to create maps and localize itself indoors. You will set up two popular ROS SLAM frameworks: gmapping and cartographer. This project guides you through configuring and running these SLAM packages step-by-step.
🎯 Goal: Set up ROS nodes and configuration files to run LiDAR-based SLAM using gmapping and cartographer. You will create the necessary launch files, parameter configurations, and topic remappings to visualize the generated maps in rviz.
📋 What You'll Learn
Create a ROS launch file to start the gmapping node with LiDAR input
Add a configuration parameter for the LiDAR scan topic name
Implement the core SLAM node launch with correct topic remapping
Add a launch file to start cartographer with its configuration and sensor topics
💡 Why This Matters
🌍 Real World
Robots use LiDAR-based SLAM to build maps and navigate unknown indoor spaces autonomously.
💼 Career
Understanding how to configure and run SLAM frameworks in ROS is essential for robotics engineers working on autonomous navigation.
Progress0 / 4 steps
1
Create a ROS launch file for gmapping node
Create a ROS launch file named gmapping_launch.launch that starts the gmapping node from the slam_gmapping package. Use the node name slam_gmapping and set the output to screen. Do not add any parameters or remappings yet.
ROS
Hint
Use the <node> tag with attributes pkg, type, name, and output.
2
Add LiDAR scan topic parameter
In the gmapping_launch.launch file, add a launch argument named scan_topic with default value /scan. Then add a remap tag inside the node to remap the scan topic to the launch argument $(arg scan_topic).
ROS
Hint
Use <arg> to declare the argument and <remap> inside the node to remap topics.
3
Launch gmapping node with parameters and remapping
Modify the gmapping_launch.launch file to add a parameter base_frame with value base_link inside the node. Keep the existing remap tag for scan. This completes the core logic to run gmapping with LiDAR input and frame configuration.
ROS
Hint
Use the <param> tag inside the node to set parameters.
4
Create a launch file for cartographer with sensor topics
Create a new ROS launch file named cartographer_launch.launch. Inside it, start the cartographer_node from the cartographer_ros package with node name cartographer_node and output screen. Add parameters to load the configuration file $(find cartographer_ros)/configuration_files/backpack_2d.lua. Remap the scan topic to /scan and the tf topic to /tf. This completes the setup to run cartographer SLAM with LiDAR input.
ROS
Hint
Use <param> tags to load configuration files and <remap> tags for topic remapping inside the node.
Practice
(1/5)
1. What is the main purpose of LiDAR-based SLAM in ROS?
easy
A. To process camera images for object detection
B. To control robot motors directly
C. To help robots create maps and know their location using laser scans
D. To send commands to robot arms
Solution
Step 1: Understand SLAM basics
SLAM stands for Simultaneous Localization and Mapping, which means building a map and knowing the robot's position at the same time.
Step 2: Identify LiDAR role
LiDAR uses laser scans to sense the environment, which helps SLAM create accurate maps and localize the robot.
Final Answer:
To help robots create maps and know their location using laser scans -> Option C
Quick Check:
LiDAR-based SLAM = mapping + localization with lasers [OK]
Hint: SLAM = map + location using sensors like LiDAR [OK]
Common Mistakes:
Confusing SLAM with motor control
Thinking SLAM processes camera images only
Assuming SLAM sends commands to robot arms
2. Which ROS launch command correctly starts the gmapping SLAM node?
easy
A. rosstart gmapping slam.launch
B. roslaunch gmapping slam_gmapping.launch
C. rosrun gmapping slam_gmapping.py
D. roslaunch cartographer slam.launch
Solution
Step 1: Recall ROS launch syntax
ROS uses roslaunch to start nodes with launch files, specifying package and launch file name.
Step 2: Match gmapping launch file
The gmapping package provides slam_gmapping.launch to start the SLAM node.
Final Answer:
roslaunch gmapping slam_gmapping.launch -> Option B
Quick Check:
Use roslaunch + package + launch file [OK]
Hint: Use roslaunch with package and launch file name [OK]
Common Mistakes:
Using rosrun instead of roslaunch for launch files
Typing rosstart which is invalid
Confusing cartographer launch with gmapping
3. Given this ROS launch snippet for Cartographer: