"Separation of Concerns" and "Composability" are two core principles
you need to understand to build good robotic systems
We want to build a high level "Task Planner", AKA "Coordinator / Orchestrator" that executes complex behaviors in a Service Oriented system.
An alternative to Hierarchical State Machines.
A Domain Specific Language to describe Behaviors.
Complexity increases exponentially with size.
The complexity of BehaviorTree grow more slowly
Tick the children, from left to right, while they return SUCCESS.
if a child returns FAILURE, stop and return FAILURE.
Tick the children, from left to right, while they return FAILURE.
If a child returns SUCCESS, stop and return SUCCESS.
Decorators are a very simple and powerful way to implement more complex logic.
It would be very complicated to do the same with state machines
There are no beers in the fridge and I don't want to keep the door of the fridge open
bool FetchBeer()
{
if( GoTo("kitchen") &&
OpenFridge() &&
Grasp("beer") &&
CloseFridge() )
{
return true;
}
else{
return false;
}
}
In the context of Behavior Trees this mean:
If we think about SubTrees and Nodes as functions, it is easy to understand how we need input and output to be modeled explicitly.
This is done in Behavior Tree using the Blackboard, a simple key-value storage
The only building block of State Machines are the transitions.
Behavior Trees have more abstractions, but you probably want to have even more (or different one) to make your tree more readable and less verbose.
We are applying here the same rules about "clean code" and "readability".
About Behavior Trees in general
About BehaviorTree.CPP