Skip to main content

๐Ÿ—บ๏ธ SLAM (Simultaneous Localization and Mapping)

SLAM is the core that allows your robot to build a map of an unknown environment while keeping track of its own positionโ€”all in real time.
This is the foundation for autonomous navigation, exploration, and manipulation.


๐Ÿค” What is SLAM?โ€‹

SLAM stands for Simultaneous Localization and Mapping.
It lets your robot create a map and know where it is on that mapโ€”using only its own sensors.

  • Localization: "Where am I right now?"
  • Mapping: "What does my world look like?"
  • SLAM: "Where am I, and what does my world look likeโ€”at the same time?"

๐Ÿง  How SLAM Works (in Your Project)โ€‹

  • Your robot uses LiDAR, depth camera, and optionally IMU/wheel odometry for input.
  • The SLAM node (Cartographer or RTAB-Map) creates a map and constantly estimates robot pose.
  • The map and pose are published to other nodes (like Navigation).

โš™๏ธ SLAM in This Projectโ€‹

You can choose between two industry-standard SLAM implementations:

Best for: Fast, lightweight, real-time 2D mapping
Uses: LiDAR (YDLIDAR T-mini Pro) for map building

# Launch robot base and LiDAR
ros2 launch limo_bringup limo_start.launch.py

# Start Cartographer SLAM
ros2 launch limo_bringup cartographer.launch.py

Visualize in RViz:

rviz2

๐Ÿ—บ๏ธ Building and Saving a Mapโ€‹

  1. Move the robot slowly throughout the environment (use teleop or remote/app)
  2. When done, save the map:
ros2 run nav2_map_server map_saver_cli -f my_map

Map will be saved as my_map.yaml and my_map.pgm in the current directory.

Map Files
  • .yaml: Map metadata (resolution, origin, thresholds)
  • .pgm: Actual map image (grayscale occupancy grid)

๐ŸŽฏ Localization Strategiesโ€‹

After a map is built, you need localization to allow the robot to "find itself" on the map at startup and during navigation.

AMCL (Adaptive Monte Carlo Localization)โ€‹

Used after Cartographer mapping. Tracks the robot's position on a 2D map using LiDAR and motion data.

ros2 launch limo_bringup limo_nav2.launch.py
# Or for Ackermann mode:
ros2 launch limo_bringup limo_nav2_ackmann.launch.py

RTAB-Map Localizationโ€‹

Launch rtabmap in localization mode:

ros2 launch limo_bringup limo_rtab_slam.launch.py localization:=true
Initial Pose Setup

In RViz, always set the robot's initial pose to align the laser scan with the map!
Use the "2D Pose Estimate" tool in RViz after startup.


๐Ÿ› ๏ธ SLAM Configurationโ€‹

Key Parameters for Cartographerโ€‹

ParameterDescriptionTypical Value
map_resolutionMap cell size (meters)0.05
tracking_frameRobot base framebase_link
published_frameMap framemap
use_odometryUse wheel odometrytrue

Key Parameters for RTAB-Mapโ€‹

ParameterDescriptionTypical Value
frame_idRobot base framebase_link
map_frame_idMap framemap
database_pathDatabase location~/.ros/rtabmap.db
localizationLocalization modefalse (mapping)

๐Ÿ’ก Best Practices & Troubleshootingโ€‹

๐ŸŒ Move Slowly During Mapping
  • Move at 0.3 m/s or slower for best accuracy
  • Avoid sudden turns or rapid acceleration
  • Give the algorithm time to process sensor data
๐Ÿ”„ Loop Closure
  • Don't close loops too quicklyโ€”give the algorithm time to recognize previously seen areas
  • Ensure good lighting for camera-based SLAM
  • LiDAR-based SLAM is more robust to lighting changes
๐Ÿ’พ Data Management
  • Backup your maps and SLAM database after every successful session!
  • Use descriptive filenames with dates: office_2025-08-07.yaml
  • Test map quality before relying on it for navigation
โš ๏ธ Common Issues
  • Laser scan and map don't align: Manually set initial pose in RViz
  • Map quality poor: Check sensor mounting, move slower, ensure good lighting
  • Localization fails: Verify map files exist and are in correct format

๐Ÿ”ง Advanced SLAM Featuresโ€‹

Multi-Session Mappingโ€‹

# Continue mapping with existing RTAB-Map database
ros2 launch limo_bringup limo_rtab_slam.launch.py
# Database automatically loads previous session

Online Loop Closureโ€‹

  • Cartographer: Automatic loop closure optimization
  • RTAB-Map: Real-time loop closure with visual and geometric validation

Map Updatesโ€‹

  • Static environments: Maps remain stable over time
  • Dynamic environments: RTAB-Map can handle moving objects

๐Ÿ“Š Performance Comparisonโ€‹

FeatureCartographerRTAB-Map
Speedโšก Very Fast๐ŸŒ Moderate
Map Quality๐Ÿ“ Good 2D๐ŸŽฏ Excellent 3D
Memory Usage๐Ÿ’พ Low๐Ÿ’พ High
Robustness๐Ÿ›ก๏ธ Very Good๐Ÿ›ก๏ธ Excellent
Setup Complexity๐Ÿ”ง Simple๐Ÿ”ง Moderate

๐Ÿ“š Learn Moreโ€‹


๐ŸŽฏ Next Stepsโ€‹

Ready to Navigate?

Once you have a good map, you're ready for autonomous navigation!