2D SLAM
slam_toolbox
I use slam_toolbox (source code) in ROS2 to run 2D SLAM on my robots. It combines LiDAR scan information alongside odometry to generate a map (.pgm
+ .yaml
output).
I’ve used slam_toolbox to generate maps on:
- F1TENTH car
- Create3 during my coop at Enlighted Inc
Installation
Installing is as easy as running the following command:
Using slam_toolbox
Launch Teleop on one window, and start SLAM using the following command:
This will start the SLAM node, and start publishing the generated map to the /map
topic.
If you want to launch with custom parameter files, run
On another terminal, open rviz by running
Then,
- Add
/map
by topic (slam_toolbox publishes the latest map to this) - Add
/graph_visualization
by topic (optional, I personally do like this) - On top left corner of rviz, panels add new panel add SlamToolBoxPlugin panel
- Once you’re done mapping, save the map using the plugin.
- You can give it a name in the text box next to Save Map. Map will be saved in whichever directory you ran slam_toolbox.
The other way to save a map is through the terminal, by running
ros2 run nav2_map_server map_saver_cli -f map_name
Generated Map Explained
this would be the .yaml
file generated. It’s actually quite straightforward.
The resolution tells you the correspondence of pixels to meters.
The origin tells you where the (0,0) in the pixel space corresponds to.
Troubleshooting
The main reason why your map generated is terrible is because of BAD Odometry.
- When I tried running F1TENTH SLAM for the first time, my odometry was inverted. As soon as I fixed that, the map generated was pretty clean
- When I tried it on the Create3
Issues
I’ve had so many problems with slam_toolbox not working. Every single time, it had to do with inverted odometry.
The recommendation is to just look at the odom
and base_link
. They should correspond with each other as you move them in real life.
In my case, for some reason, as I was moving in one direction, the interpretation was going in the exact opposite direction. I just flipped the LiDAR around by 180 degrees, and that fixed the issue.
Credits
I learned to use this by consulting the F1TENTH lecture slides, which can be found here.
- I’m pretty sure it’s slam_params_file instead of params_file everywhere?? I checked with
ros2 param get slam_toolbox max_laser_range
, the other one actually works. I figured it out from this source code - It’s slam_params_file on the newer ROS2 distributions