Prerequisites
Before using autonomous navigation, you must have:- A saved map: Create a map using SLAM first
- Map files: Both
.pgmand.yamlfiles in~/maps/ - Matching simulation world: Use the same world where you created the map
You cannot navigate autonomously without a map. Complete the SLAM mapping process first before attempting navigation.
Starting Navigation2
Using the alias
The pre-configured alias starts Navigation2 with your saved map:~/maps/my_map.yaml.
Using the full command
For more control or different map locations:Complete navigation workflow
Launch simulation
Start the same world you used for mapping:The simulation environment must match your saved map.
Start Navigation2
In a second terminal, launch Nav2 with your map:RViz2 will open automatically showing your map.
Set initial pose
In RViz2:
- Click the “2D Pose Estimate” button in the toolbar
- Click on the map where the robot is currently located
- Drag to set the robot’s orientation
- Release the mouse button
Set navigation goal
In RViz2:
- Click the “Navigation2 Goal” button in the toolbar
- Click on your desired destination on the map
- Drag to set the desired final orientation
- Release the mouse button
Using RViz2 for navigation
Initial pose estimation
Telling Nav2 where the robot is located on the map. Steps:- Click “2D Pose Estimate” button (top toolbar)
- Click on the map at the robot’s current location
- Drag the arrow to match the robot’s orientation
- Release to set the pose
- Green particle cloud appears around the robot
- Particles should converge to a tight cluster
- If particles are spread out, your pose estimate is inaccurate
Setting navigation goals
Telling the robot where to go. Steps:- Click “Navigation2 Goal” button (top toolbar)
- Click on your desired destination on the map
- Drag to set the final orientation you want
- Release to start navigation
- Nav2 computes a global path (green line)
- Robot begins moving toward the goal
- Local planner adjusts for dynamic obstacles
- Robot stops when goal is reached
Monitoring navigation
In RViz2, watch:- Global path (green line): Planned route to goal
- Local costmap (colored grid around robot): Obstacle awareness
- Robot footprint (small square): Robot’s physical size
- Laser scan (red dots): Real-time sensor data
- Robot moving: Navigation is active
- Robot stopped at goal: Success!
- Robot oscillating: Path planning difficulty
- Robot stopped mid-path: Obstacle blocking or navigation failure
Workflow examples
Navigate in TurtleBot3 world
Terminal 1: Launch world- Set initial pose where robot starts
- Click Navigation2 Goal
- Choose a destination across the map
- Watch the robot navigate autonomously
Navigate in house environment
Terminal 1: Launch house- Set initial pose in the starting room
- Set navigation goal in a different room
- Watch the robot navigate through doorways autonomously
Best practices
Accurate initial pose
Critical for success:- Look at robot position in Gazebo
- Match that position on the RViz2 map
- Align the arrow with robot’s facing direction
- If navigation fails, reset the initial pose
- Particle cloud should be tight and small
- Laser scan should align with map walls
- Robot’s position should match Gazebo
Choosing good goals
Select destinations that:- Are in open, free space (white areas on map)
- Have clear paths from current location
- Avoid narrow passages for first attempts
- Are reachable without complex maneuvering
- Are in or near obstacles (black areas)
- Require passing through very narrow spaces
- Are in unknown areas (gray on map)
Dealing with navigation failures
If the robot stops moving:Choose closer goal
Try a shorter navigation distance first, then navigate to the original goal in steps.
Understanding Nav2 behavior
Path planning
Nav2 uses two planners: Global planner:- Plans overall route from start to goal
- Uses the static map
- Shown as green line in RViz2
- Computed once per goal
- Adjusts path in real-time
- Avoids dynamic obstacles
- Follows global path while avoiding collisions
- Continuously updated
Costmaps
Nav2 uses costmaps to represent obstacle information: Global costmap:- Based on your saved map
- Covers entire environment
- Static obstacles
- Small area around robot
- Updated with live sensor data
- Detects dynamic obstacles
- Shown as colored grid in RViz2
Recovery behaviors
If navigation gets stuck, Nav2 automatically tries:- Rotation: Spin in place to find a path
- Backing up: Move backward to escape tight spots
- Clear costmap: Reset obstacle information and retry
Troubleshooting
Robot won’t move
Map doesn’t match environment
Cause: Using a map from a different world. Solution:- Always use the map created for the current simulation world
- If you’re in
tb3_world, use the map created when you exploredtb3_world - Re-create the map if you’ve modified the environment
Robot gets stuck
Use teleoperation
Temporarily control the robot manually:Move to open space, then restart navigation.
Poor navigation performance
Symptoms:- Robot takes inefficient paths
- Excessive oscillation
- Frequent recovery behaviors
- Create a higher quality map with SLAM (drive slower during mapping)
- Ensure initial pose is very accurate
- Choose goals in open areas
- Adjust Nav2 parameters for your environment (advanced)
RViz2 not showing map
Advanced navigation
Multi-goal navigation
Navigate to multiple points sequentially:- Set first goal and wait for completion
- Set second goal and wait
- Continue for each destination
Waypoint following
Nav2 supports waypoint following through the Nav2 Waypoint Follower for complex routes.Parameter tuning
Advanced users can tune Nav2 parameters:- Planner settings
- Controller gains
- Costmap configurations
- Recovery behavior thresholds