BUILD A MAP.
Drive the car slowly around a room and turns the LiDAR sweeps and wheel odometry into a 2D occupancy grid. Three backends ship on the car: pick one, watch the map form in , then save it for navigation.
DRIVE TO MAP.
Mapping runs on top of the live driver, and you build the map by driving the car yourself. Keep the transmitter in RC mode and take it slowly: smooth, steady passes let the scan matcher keep up.
- The driver is up on the car (start it with
teleop, see ROS 2 driver). - You can reach the car's ROS graph from your laptop (see Networking).
- A bounded indoor space with walls the LiDAR can see. Glass and mirrors read as gaps, so keep them out of the run.
- SWB up (manual), so you stay on the sticks while SLAM runs.
THREE WAYS TO MAP.
Each backend runs in its own terminal, with a second terminal that opens RViz so you can watch. Start one mapper, not three.
| Backend | Good for |
|---|---|
| slam_toolbox | The default. Solid pose-graph SLAM, easy to resume and refine. |
| gmapping | Classic particle-filter SLAM. Light and familiar. |
| Cartographer | Loop-closure heavy, good on larger or repetitive spaces. |
bashracecar ws osracer # switch this shell to the vendor workspace ros2 launch osracer_slam slam_toolbox.launch.py # terminal 1 ros2 launch osracer_debug debug_mapping.launch.py # terminal 2 (RViz)
bashracecar ws osracer # switch this shell to the vendor workspace ros2 launch osracer_slam gmapping.launch.py # terminal 1 ros2 launch osracer_debug debug_mapping.launch.py # terminal 2 (RViz)
bashracecar ws osracer # switch this shell to the vendor workspace ros2 launch osracer_slam cartographer.launch.py # terminal 1 ros2 launch osracer_debug debug_cartographer.launch.py # terminal 2 (RViz)
WATCH IT BUILD.
The debug terminal opens RViz with the fixed frame set to map. As you drive, the occupancy grid fills in around the car.
The grid
The scan
The path
SAVE THE MAP.
With the mapper still running and the space covered, save. You get a map.pgm image and a map.yaml metadata file under osracer_slam/maps/. That pair is what Nav2 loads.
bashracecar ws osracer # switch this shell to the vendor workspace ros2 launch osracer_slam map_save.launch.xml
bashracecar ws osracer # switch this shell to the vendor workspace ros2 launch osracer_slam map_save_cartographer.launch.xml
