Behavior Trees for Nav2 and Robot Autonomy¶
Source: ros2-copilot-skills catalog
Why This Matters¶
Behavior trees are where many ROS 2 robots stop being demos and start becoming systems. They let you centralize decision logic, make recovery behavior explicit, and build reusable autonomy pieces without burying application logic across launch files, timer callbacks, and one-off state variables.
Distilled Takeaways¶
- Nav2 uses BehaviorTree.CPP v4, and the XML file is not just configuration. It is the robot's decision structure for navigation.
- Control nodes, decorator nodes, and blackboard variables shape behavior as much as the leaf action nodes do.
- Blackboard hygiene matters. If data flow between nodes is vague, the tree becomes difficult to debug and harder to evolve safely.
- Waypoint following is enough for some task dispatch patterns, but richer autonomy usually needs an application-level tree that reasons about failures, retries, and robot state.
- Logging and visualization are not optional once trees become non-trivial. A BT without observability becomes a hidden state machine.
Practical Value¶
- Use a small number of well-named subtrees rather than one giant XML file.
- Treat recovery logic as a first-class subtree, not as a last-minute appendage.
- Keep application-level autonomy decisions above the lower-level navigation action nodes.
- Use Groot2 and trace logging early, before the tree becomes too large to reason about by inspection.
Start Here¶
- For BT execution semantics: Behavior Tree Ticks, Status, and Control Flow
- For Nav2 leaf-node structure: Nav2 Behavior Tree Action Nodes, Behavior Tree Control Nodes, and Behavior Tree Decorator Nodes
- For extending the tree with your own code: Custom Nav2 BT Plugins and Configuration, Custom BT Action Nodes in C++, and Custom BT Action Nodes in Python
Corroborating References¶
When to Read the Original Source¶
Go to the original skills when you need exact XML patterns, subtree composition examples, custom node extension points in Python or C++, and practical advice on mixing built-in Nav2 nodes with higher-level patrol or multi-goal logic.