BehaviorTree.CPP
Presentation Title 4.0
Presentation
Subtitle
Newfeaturesand how they make your life easier
January 2022
October
21st, 2022

Davide Faconti
StaffYour Engineer
Name | name@picknik.ai
davide.faconti@picknik.ai

About me
Davide Faconti, nice to meet you
Working at Picknik (but not on Behavior Trees)
Almost 20 years in robotics doing:●

Humanoid robots design●Task planning●

Bipedal Dynamic Walking●

Tooling and monitoring●

Low hardware drivers●

System architectures●Navigation and Localization●Project Management●Perception●

Product development●

Manipulation●But….

About me
Davide Faconti, nice to meet you
Working at Picknik (but not on Behavior Trees)
Almost 20 years in robotics doing:●

Humanoid robots design●Task planning●

Bipedal Dynamic Walking●Tooling and monitoring●

Low hardware drivers●System architectures●

Navigation and Localization●Project Management●

Perception●

Product development●

Manipulation●But….

What to expect in the next 20 minutes
Me, showing pie-charts
Apparently
random slides

Finally presenting
BT.CPP 4.0

Simplistic introduction
to BT.CPP
I am not going to explain what Behavior Trees areWhat makes software “good” and why do we want that?
Good software is always about “getting thingsdone”, but considering the human first
Plato

01 Writing software that a computer can interpret andrun makes the software “correct”, but not “good”.

02

The bottleneck to scale up a software system isusually the ability of the human mind to manage
complexity.
This is the reason why a good software is one that03 decreases the perceived complexity.

Aristotle

How do you react to the concerns of your user?

Option 1:

Option 2:“You are…”

Or we can use empathy tounderstand your user’s point of view

Advantages of Behavior Trees
Advantages of Behavior Trees:●

Easier to “read”
Graphical representation of FSMs rapidly become “spaghetti”.

●

Intrinsically hierarchical
Similar to Hierarchical State Machines.

●

Focus on actions, not states
We usually model our problem in terms of actions, not states.

●

Extensibility of the “language”
Decorators and Control logic provide powerful abstractions●

But… they are not as intuitive for the user :(People are very familiar with state machines, and mapping theirideas into behavior tree could be challenging

BehaviorTree.CPP●

Nodes are defined in C++, Trees in XML
The best of compiled and interpreted languages together

BehaviorTree.CPP●

Nodes are defined in C++, Trees in XML
The best of compiled and interpreted languages together●

Increasing popularity in the ROS community
Driven probably by the early adoption of Nav2

“Behavior Trees and State Machines in
Robotics Applications”
Razan Ghzouli, Swaib Dragule, Thorsten Berger,
Einar Broch Johnsen, Andrzej Wasowski
arXiv:2208.04211

BehaviorTree.CPP●

Nodes are defined in C++, Trees in XML
The best of compiled and interpreted languages together●

Increasing popularity in the ROS community
Driven probably by the early adoption of Nav2●

Technically decoupled from ROS
A double-edged sword: easy to include in any project, but notidiomatic in the context of ROS.

BehaviorTree.CPP●

Nodes are defined in C++, Trees in XML
The best of compiled and interpreted languages together●

Increasing popularity in the ROS community
Driven probably by the early adoption of Nav2●

Technically decoupled from ROS
A double-edged sword: easy to include in any project, but notidiomatic in the context of ROS.

●Tooling and Graphic interfaces
Groot is a useful tool that provides editing and real-timemonitoring. MoveIt Studio integrates a BT editor, too.

Behavior Trees as extensible Domain Specific Language

In electronics, the NAND gate is the building block that you can use to build theothers.
Similarly, the most atomic concept of FSM is the state transition.

The way Behavior Trees provide high level of abstraction
goes beyond hierarchical compositions:●You can create complex behaviors by composition ofNodes and SubTrees●But you can also “extend the language”, creating yourown custom Decorators and Controllers.

Current problems with BT.CPPSometimes, it takes too much time to map yourmental model of the problem into a tree!!

Because we still think in terms of “states”( Do you remember what we said about “you are doing it wrong” and empathy? )Let me rephrase…

Behavior Trees don’t want you tothink in terms of states.
What if that is our weakness?

Introducing…

BehaviorTree.CPP 4.0

Goals of version 4.001Reduce the cognitive effort of both theperson designing the tree or reviewing it.

02

Translate more effectively the “mentalmodel” of the designer into a tree.

03

Add more expressivity to the XML codeand the GUI representation.

04

In short: enhanced productivity

A scripting language inside BTs

We can now add simple piece of code (“one liners”) to express equality, assignment, comparison,arithmetic operations and if-then-else. Our variables are the elements of the blackboard.

Examples:; p a r a m_ B = ‘ h e l l o ’ ; e r r o r _ c o de = 4 2Assignment●

param_A = 5.0●( p a r a m_ A ! = p a r a m_ B) && ( e r r o r _ c od e == 0 )Logic operators●s p e e d = ( ma x _ s p e e d / 2 ) + 4

Arithmetic●t a r g e t = ( v o l t a g e < 1 0 ) ? ‘ r e c h a r g e _ p os e ’ : ‘ l o a d _ p os e ’

If-then-else clauses

Example: Initializing blackboard variables

BeforeAfter(multiple commands using semicolons)Example: the Precondition Decorator

BeforeAfter(not just equality)

States can make your BT layout simpler

This solves the most common limitation of BTs: sometimes you DO wantto think in terms of states and you need to return multiple results

Pre and Post conditions●

Now that we have unleashed the power ofscripts, we can go a step further, adding Preand Post conditions to every Node●

Shamelessly inspired by Unreal Engine BT●

It needs GUI support to become a gamechanger (but you will have to wait).

●Implemented as optional XML attributes

Example

This is a Node (or an entire, complex SubTree) executed only if (voltage <= 15).
Blackboard variable state changed to string “landed” if the Node return
SUCCESS.

XMLGUIOne more examples

Here, instead of recovering locally to the FAILURE of MoveBase, I want to do the recovery
routine in another part of the tree. I use the port “results” to remember that.

BeforeAfter(with enums!)

Pre-conditions●

Optional Scripts executed before
the actual tick()_skipIf

Skip (don’t execute this node) if
condition is true

●Can be used to “skip” the executionof a Node and its children.

_f a i l ur e I f

Skip and return FAILURE●

Being able to halt a RUNNING
Node, it is technically equivalent toReactiveSequence (but better?)_s uc c e s s I f

Skip and return SUCCESS_whi l e

Don’t start, or halt a RUNNING
Node, if the condition becomes false

Post-conditions●

Optional Scripts executed after theactual tick()_onSuccess

Script executed if Node returns
SUCCESS●Can be used to set variables (states,error codes, etc.)_onFa i l ur e

Script executed if Node returns
FAILURE●In 3.X it was impossible to detect if anaction was halted. Now we can useonHalted()_onHa l t e d

Script executed if a RUNNING
Node was halted_pos tScript executed if Node returns
either SUCCESS or FAILURE

Documentation, tutorials and Migration guide

I hope you enjoy reading this as much as I hated writing itWhat to expect next●

Currently in Alpha.
More stable releases by the end of the year.

●Feedback from the community
AKA, “you”. Try it, ask questions, give ideas.

●Editors supporting the newfeatures
MoveIt Studio and Groot 2.0●Documentation and design
patterns
We need to create idiomatic use of BTs

MoveIt Studio Developer Platform combines BehaviorTree.cpp with MoveIt