Behavior trees (BT) are becoming increasingly common in complex robotics tasks. They are a tree structure of tasks to be completed. It creates a more scalable and human-understandable framework for defining multi-step or many-state applications. This is opposed to a finite state machine (FSM) which may have dozens of states and hundreds of transitions. An example would be a soccer-playing robot. Embedding the logic of soccer gameplay into an FSM would be challenging and error-prone with many possible states and rules. Additionally, modeling choices like shooting at the goal from the left, right, or center, are particularly unclear. With a BT, basic primitives, like “kick”, “walk”, and “go to ball”, can be created and reused for many behaviors.
Some additional information can be found here.
Behavior Trees provide a formal structure for navigation logic which can be to create complex systems but also be verifiable and validated as provenly correct using advanced tools. Having the application logic centralized in the behavior tree and with independent task servers (which only communicate data over the tree) allows for formal analysis.
Using the BehaviorTree CPP V3
behavior tree library, we create node plugins that can be constructed into a tree, inside the BT Navigator
node. The node plugins are loaded into the BT and when the XML file of the tree is parsed, the registered names are associated. At this point, we can march through the behavior tree to navigate.
An example of a Navigate to Pose
Behavior Tree is shown below:
This tree diagram describes the actions to take given a request and response structure. The tree on the right is the Recovery
tree, which details the steps to take in the event of a failure within the Navigation
tree.
The XML
code describing the behavior tree above looks like below:
<root main_tree_to_execute="MainTree">
<BehaviorTree ID="MainTree">
<RecoveryNode number_of_retries="6" name="NavigateRecovery">
<PipelineSequence name="NavigateWithReplanning">
<RateController hz="1.0">
<RecoveryNode number_of_retries="1" name="ComputePathToPose">
<ComputePathToPose goal="{goal}" path="{path}" planner_id="GridBased"/>
<ReactiveFallback name="ComputePathToPoseRecoveryFallback">
<GoalUpdated/>
<ClearEntireCostmap name="ClearGlobalCostmap-Context" service_name="global_costmap/clear_entirely_global_costmap"/>
</ReactiveFallback>
</RecoveryNode>
</RateController>
<RecoveryNode number_of_retries="1" name="FollowPath">
<FollowPath path="{path}" controller_id="FollowPath"/>
<ReactiveFallback name="FollowPathRecoveryFallback">
<GoalUpdated/>
<ClearEntireCostmap name="ClearLocalCostmap-Context" service_name="local_costmap/clear_entirely_local_costmap"/>
</ReactiveFallback>
</RecoveryNode>
</PipelineSequence>
<ReactiveFallback name="RecoveryFallback">
<GoalUpdated/>
<RoundRobin name="RecoveryActions">
<Sequence name="ClearingActions">
<ClearEntireCostmap name="ClearLocalCostmap-Subtree" service_name="local_costmap/clear_entirely_local_costmap"/>
<ClearEntireCostmap name="ClearGlobalCostmap-Subtree" service_name="global_costmap/clear_entirely_global_costmap"/>
</Sequence>
<Spin spin_dist="1.57"/>
<Wait wait_duration="5"/>
<BackUp backup_dist="0.15" backup_speed="0.025"/>
</RoundRobin>
</ReactiveFallback>
</RecoveryNode>
</BehaviorTree>
</root>
One reason this library is used is its ability to load subtrees. This means that the Nav2 behavior tree can be loaded into another higher-level BT to use this project as a node plugin. An example would be in soccer play, using the Nav2 behavior tree as the “go to ball” node with ball detection as part of a larger task. Additionally, we supply a NavigateToPoseAction
plugin (among others) for BT so the Nav2 stack can be called from a client application through the usual action interface.
More detailed information regarding configuring and understanding behavior trees can be found on the Nav2 wiki.
<aside> 💡 For a more in-depth understanding of behavior trees, you can use the documentation within the Nav2 wiki. This is not necessary to get your system running but is useful to know for more complicated implementations.
</aside>
Nav2 Behavior Trees — Navigation 2 1.0.0 documentation
Home Page: NAV 2
Next Page: Navigation Servers