Lab C: SLAM


Today's Lab



Mapping Environments Using SLAM


Please work with your particle filter project partner during today's lab.

In this exercise, you will (1) use SLAM to generate a map of the maze we've built for the Turtlebot4 (shown below), and (2) save & load the map - visualizing it in RViz.

maze

Setup


To start out today's lab, you'll want to have set up your particle filter project ROS2 package (if you haven't already). This involves:

To ensure that you're saving your map files in the right place, create a new maps directory at the full path:

~/intro_robo_ws/src/particle_filter_project/maps
This directory is where you'll want to save all your map files that you generate during this lab and for the particle filter project.


Using SLAM to Create a Map of Your Environment


The Turtlebot4 ROS2 packages have nodes that can perform SLAM and output a map of an environment that the Turtlebot4 navigates. You can follow these links to find more information on generating a map using SLAM and Turtlebot4 navigation

Now, let's run SLAM and generate a map of your Turtlebot4's environment. Do this by executing the following:

Difficulties Recording the Whole Maze: One thing we've noticed while trying to record a map of the entire maze is that the SLAM algorithm often has a tough time recording the last 10-20% of the maze. If you find that you're having trouble recording the whole maze, try recording a map of one half of the maze. You can then use this partial map for your particle filter localization project.

Here's an example of what you should see in RViz when you're generating your map (my computer was lagging a bit during the recording of this gif, yours should look a bit more continuous):

Turtlebot3 SLAM in RViz
Turtlebot3 SLAM in hallway

Loading a Saved Map


To load a map that you've saved and visualize it in RViz, you'll need to:

  1. Map names and location: Make sure that the map you want to visualize is named maze_map and that both the maze_map.yaml and maze_map.pgm files are in the ~/intro_robo_ws/src/particle_filter_project/maps directory.
  2. Build your colcon workspace: When you add a new map file to your ROS2 package, you'll need to re-build your colcon workspace and source the install/setup.bash file again so that ROS2 can find the new map files.
    $ cd ~/intro_robo_ws
    $ colcon build --symlink-install --packages-select particle_filter_project
    $ source install/setup.bash
  3. Launch the map in RViz: To visualize your saved map in RViz, you'll need to to launch the visualize_particles_launch.py file that we've created that comes with your particle filter project ROS2 starter code package. This launch file will launch RViz and the map server node that will load your saved map. You can run this command in a new terminal window:
    ros2 launch particle_filter_project visualize_particles_launch.py

Get map loaded in RViz

Further SLAM Learning Materials


If you're interested in learning more about SLAM, feel free to check out:


Particle Filter Project Work Time + Maze Recording


Once you've finished having fun exploring the built-in SLAM Turtlebot4 ROS2 packages, please use the rest of class time to work on your particle filter localization project with your project partner.

For your particle filter localization project, one thing you will need is a map of the maze. Use time in lab today to record a map of the maze for your project. Only one team can record a map of the maze at a time, so please wait your turn and work on other aspects of the project while you're waiting.