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.
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:
~/intro_robo_ws/src directoryinstall/setup.bashfile: $ cd ~/intro_robo_ws
$ colcon build --symlink-install --packages-select particle_filter_project
$ source install/setup.bash
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.
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:
$ ros2 launch turtlebot4_navigation slam.launch.py namespace:=/tb05
$ ros2 launch turtlebot4_viz view_robot.launch.py namespace:=/tb05
Fixed Frame in RViz's Global Options from map to base_link.
maze_map - the map name expected for your particle filter project
$ ros2 run nav2_map_server map_saver_cli -f "maze_map" --ros-args -p map_subscribe_transient_local:=true -r __ns:=/tb05
Please note, if you did not run this command from the ~/intro_robo_ws/src/particle_filter_project/maps directory, you'll need to move your map files to that directory in order to allow your ROS2 package to access the map when visualizing it.
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):
To load a map that you've saved and visualize it in RViz, you'll need to:
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.
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
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
If you're interested in learning more about SLAM, feel free to check out:
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.