Nav2
Nav2 is the navigation framework for ROS 2, used to move mobile robots — delivery robots, warehouse AMRs, service robots, research platforms — from one pose to another safely. It combines localization, environmental representation in costmaps, global planners, local controllers, path smoothers, and recovery behaviors, orchestrated by behavior trees that define how navigation proceeds and how failures are handled.
Nav2 is highly configurable through plugins and YAML parameters, which is both its strength and its learning curve. Getting a robot to navigate well depends less on choosing algorithms than on fundamentals: a correct transform tree, accurate odometry, well-tuned costmaps and inflation, controllers matched to the robot's kinematics, and recovery behaviors that resolve common failures without human help.
TL;DR
- Nav2 needs a correct TF tree (map → odom → base_link → sensors), odometry, and localization (AMCL on a known map, or SLAM Toolbox).
- Costmaps combine static maps, live obstacles, and inflation; tune inflation radius and cost scaling to the robot's size and margins.
- Planner server plugins (NavFn, Smac Hybrid-A*, Smac Lattice) compute global paths; controller server plugins (Regulated Pure Pursuit, MPPI, DWB) follow them.
- The BT Navigator runs behavior trees that sequence planning, control, and recovery behaviors (clear costmaps, spin, back up, wait).
- Command navigation with the Simple Commander API or actions such as
NavigateToPoseandFollowWaypoints. - Use the collision monitor, simulate before deploying, and tune on the real robot with recorded data.
Quick Example
Sending a goal with the Simple Commander API and enforcing a time limit:
Part of a local costmap configuration, inflating obstacles around a 0.22 m-radius robot:
Core Concepts
Transforms, Odometry, and Localization
Nav2 follows ROS conventions (REP 105): map → odom → base_link. Odometry (wheel encoders fused with an IMU, often via robot_localization) publishes odom → base_link smoothly; localization publishes map → odom to correct drift. AMCL localizes against a known map with a particle filter; SLAM Toolbox builds maps and can localize in them. Most "Nav2 doesn't work" problems are TF errors: wrong frames, stale transforms, or timestamps out of sync. See Robot Localization and Mapping.
Costmaps
The global costmap covers the whole map for planning; the local costmap is a rolling window around the robot for control. See Robot Perception and Sensing.
Servers and Plugins
Choose planners and controllers by kinematics: differential-drive robots work well with NavFn or Smac 2D plus Regulated Pure Pursuit or MPPI; car-like robots need Smac Hybrid-A* or lattice planners. See Robot Motion Planning.
Behavior Trees and Recovery
The BT Navigator executes a behavior tree (XML) that, in the default tree, computes a path at a set rate, follows it, and on failure runs recovery behaviors in a round-robin — clear costmaps, spin, wait, back up — before retrying or failing the task. Custom trees add mission-specific logic, such as replanning less often, using different controllers in narrow areas, or asking a remote operator for help.
Lifecycle and Safety
Nav2 nodes are lifecycle nodes managed by a lifecycle manager, which brings them up in order and can restart them. The collision monitor checks sensor data against polygons around the robot and slows or stops it independently of planning, a useful extra layer — but not a replacement for certified safety systems. See Robot Safety and Fleet Operations.
Best Practices
Fix TF and Odometry First
Verify frames, timestamps, and odometry accuracy (drive known distances and rotations) before tuning planners.
Tune Costmaps to Physical Margins
Set footprint or radius accurately and choose inflation from real localization and control error.
Match Controllers to Kinematics
Use planners and controllers that respect the robot's motion constraints, and set realistic velocity and acceleration limits.
Simulate, Then Record Real Runs
Test in simulation, then record bags of real runs to reproduce and tune failures.
Common Mistakes
Mismatched Timestamps
Inflation Too Small or Too Large
No Timeout on Goals
FAQ
What is Nav2?
The ROS 2 navigation stack: a set of servers, plugins, and behavior trees that localize a mobile robot, plan paths, follow them while avoiding obstacles, and recover from failures.
What is the difference between the global and local costmap?
The global costmap covers the entire map and is used by the planner; the local costmap is a smaller rolling window around the robot, updated quickly with sensor data and used by the controller.
Which controller should I use?
Regulated Pure Pursuit is a robust, simple default for path following; MPPI offers predictive, constraint-aware behavior for more dynamic environments; DWB is highly configurable. Test them on your robot.
How does Nav2 recover from being stuck?
Its behavior tree runs recovery behaviors such as clearing costmaps, spinning, waiting, and backing up, then retries planning; after repeated failures the navigation task fails and should be escalated.
Do I need SLAM to use Nav2?
You need a map and localization. SLAM Toolbox can build the map; AMCL can localize in a saved map. Nav2 can also navigate with SLAM running live.
Related Topics
- Robot Localization and Mapping — Odometry, AMCL, and SLAM
- Robot Motion Planning — Planners and controllers in depth
- Robotics & Autonomous Systems — The robotics software stack
- Robot Perception and Sensing — Sensors feeding costmaps
- Robot Simulation and Validation — Testing navigation before deployment
- Python — Scripting missions with Simple Commander