For the complete documentation index, see llms.txt. This page is also available as Markdown.

Demo - Mapping and Navigation

This documentation is currently in beta. Please proceed carefully, and if you run into issues or need additional information, reach out to Hello Robot directly for support.

A fundamental feature of mobile robots like Stretch is the ability to create a map of an environment and then navigate around it autonomously. The following tutorial will explain how to quickly build a 2-dimensional map that the robot can use to navigate around your current environment, using ROS 2 software called Nav2.

Building a Map

Building a map of the environment allows the robot to understand where it is currently located, and where you would like it to travel to. Stretch builds maps using the 3D LiDAR sensors located in the robot's head. These sensors allow Stretch to understand the structure of the space around the robot, including the floor, walls, and obstacles. By driving the robot slowly around the space, Stretch builds its understanding of the space, and will create a 2D map of all of the area that it can traverse freely.

1

Home and Stow the Robot

To make a map accurately, it is important that Stretch's arm and gripper are tucked out of the way so that they do not block the view of the sensors. To do this, run the following commands on Stretch, making sure the arm and wrist have free space to move.

stretch_robot_home
stretch_robot_stow
2

Launch the ROS 2 Mapping Node

Start the offline mapping launch file by running the following command in a terminal:

ros2 launch stretch_nav2 offline_mapping.launch.py

If you want to display the live feed from the robot cameras while driving, you can also run the following in a separate terminal window:

stretch_camera_show --opencv --right
3

Begin Teleoperation

In a new terminal, start gamepad teleop by running:

stretch_gamepad_teleop

Just as you did in the Quick Start Guide, use the gamepad left stick and bumpers to move the robot around the space. You can watch the laser scan in RViz to understand what areas the robot has already scanned. Blank sections should be filled in by driving the robot around to get a better view.

Once the map of your space looks fairly complete, you can move to the next step. We recommend starting with just one or two rooms for this initial demonstration.

4

Save the Map

Open a new terminal (leaving the one with the mapping node running) and use the following command to save the map to your fleet directory, replacing <map_name> with the name you want to use (eg stretch_demo_map)

ros2 run nav2_map_server map_saver_cli -f ${HELLO_FLEET_PATH}/maps/<map_name>
5

Close the Mapping Node

Go to the terminal window with the mapping launch file (the one from Step 2), and press Ctrl+C to close the stop the mapping script.

Navigating the Map

Phase 2: Navigating the Generated Map

Now that we have saved a map, we can use it to tell the robot to autonomously navigate through your environment. Stretch will still look for new obstacles around its body, so if an object or person moves through the space, it will adjust and adapt to avoid collisions and plan its movements intelligently.

1

Launch the ROS 2 Navigation Node

Use the following terminal command to start Nav2 and point it to the .YAML file for the map you just created. Don't forget to update the <map_name> parameter to the name you chose above.

2

Set the Initial Robot Position

You should now see the map open on Stretch in the RViz2 software. However, the robot doesn't yet know where it is currently positioned on the map. We'll need to tell it approximately where it is located and which direction it is facing.

In the RViz2 window showing the map, click on the "2D Pose Estimate" button, then click on the robot's current location in the map, and hold and drag in the direction the robot is currently facing. Release to set the robot's orientation.

#this definitely needs a gif or short video

3

Set a Navigation Goal

In RViz2, click the "Nav2 Goal" button, then click a position on the map where you want the robot to navigate to. Make sure the position is inside the free area on the map.

Stretch should now start driving to the location you selected autonomously! Try sending Stretch to different points in the room, then interact with it by moving objects around or standing in front of the robot to force it to react to these new obstacles and find alternative routes.

Troubleshooting and Debugging
  1. Isolate node errors: If navigation fails at startup, try adding use_composition:=false to the navigation launch command. This starts nodes outside a shared container, which makes errors easier to spot.

  2. Remote operation: If you use a remote desktop session, you may need to plug in a dummy HDMI adapter so the display server starts correctly. One of these shipped in the accessory box along with your robot

  3. Navigation does not start after setting the pose: If too much time passes before you set the robot's initial pose, the navigation stack may need to be reset. A common symptom is that the local costmap appears in RViz2, but the global costmap does not.

    To recover:

    1. In the Navigation panel in RViz2, click Startup.

    2. Click Reset.

    3. Set the robot's initial pose again.

    Once the global costmap appears, the robot is ready to accept navigation goals.

Learn More

To learn more information about ROS 2 Nav2 software, check out the official Nav2 Getting Started guide to learn the concepts in simulation. For more advanced topics and tuning guides for navigation on Stretch, you can also explore the tutorials in Navigation University. In the next section, we'll learn how to launch the Web Teleoperation demo to drive Stretch with a user-friendly interface from a remote PC or mobile phone.

Last updated

Was this helpful?