Navigating with Stretch
Use this workflow to create a 2D map and navigate with ROS 2 Nav2.
Phase 1: Generating a Map
Video: Mapping workflow
1. Home the robot: Home the joints before any mobile operation.
stretch_robot_home2. Stow the robot: Stow the arm so it stays within the base footprint.
stretch_robot_stow

3. Launch the mapping node: In a terminal, start the offline mapping launch file.
Optional: Enable the camera view if you want a live feed while driving.
4. Start teleoperation: In a second terminal, start the gamepad node and drive the robot through the area you want to map. See the gamepad teleop primer for setup and controls.
5. Save the map: After you cover the full area, leave the mapping node running. Open a new terminal and save the map to your fleet directory. Replace <map_name> with a name such as hq_upstairs.
6. Close the mapping node: Before starting navigation, stop the mapping launch file with Ctrl+C in its terminal.
Phase 2: Navigating the Generated Map
With the map saved, you can navigate autonomously.
Video: Navigation workflow
1. Launch navigation: Start Nav2 and pass the YAML file for the map you just created.
2. Set the initial pose: Set the robot's initial pose so it matches the robot's actual position and orientation on the map.
You can set the pose interactively in RViz2 using 2D Pose Estimate:
Click at the robot's current location on the map.
Hold and drag in the direction the robot is facing.
Release to set the robot's orientation.
Alternatively, you can configure a fixed initial pose in the AMCL parameters so Nav2 initializes at the same location each time it starts. Add the following to your AMCL configuration file:
The values above are examples only. Replace x, y, and yaw with the robot's actual starting position and orientation in your map.
Video: Setting the initial pose in RViz2
3. Send a goal: Use Nav2 Goal in RViz2 (as shown in the navigation video), or send a goal from the terminal. Make sure the position is inside the map bounds and clear of obstacles.
Troubleshooting and Debugging
Isolate node errors: If navigation fails at startup, add
use_composition:=falseto the navigation launch command. This starts nodes outside a shared container, which makes errors easier to spot.Remote operation: If you use a remote desktop session, plug in a dummy HDMI adapter so the display server starts correctly.
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:
In the Navigation panel in RViz2, click Startup.
Click Reset.
Set the robot's initial pose again.
Once the global costmap appears, the robot is ready to accept navigation goals.
Video: Resetting the Nav2 stack in RViz2
Last updated
Was this helpful?
