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 your Turtlebot's environment, and 3) save & load the map - visualizing it in RViz.
To start out today's lab, we'll want to create a new ROS package:
$ cd ~/catkin_ws/src/intro_robo
$ catkin_create_pkg lab_c_map_environment_using_slam rospy std_msgs geometry_msgs sensor_msgs
$ cd ~/catkin_ws && catkin_make
$ source devel/setup.bash
Just to keep everything organized, we'll want to create directories called launch
, map
,
worlds
within the lab_c_map_environment_using_slam
directory:
~/catkin_ws/src/intro_robo/lab_c_map_environment_using_slam/launch
~/catkin_ws/src/intro_robo/lab_c_map_environment_using_slam/map
~/catkin_ws/src/intro_robo/lab_c_map_environment_using_slam/worlds
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.
Now, let's run SLAM and generate a map of your Turtlebot3's environment. Do this by executing the following:
Terminal 1: roscore
roscore
Terminal 2: SSH into the Turtlebot and run Bringup
$ ssh pi@IP_OF_TURTLEBOT
$ set_ip LAST_THREE_DIGITS
$ bringup
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 created a full map of your environment (exploring the entire space), you can
save your map (please save it in the ~/catkin_ws/src/intro_robo/lab_c_map_environment_using_slam/map
directory) using the following command (do not add a file extension, it will do so automatically):
$ rosrun map_server map_saver -f filepath_and_filename
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):
If you want to load a map that you've saved and visualize it in RViz, you'll need to create a new roslaunch file
(visualize_map.launch
) 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 lab_c_map_environment_using_slam)/map/your_map_file.yaml" />
<!-- Map server -->
<node pkg="map_server" name="map_server" type="map_server" args="$(arg 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 lab_c_map_environment_using_slam visualize_map.launch map:=map_location.
Once you've saved visualize_map.launch
, you'll need to have running in your terminals:
Terminal 1:
$ roscore
Terminal 2:
$ ssh pi@IP_OF_TURTLEBOT
$ bringup
Terminal 3:
roslaunch lab_c_map_environment_using_slam visualize_map.launch
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. To do that you'll need to hit the Add
button at the bottom left
and specify the /map
topic (see gif below).
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 Turtlebot3 ROS 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. Feel free to 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.