Class Meeting 07: SLAM


Today's Class Meeting



What You'll Need for Today's Class


For today's class, you'll need the following tools/applications ready and running:


Class Exercise: SLAM in Action


Please head into these breakout rooms for this class exercise.

The Turtlebot3 ROS packages have nodes that can perform SLAM and output a map of an environment that the Turtlebot3 navigates. For more details on executing Turtlebot3's SLAM nodes, feel free to check out the Turtlebot3 SLAM documentation.

Turtlebot3 SLAM

Running SLAM and Generating a Map


To run SLAM and generate a map of your Turtlebot3's environment, execute the following:

Terminal 1: roscore

roscore

Terminal 2: Launch the simulated environment for your Turtlebot3 to explore (a full list of possible simulated environments that you can launch can be found in the turtlebot3_simulations ROS package)

roslaunch turtlebot3_gazebo name_of_launchfile.launch

Terminal 3: Run the slam node

roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping

Terminal 4: Teleoperate the Turtlebot3 around the environment until you get a complete map

roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

Terminal 5: After you have finished exploring your environment with your Turtlebot3, you can save your map using the following command

rosrun map_server map_saver -f filepath_and_filename.yaml

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

Loading a Saved Map


If you want to load a map that you've saved and visualize it in RViz, you'll need to create a launch file that contains the following:

<launch>

  <arg name="open_rviz" default="true"/>
  <arg name="model" default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]"/>
  <arg name="map" default="$(find particle_filter_project)/map/house_map.yaml" />

  <!-- Map server -->
  <node pkg="map_server" name="map_server" type="map_server" args="$(map)"/>

  <!-- Run a transformation between the map and odom frames -->
  <node pkg="tf" type="static_transform_publisher" name="link1_broadcaster" args="0 0 0 0 0 0 /map /odom 100" />

  <include file="$(find turtlebot3_bringup)/launch/turtlebot3_remote.launch">
    <arg name="model" value="$(arg model)"/>
  </include>

  <!-- rviz -->
  <node name="rviz" pkg="rviz" type="rviz" args="-d $(find turtlebot3_gazebo)/rviz/turtlebot3_gazebo_model.rviz"/>

</launch>

In the launch file code above, you'll either need to 1) change your default map location in your launchfile code to the location where you saved your map or 2) set the map argument when you run the launchfile, e.g., roslaunch package_name launch_file_name.launch map:=map_location.

Once you have RViz open, you will also need to add a map object and have it subscribe to the /map topic in order to visualize the map.


Further SLAM Learning Materials


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


Particle Filter Project Studio (Work) Time


Once you've finished having fun exploring the built-in SLAM Turtlebot3 ROS packages, please head to a breakout room with your particle filter project partner, where you can continue working on your particle filter project.

The teaching team will check in with each particle filter project team today. When one of us comes to your Zoom breakout room, please be ready to communicate the following with us:

Once a member of the teaching team has checked in with your team, you and your partner are free to either:

  1. stay in your breakout room and continue working on the project until the end of class time or
  2. leave and either work with your partner outside of an Intro Robotics Zoom breakout room or simply leave.
The teaching team will stick around until the end of the class period to answer any questions you might have about the particle filter project and/or discuss your projects with you.