Overview
Nav2 (Navigation 2) is the ROS2 navigation stack. It enables robots to autonomously navigate from point A to point B while avoiding obstacles.Nav2 combines localization, mapping, path planning, and obstacle avoidance into a complete autonomous navigation system.
Nav2 Architecture
Components
Planner Server
Computes global path from start to goal using map. Algorithms: NavFn, Smac Planner.
Controller Server
Follows path while avoiding dynamic obstacles. Algorithms: DWB, TEB, MPPI.
Behavior Server
Executes recovery behaviors (backup, spin, wait) when stuck.
BT Navigator
Coordinates all servers using Behavior Trees (decision logic).
Waypoint Follower
Navigates through multiple waypoints in sequence.
Lifecycle Manager
Manages server lifecycles (startup, shutdown, recovery).
Map Server
Provides occupancy grid map (from SLAM or pre-built).
AMCL / Localization
Localizes robot in map (corrects odometry drift).
Prerequisites
Before using Nav2:- Map created (using SLAM Toolbox or Cartographer)
- Localization working (EKF fusion or AMCL)
- Odometry accurate (<5% error)
- LiDAR functioning (publishes
/scan) - Robot control (accepts
/cmd_vel) - TF tree complete (map → odom → base_link)
Installation
Basic Configuration
Minimal Nav2 Parameters
File:config/nav2_params.yaml
Launch File
File:launch/navigation.launch.py
Complete System Launch
File:launch/robot_navigation.launch.py
RViz Configuration
Launch RViz
Essential Displays
-
Fixed Frame:
map -
Map - Static map
- Topic:
/map - Color Scheme: map
- Topic:
-
Global Costmap - Planning costmap
- Topic:
/global_costmap/costmap - Color Scheme: costmap
- Topic:
-
Local Costmap - Local obstacle avoidance
- Topic:
/local_costmap/costmap - Color Scheme: costmap
- Topic:
-
Global Plan - Computed path
- Topic:
/plan - Color: Green
- Topic:
-
Local Plan - Trajectory being followed
- Topic:
/local_plan - Color: Red
- Topic:
-
LaserScan - LiDAR data
- Topic:
/scan
- Topic:
- RobotModel - Robot visualization
- TF - Coordinate frames
-
2D Nav Goal - Set navigation goals
- Toolbar → 2D Nav Goal button
Save RViz Config
File → Save Config As →rviz/navigation.rviz
Sending Navigation Goals
Method 1: RViz (Interactive)
- Click “2D Nav Goal” button in toolbar
- Click and drag on map:
- Click: Goal position
- Drag direction: Goal orientation
- Release mouse
- Robot navigates to goal!
Method 2: Command Line
Method 3: Python Script
Navigation Workflow
1
Launch Complete System
- All nodes running (
ros2 node list) - Map loaded (
/maptopic) - Localization active (AMCL or EKF)
- Costmaps publishing
2
Localize Robot
If using AMCL:
- Open RViz
- Click “2D Pose Estimate”
- Click robot’s actual position on map
- Drag to set orientation
- Watch particles converge
- Already localized automatically
3
Send Navigation Goal
- Click “2D Nav Goal” in RViz
- Click goal position on map
- Drag to set orientation
- Release mouse
4
Monitor Navigation
Watch in RViz:
- Green path (global plan) from robot to goal
- Red trajectory (local plan) adjusting around obstacles
- Robot moving toward goal
- Costmaps updating in real-time
5
Goal Reached
Success indicators:
- Robot stops at goal
- Status: “Goal succeeded”
- Velocity commands stop (
/cmd_vel= 0)
- Check logs:
ros2 node logs /controller_server - Common: Path blocked, timeout, robot stuck
Behavior Tree
Nav2 uses Behavior Trees for decision logic:Troubleshooting
No path found
No path found
Causes:
- Goal in occupied space
- Goal too close to obstacle
- No valid path exists
- Choose different goal
- Increase planner tolerance
- Check global costmap (goal might appear blocked)
Robot won't move
Robot won't move
Debug:
-
Check
/cmd_velpublished: - Check controller server status
- Verify robot control stack running
- Check velocity limits not too restrictive
Robot oscillates / unstable
Robot oscillates / unstable
Cause: Controller gains too aggressiveSolutions:
- Reduce max velocities
- Increase controller frequency
- Tune DWB parameters
- Switch controller plugin (try TEB or MPPI)
Gets stuck near obstacles
Gets stuck near obstacles
Cause: Costmap inflation too largeSolution:
- Reduce
inflation_radius - Reduce
cost_scaling_factor - Check
robot_radiusaccurate
Next Steps
Path Planning
Deep dive into planners and costmaps
Behavior Trees
Customize navigation behavior
Navigation Testing
Systematic navigation validation
AMCL Localization
Localize robot in pre-built map