๐บ๏ธ 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:
- ๐ฏ Cartographer (2D LiDAR)
- ๐ฅ RTAB-Map (3D RGB-D)
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
Best for: High-quality, dense 3D mapping
Uses: Depth camera (Orbbec DaBai) and LiDAR
# Start robot base and camera
ros2 launch limo_bringup limo_start.launch.py
ros2 launch orbbec_camera dabai.launch.py
# OR (for Astra camera):
ros2 launch astra_camera dabai.launch.py
# Start RTAB-Map SLAM
ros2 launch limo_bringup limo_rtab_slam.launch.py
RViz will show the real-time point cloud and map.
๐บ๏ธ Building and Saving a Mapโ
- Cartographer
- RTAB-Map
- Move the robot slowly throughout the environment (use teleop or remote/app)
- 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.
.yaml: Map metadata (resolution, origin, thresholds).pgm: Actual map image (grayscale occupancy grid)
- RTAB-Map saves its database automatically as
~/.ros/rtabmap.dbin your home folder - To backup or use later, copy this file to a safe place!
# Backup your RTAB-Map database
cp ~/.ros/rtabmap.db ~/my_maps/office_map_$(date +%Y%m%d).db
RTAB-Map databases can get large (GB+). Regularly backup and clean old sessions.
๐ฏ 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
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โ
| Parameter | Description | Typical Value |
|---|---|---|
map_resolution | Map cell size (meters) | 0.05 |
tracking_frame | Robot base frame | base_link |
published_frame | Map frame | map |
use_odometry | Use wheel odometry | true |
Key Parameters for RTAB-Mapโ
| Parameter | Description | Typical Value |
|---|---|---|
frame_id | Robot base frame | base_link |
map_frame_id | Map frame | map |
database_path | Database location | ~/.ros/rtabmap.db |
localization | Localization mode | false (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โ
| Feature | Cartographer | RTAB-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โ
- Official ROS2 SLAM Tutorials
- Cartographer Documentation
- RTAB-Map Documentation
- Navigation Stack Integration
๐ฏ Next Stepsโ
Once you have a good map, you're ready for autonomous navigation!
- Next: Navigation & Path Planning
- Integration: System Integration
- Backup: Backup & Restore