Overview
The Map Server loads and serves occupancy grid maps to navigation systems. It’s essential for autonomous navigation with pre-built maps.Map Server provides the
/map topic that Nav2 uses for path planning and obstacle avoidance.Map Formats
Occupancy Grid Map
Components:- Image file (
.pgm): Grayscale image of map - Metadata file (
.yaml): Map parameters
PGM Image
Portable GrayMap format:- White (255): Free space
- Black (0): Occupied space
- Gray (205): Unknown space
YAML Metadata
File:maps/my_map.yaml
-
resolution: Physical size of one pixel
- 0.05 = 5cm per pixel (common for indoor)
- 0.01 = 1cm per pixel (high detail)
- 0.1 = 10cm per pixel (large areas)
-
origin: Position of map’s bottom-left corner in world frame
- Usually negative to center map around (0,0)
- Example: [-10, -10, 0] → 20×20m map centered at origin
-
occupied_thresh: Probability threshold for occupied
- 0.65 = 65% confidence → mark as occupied
- Higher = fewer obstacles (conservative)
- Lower = more obstacles (aggressive)
-
free_thresh: Probability threshold for free
- 0.196 = 19.6% confidence → mark as free
- Space between thresholds = unknown
-
negate: Invert image colors
- 0 = white is free (standard)
- 1 = black is free (inverted)
Saving Maps
Method 1: From SLAM Toolbox
While SLAM running: Option A: RViz plugin- Panels → SlamToolboxPlugin
- Click “Save Map”
- Choose location:
~/maps/my_map
my_map.pgmmy_map.yaml
Method 2: map_saver_cli
Standalone map saving:-f: Output filename (without extension)--map-topic: Topic to subscribe (default:/map)--image-format:pgmorpng--mode:trinary,scale, orraw--free: Free threshold--occ: Occupied threshold
Verifying Saved Map
Loading Maps
Map Server Launch
File:launch/map_server.launch.py
Lifecycle Management
Map server uses lifecycle nodes (managed state): States:- Unconfigured (initial)
- Inactive (configured but not serving map)
- Active (serving map)
- Finalized (shutdown)
Verifying Map Loaded
Check Topic
RViz Visualization
- Fixed Frame:
map - Add → Map
- Topic:
/map - Color Scheme: map
- Topic:
- Add → RobotModel
- Add → TF
Editing Maps
GIMP (GNU Image Manipulation Program)
Install:- Open
my_map.pgmin GIMP - Use paintbrush:
- White: Mark as free
- Black: Mark as occupied
- Gray (50%): Mark as unknown
- Save as PGM (same filename)
- Add virtual walls (block off areas)
- Remove dynamic objects (chairs moved)
- Clean up noise
- Expand walls slightly (safety margin)
imagemagick (Command-line)
Update Origin After Editing
If rotated/resized, updateorigin in YAML:
Map Server Services
Map server provides services for runtime map management:Load Map
Save Map (if map_saver enabled)
Multi-Floor / Multi-Map
For buildings with multiple floors:Approach 1: Separate Map Files
Approach 2: 3D Map (Advanced)
Use Octomap for 3D environments:Map Quality Check
Checklist
- Walls continuous: No gaps in walls
- Rooms closed: All rooms form closed shapes
- No artifacts: No stray black pixels (noise)
- Free space clear: Open areas are white
- Resolution appropriate: 5cm for indoor, 10cm for outdoor
- Origin correct: Robot starts at reasonable position
Quantitative Metrics
Map coverage:Troubleshooting
Map not appearing in RViz
Map not appearing in RViz
Debug:
-
Check map server running:
-
Check map server state:
-
Check
/maptopic: -
Check Fixed Frame in RViz =
map
Map loads but is rotated/shifted
Map loads but is rotated/shifted
Cause: Incorrect
origin in YAMLSolution:- Adjust origin [x, y, yaw] in YAML file
- Visualize in RViz to iteratively correct
- Common: yaw = 0, ±π/2, ±π
Map quality poor (blurry, noisy)
Map quality poor (blurry, noisy)
Causes:
- SLAM mapping speed too fast
- LiDAR vibration
- Poor odometry
- Remap at slower speed
- Edit map in GIMP (clean up noise)
- Apply median filter:
'Could not load map' error
'Could not load map' error
Causes:
- File path incorrect
- YAML syntax error
- PGM file corrupted
-
Check file exists:
-
Validate YAML:
-
Test PGM loads:
Integration with Navigation
Full navigation stack:Best Practices
Map Resolution
- Indoor: 0.05m (5cm) - good balance
- Detailed: 0.01m (1cm) - large files
- Outdoor: 0.1m (10cm) - faster processing
Map Naming
Use descriptive names:
lab_floor3_20240315.yamlhome_downstairs.yaml- Avoid:
map.yaml,test.yaml
Version Control
- Store maps in Git
- Tag versions:
v1.0-initial,v1.1-furniture-added - Keep backup of working maps
Documentation
Document each map:
- Creation date
- Environment (which floor/area)
- Known issues
- Update history
Next Steps
Cartographer
Alternative SLAM solution for complex environments
Navigation
Use maps for autonomous path planning with Nav2
Localization
Localize robot in pre-built map using AMCL
Multi-Robot Mapping
Coordinate multiple robots for faster mapping