Nav2 uses Behaviour Trees (BT) to manage high-level logic, state transitions, and recovery actions. This allows the robot to handle complex navigation failures without locking up or acting erratically.

1. The BT Navigator

This is the core node that acts as the primary "brain" of the navigation system.

  • How it works: Instead of hardcoding complex if/else statements in C++ or Python, the navigation logic is orchestrated using a modular XML file.
  • The Benefit: You can completely alter how a robot responds to failures by simply swapping the text in an XML file rather than refactoring or recompiling software code.

2. The Behaviour Server (Recoveries)

The problem solver. If the robot gets trapped, stuck in a tight corner, or encounters a navigation failure, this server executes predefined manoeuvres to fix the situation.

  • Standard Recoveries:
    • Spin: Rotates the robot in place to clear out blind spots in its sensor views.
    • Backup: Backs out a set distance to escape a dead end or a tight cluster of obstacles.
    • Wait: Pauses for a few seconds to see if dynamic obstacle traffic (like a human passing by) clears up on its own.
    • ClearCostmap: Wipes cached sensor memory in case a transient error or phantom reading ghosted the costmap grid.