Bird
Raised Fist0
ROSframework~10 mins

LiDAR-based SLAM (gmapping, cartographer) in ROS - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - LiDAR-based SLAM (gmapping, cartographer)
Start Robot with LiDAR
↓
LiDAR Scans Environment
↓
Scan Data Sent to SLAM Algorithm
↓
SLAM Algorithm Processes Scans
↓
Update Map and Robot Pose
↓
Publish Updated Map and Pose
↓
Robot Uses Map for Navigation
↓
Loop Back to LiDAR Scans
The robot uses LiDAR to scan surroundings, sends data to SLAM software (gmapping or cartographer), which processes scans to update the map and robot's position continuously.
Execution Sample
ROS
# Launch gmapping SLAM
roslaunch gmapping slam_gmapping.launch

# Start robot with LiDAR
roslaunch robot_bringup bringup.launch

# View map updates
rosrun rviz rviz
This code launches gmapping SLAM, starts the robot with LiDAR, and opens RViz to visualize the map updates in real-time.
Execution Table
StepActionInput DataSLAM ProcessOutputMap Update
1Robot starts and LiDAR activatesNo scan yetWaiting for scansNo outputEmpty map
2LiDAR sends first scanRaw LiDAR scan dataInitialize map and poseInitial pose estimateMap with first scan points
3New scan receivedNew LiDAR scanMatch scan to map (scan matching)Updated pose estimateMap refined with new scan
4Loop continuesContinuous scansOptimize pose and map (particle filter or graph optimization)Pose and map updatedMap grows and improves
5Robot moves and scansMotion + scan dataCorrect pose driftAccurate poseConsistent map
6SLAM publishes map and poseProcessed dataPublish to ROS topicsMap and pose availableMap ready for navigation
7Robot uses map for navigationMap and posePath planningNavigation commandsMap used for obstacle avoidance
8Process repeatsNew scansContinuous updateReal-time pose and mapDynamic map updates
9ExitShutdown commandStop SLAMNo outputFinal map saved
💡 SLAM stops when robot or system shuts down, final map is saved for future use.
Variable Tracker
VariableStartAfter Step 2After Step 4After Step 6Final
LiDAR Scan DataNoneFirst scan dataMultiple scansContinuous scansNone (shutdown)
Robot PoseUnknownInitial estimateRefined estimateOptimized poseFinal pose
Map DataEmptyInitial map pointsGrowing mapDetailed mapSaved map
SLAM StateIdleInitializingRunningPublishingStopped
Key Moments - 3 Insights
Why does SLAM need multiple LiDAR scans instead of just one?
Because the execution_table shows the map starts empty and only grows after multiple scans (rows 2 to 4). One scan gives limited info; multiple scans help build a complete map and refine robot pose.
How does SLAM correct the robot's position over time?
The table shows SLAM uses scan matching and optimization (row 4) to update the pose estimate continuously, correcting drift caused by robot movement (row 5).
What happens when SLAM stops running?
According to the exit_note and last row, SLAM stops when the system shuts down, and the final map is saved for later use.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3. What is the SLAM process doing?
AInitializing the map and pose
BPublishing the final map
CMatching the new scan to the existing map
DStopping the SLAM process
💡 Hint
Refer to the 'SLAM Process' column at step 3 in the execution_table.
At which step does the robot pose become optimized?
AStep 4
BStep 2
CStep 6
DStep 8
💡 Hint
Check the 'Robot Pose' variable in variable_tracker after step 4.
If the LiDAR stops sending scans after step 4, what happens to the map updates?
AMap continues to grow
BMap stops updating
CMap resets to empty
DMap publishes final version immediately
💡 Hint
Look at the 'Map Update' column in execution_table rows after step 4.
Concept Snapshot
LiDAR-based SLAM uses laser scans to build a map and locate the robot.
Gmapping uses particle filters; Cartographer uses graph optimization.
Process: scan → match → update pose → update map → publish.
Continuous loop for real-time mapping and localization.
Outputs map and robot pose for navigation.
Shutdown saves the final map.
Full Transcript
LiDAR-based SLAM works by the robot scanning its environment with a laser sensor. The scan data is sent to SLAM software like gmapping or cartographer. The SLAM algorithm processes these scans to estimate the robot's position and build a map. Initially, the map is empty. After the first scan, the map starts forming. Each new scan is matched to the existing map to refine the robot's pose and improve the map. This process repeats continuously as the robot moves. The SLAM system publishes the updated map and pose so the robot can navigate safely. When the robot or system stops, SLAM saves the final map for future use.

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

  1. 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.
  2. Step 2: Identify LiDAR role

    LiDAR uses laser scans to sense the environment, which helps SLAM create accurate maps and localize the robot.
  3. Final Answer:

    To help robots create maps and know their location using laser scans -> Option C
  4. 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

  1. Step 1: Recall ROS launch syntax

    ROS uses roslaunch to start nodes with launch files, specifying package and launch file name.
  2. Step 2: Match gmapping launch file

    The gmapping package provides slam_gmapping.launch to start the SLAM node.
  3. Final Answer:

    roslaunch gmapping slam_gmapping.launch -> Option B
  4. 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:
<launch>
  <include file="$(find cartographer_ros)/launch/demo_backpack_2d.launch" />
</launch>
What will happen when you run this launch file?
medium
A. It launches a robot simulation without SLAM
B. It starts gmapping SLAM with a 3D map
C. It causes a syntax error due to missing parameters
D. It starts Cartographer SLAM with a 2D LiDAR backpack demo configuration

Solution

  1. Step 1: Understand the include tag

    The <include> tag loads another launch file from the cartographer_ros package.
  2. Step 2: Identify the included launch file

    demo_backpack_2d.launch is a Cartographer demo for 2D SLAM using a backpack LiDAR sensor.
  3. Final Answer:

    It starts Cartographer SLAM with a 2D LiDAR backpack demo configuration -> Option D
  4. Quick Check:

    Include demo_backpack_2d.launch = Cartographer 2D SLAM [OK]
Hint: Include demo_backpack_2d.launch means Cartographer 2D SLAM [OK]
Common Mistakes:
  • Confusing Cartographer with gmapping
  • Assuming missing parameters cause errors here
  • Thinking it launches simulation without SLAM
4. You try to run gmapping with this command:
roslaunch gmapping slam_gmapping.launch
But get an error: "Could not find node of type slam_gmapping in package gmapping". What is the likely cause?
medium
A. The gmapping package is not installed or sourced properly
B. You used rosrun instead of roslaunch
C. The launch file name is misspelled
D. Your LiDAR sensor is not connected

Solution

  1. Step 1: Analyze the error message

    The error says it cannot find the node type in the gmapping package, meaning the package or node is missing.
  2. Step 2: Check common causes

    This usually happens if the gmapping package is not installed or the ROS environment is not sourced to find it.
  3. Final Answer:

    The gmapping package is not installed or sourced properly -> Option A
  4. Quick Check:

    Missing package or source = node not found error [OK]
Hint: Check package installed and sourced if node not found error [OK]
Common Mistakes:
  • Assuming rosrun vs roslaunch causes this error
  • Thinking a typo in launch file name causes node type error
  • Blaming LiDAR connection for node not found
5. You want to create a 3D map using Cartographer with a LiDAR sensor on a robot. Which approach is best?
hard
A. Use Cartographer's 3D SLAM launch files and configure sensor topics properly
B. Use gmapping with default 2D settings and add a 3D camera
C. Run gmapping and Cartographer simultaneously for better accuracy
D. Use Cartographer's 2D demo launch files and convert output to 3D later

Solution

  1. Step 1: Understand SLAM capabilities

    Gmapping supports only 2D SLAM, so it cannot create 3D maps directly.
  2. Step 2: Choose Cartographer for 3D

    Cartographer supports 3D SLAM and has launch files designed for 3D mapping with LiDAR sensors.
  3. Step 3: Configure sensor topics

    Properly setting sensor topics in Cartographer launch files ensures correct data flow for 3D mapping.
  4. Final Answer:

    Use Cartographer's 3D SLAM launch files and configure sensor topics properly -> Option A
  5. Quick Check:

    3D map needs Cartographer 3D launch + sensor config [OK]
Hint: 3D mapping needs Cartographer 3D launch and sensor setup [OK]
Common Mistakes:
  • Trying to use gmapping for 3D maps
  • Running both SLAM systems at once
  • Using 2D demos and expecting 3D output
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard