SLAM Mapping
Simultaneous Localization and Mapping - Build maps of your environment
Tutorial Overview
π― Learning Objectives
By the end of this tutorial, you will:
β Understand SLAM concepts and why it's needed
β Launch SLAM on Beetlebot
β Drive robot to create high-quality maps
β Save and load maps
β Interpret map quality indicators
β Troubleshoot mapping issues
β Create maps of different environments
β Understand map formats and parameters
β±οΈ Time Required
Reading & Theory: 25 minutes
First Map Creation: 30 minutes
Map Quality Practice: 35 minutes
Advanced Mapping: 30 minutes
Troubleshooting: 20 minutes
Total: ~140 minutes
π Prerequisites
β Completed Sensor Data Visualization
β Completed Sensor Fusion with EKF
β Can drive robot smoothly
β Understanding of LiDAR data
β Can use RViz confidently
β Environment to map (room, hallway, etc.)
π οΈ What You'll Need
β Beetlebot (fully charged, LiDAR working)
β Laptop with ROS2 Jazzy
β Wireless controller
β Environment with clear features:
Walls, furniture, doorways
At least 3m Γ 3m space
Avoid glass, mirrors (LiDAR can't see them well)
β Patience (good maps take practice!)
Part 1: What is SLAM?
The Chicken-and-Egg Problem
Classic robotics problem:
SLAM Solution: Do BOTH simultaneously!
Build map while determining position
Use partial map to improve position estimate
Use improved position to refine map
Iterate continuously
Why SLAM is Hard
Challenges:
Data Association
Is this wall same as one seen before?
Or a different wall that looks similar?
Wrong associations = bad map
Loop Closure
Return to previous location after long path
Accumulated drift makes it look different
Must recognize "I've been here before!"
Correct entire trajectory when loop closes
Computational Complexity
Tracking thousands of map features
Maintaining correlations (covariances)
Real-time requirements (robot keeps moving)
SLAM Approaches
Beetlebot uses: SLAM Toolbox (graph-based SLAM)
Other common methods:
GMapping - Older, FastSLAM-based (particle filters)
Cartographer - Google's SLAM (submap optimization)
Hector SLAM - No odometry needed (scan matching only)
RTAB-Map - RGB-D SLAM (uses depth cameras)
Why SLAM Toolbox?
β Modern, actively maintained
β ROS2 native
β Real-time capable
β Loop closure detection
β Map serialization (save/load)
β Good for 2D LiDAR
Map Representation
Occupancy Grid Map:
File format: PGM (image) + YAML (metadata)
[PLACEHOLDER: Example map image showing occupied/free/unknown]
Part 2: Your First SLAM Map
Check System Status
Before starting:
Launch SLAM Toolbox
On robot (via SSH or auto-launched):
Your robot likely has SLAM configured to launch automatically. Check:
What launches:
slam_toolboxnodeSubscribes to:
/scan,/odometry/filteredPublishes:
/map,/map_metadataProvides: Loop closure, graph optimization
Visualize SLAM in RViz
On laptop:
Configure RViz for SLAM:
[PLACEHOLDER: Screenshot of properly configured RViz for SLAM]
Drive Pattern for Good Maps
π SLAM Driving Best Practices:
DO:
β Drive slowly (0.3-0.5 m/s max)
β Make long, gentle turns (not sharp 90Β° turns)
β Overlap scans (return to previous areas)
β Close loops (return to start periodically)
β Keep consistent speed (no sudden acceleration)
β Drive in open areas first, then details
DON'T:
β Drive too fast (>0.8 m/s) - scans don't overlap enough
β Make sharp turns - causes scan matching errors
β Drive in complete darkness - LiDAR needs features
β Go near mirrors/glass - LiDAR passes through
β Have moving obstacles during initial mapping
Exercise 8.1: Create Your First Map
Task: Map a single room
Preparation:
Mapping procedure:
Expected time: 3-5 minutes for typical room
Saving Your Map
Once mapping complete:
Files created:
my_first_map.pgm- Image file (occupancy grid)my_first_map.yaml- Metadata (resolution, origin, thresholds)
Understanding the Map Files
YAML file (metadata):
Contents:
Key parameters:
resolution: Size of each grid cell
Smaller = more detail, larger file
Typical: 0.05m (5cm)
Range: 0.01-0.10m
origin: Where is (0,0) of image in world coordinates
Usually bottom-left corner
Negative values = map extends in negative x,y
occupied_thresh: LiDAR hit probability β occupied
Higher = more conservative (less marked as obstacle)
Lower = more aggressive (more marked as obstacle)
free_thresh: No hit probability β free
Higher = more aggressive marking as free
Lower = more conservative
Viewing Map Image
Open PGM file:
Image colors:
Black pixels: Occupied (walls, obstacles)
White pixels: Free space (can drive here)
Gray pixels: Unknown (not explored)
[PLACEHOLDER: Example saved map image]
Part 3: Map Quality Assessment
Visual Inspection
Good map indicators:
β Straight walls are straight (not wavy or jagged) β Corners are sharp (90Β° corners clear) β Closed spaces are closed (rooms fully enclosed) β Symmetry preserved (symmetric rooms look symmetric) β Minimal gray (unknown) (most area explored) β No "ghost" walls (false obstacles from bad scans) β Loop closures successful (start/end positions align)
Poor map indicators:
β Wavy walls (drove too fast, scan matching failed) β Blurred edges (inconsistent scans, moving during scan) β Disconnected rooms (walls have gaps where shouldn't) β Overlapping walls (double walls, loop closure failed) β Ghost obstacles (artifacts from reflections, moving objects) β Large unknown areas (didn't explore thoroughly)
[PLACEHOLDER: Side-by-side comparison good map vs poor map]
Quantitative Metrics
Check map statistics:
Calculate map coverage:
Good map targets:
Free space: 40-60%
Occupied: 10-20%
Unknown: <30%
Exercise 8.2: Map Quality Comparison
Task: Create two maps of same room, compare quality
Map 1: Fast driving (poor technique)
Map 2: Slow, careful driving (good technique)
Compare:
Expected result: Careful map significantly better!
Part 4: Advanced Mapping Techniques
Multi-Room Mapping
Challenge: Map entire floor with multiple rooms
Strategy:
Loop Closure Detection
What is loop closure?
When robot returns to previously mapped area:
SLAM detects "I've been here before!"
Measures difference between:
Where odometry says robot is
Where map says robot should be
Adjusts entire trajectory to minimize error
Updates map accordingly
Visual signs of loop closure in RViz:
Sudden "snap" of map alignment
Previous trajectory may shift slightly
Console message: "[INFO] Loop closure detected"
Exercise 8.3: Intentional Loop Closure
Task: Observe loop closure correction
Procedure:
Mapping Large Spaces
For spaces >100mΒ²:
Challenges:
Computational load increases
Memory requirements grow
Loop closure more difficult (more potential matches)
Solutions:
Increase map resolution (larger cells)
Reduce map update rate
Split into submaps
Map each area separately
Merge offline using map merging tools
Use better computer
SLAM runs on robot's Pi 5
For huge maps, might need more powerful PC
Part 5: Common Issues and Solutions
Problem: Walls Look Wavy
Cause: Driving too fast, scan matching fails
Solution:
Problem: Map Has Double Walls
Cause: Loop closure failed or didn't happen
Solution:
Problem: Ghost Obstacles
Cause: Reflections (mirrors, glass), moving objects, or sensor noise
Solution:
Problem: Large Gray (Unknown) Areas
Cause: Didn't drive in those areas, or LiDAR obstructed
Solution:
Problem: Map Rotation/Scale Wrong
Cause: TF tree issues, incorrect odometry
Solution:
Part 6: Map Editing and Processing
Cleaning Up Maps
Remove artifacts using GIMP:
Common edits:
Remove ghost obstacles (erase black pixels)
Close gaps in walls (draw black lines)
Clear unknown areas (fill with white if you know it's free)
Remove robot from map (sometimes captured in scans)
Adding Virtual Walls
Use case: Prevent robot from entering certain areas
Inflating Obstacles
Add safety margin around obstacles:
Run:
Part 7: Using Maps for Navigation
Loading a Saved Map
For next tutorial (Localization), you'll load maps:
Or use launch file:
Map Server Parameters
Customize map serving:
Part 8: Best Practices Summary
Pre-Mapping Checklist
RViz configured and ready
Plan rough mapping route
During Mapping
Drive slowly (0.3-0.5 m/s)
Make gentle turns (no sharp 90Β° corners)
Overlap scans (return to same areas)
Close loops regularly (return to start every 2-3 minutes)
Monitor map quality in RViz
Cover all areas systematically
Final loop closure (return to exact start position)
Post-Mapping
Save map with descriptive name
Inspect map image for quality
Check map statistics (% occupied/free/unknown)
Edit map if needed (remove artifacts)
Test map (load and localize - next tutorial)
Backup map files (copy to laptop)
Document map (name, date, environment notes)
Part 9: Knowledge Check
Concept Quiz
What does SLAM stand for and what does it solve?
Why drive slowly during SLAM?
What is loop closure and why is it important?
What do black, white, and gray pixels mean in map?
Can you create perfect maps without any drift?
Hands-On Challenge
Task: Map a complex environment
Requirements:
Multi-room environment (3+ rooms)
Include hallways, doorways, furniture
Total area >50mΒ²
Complete map in single session (no restarts)
Achieve <25% unknown area
Save final map with documentation
Deliverable:
Map files (.pgm + .yaml)
Screenshot of map in RViz
Statistics (occupied/free/unknown percentages)
Written description of environment
Notes on challenges encountered
Bonus:
Create before/after comparison (initial attempt vs. improved attempt)
Edit map to remove artifacts
Add inflation layer for safety margins
Part 10: What You've Learned
β
Congratulations!
You now understand:
SLAM Fundamentals:
β Simultaneous localization and mapping concept
β Graph-based SLAM (SLAM Toolbox)
β Loop closure detection and correction
β Occupancy grid representation
Practical Mapping:
β Launching and configuring SLAM
β Driving techniques for quality maps
β Saving and loading maps
β Visual quality assessment
β Common issues and solutions
Advanced Topics:
β Multi-room mapping strategies
β Map editing and processing
β Obstacle inflation
β Map statistics and metrics
Next Steps
π― You're Now Ready For:
Immediate Next: β Localization Techniques - Use saved maps to localize robot
Autonomous Navigation: β Autonomous Navigation - Navigate using your maps
Advanced Mapping:
3D SLAM (if you add depth camera)
Outdoor mapping (with GPS fusion)
Dynamic environments (handle moving obstacles)
Multi-robot SLAM (collaborative mapping)
Quick Reference
Essential SLAM Commands
SLAM Driving Checklist
Initial perimeter
0.3-0.5 m/s
Gentle arcs
Define boundaries
Interior coverage
0.3-0.5 m/s
Smooth curves
Fill in details
Loop closures
0.3 m/s
Gentle
Every 2-3 minutes
Final pass
0.3 m/s
Follow previous path
Consistency check
Troubleshooting Flowchart
Completed SLAM Mapping! π
β Continue to Localization Techniques β Or return to Tutorial Index
Last Updated: January 2026 Tutorial 8 of 11 - Advanced Level Estimated completion time: 140 minutes
Last updated