Skip to content

Behavior Trees

Martin Molina edited this page Jun 4, 2021 · 3 revisions

A mission plan can be specified in Aerostack using behavior tree. A behavior tree is a modelling language that uses a graphical notation to represent the behavior of a system. Aerostack provides a tool related to behavior trees called behavior tree interpreter.

Behavior tree representation

The user can specify a mission plan using a text file using YAML syntax using the following representation.

Types of tree nodes

Each behavior tree is represented with a hierarchy of executable nodes. Nodes can succeed or fail during the execution of the mission plan. When the operator creates a behavior tree, the operator gives a name to each node and associates a particular type.

Leaf nodes are used to execute simple actions. The types of leaf nodes are the following:

  • Task. A task node specifies a particular task that Aerostack can execute with a robot behavior, such as TAKE_OFF, LAND or FOLLOW_PATH. To know the available list of behavior tasks, consult the following link: catalog of behavior tasks. If the type is goal-based, this node succeeds when the goal is accomplished. If the type is recurrent, this node succeeds if the task is correctly started (or if it is correctly stopped).
  • Add belief. This node adds a belief expression to the memory of beliefs. It succeeds if the belief is correctly added, otherwise fails.
  • Remove belief. This node removes a belief expression from the memory of beliefs. It succeeds if the belief is correctly removed, otherwise fails.
  • Query. A query node corresponds to a question that is verified in the memory of beliefs. The question is formulated with a belief expression with a set of predicates that, optionally, can include variables. This node succeeds if the belief expression is true, otherwise it fails. Queries are useful to help control the mission workflow.

Intermediate nodes of the tree establish the control regime (e.g., a sequence, a loop, etc.). The types of intermediate nodes are the following:

  • Sequence. This node executes the child nodes in sequence and succeeds when all the children succeed. Otherwise it fails.
  • Selector. This node executes the child nodes in sequence and succeeds when one of the children succeeds. If none of them succeeds, it fails.
  • Parallel. This node executes its child nodes in parallel. Let N be the number of child nodes. It returns success if the number of succeeding children is larger or equal than a local constant S, specified by the user. Returns failure if the number of failing children is larger N - S.
  • Repeat. This node repeats the execution of a child node a number of times. Returns success. It can only have one child node.
  • Repeat until fail. This node repeats the sequential execution of child nodes until a child node fails. This node always succeeds.
  • Inverter. This node returns failure if the child node succeeds. Otherwise it succeeds.
  • Succeeder. This node executes its child node and, no matter what is the result of the execution, it always succeeds.

Belief expressions and variables

When the user creates a node corresponding to a behavior task, the user can write specific parameters. For example, if the user creates a node corresponding to the task GENERATE_PATH, the user can write the parameters in the corresponding box of the window as follows:

destination: [7.5, 8.5, 3.5]

Behavior trees in Aerostack can use variables to communicate information between leaf nodes. For example, the user can create a query node called "Identify current position" with the belief expression:

self(?R), position(?R,(?X,?Y,?Z))

In this expression, R, X, Y, and Z are preceded by a question mark (?) to represent that they are variables. When this node is executed, the expression matches the corresponding predicates in the belief memory. For example, if the belief memory has the predicates self(1), position(1, (3.3, 8.7, 0.6)), the variables get the values R = 1, X = 3.3, Y = 8.7, Z = 0.6.

The values of these variables can be used by other nodes of the mission plan. For instance, there may be an operation node in another place of the same mission plan that uses the behavior GENERATE_PATH with the following argument:

destination: [+X, +Y, +Z]

The sign plus (+) as a prefix of the variable name indicates that the variable will be substituted during the execution by the value that the variable has in this moment. Considering the previous example, this means that the robot will requested to go to a destination with the coordinates (3.3, 8.7, 0.6).

Behavior tree interpreter

The goal of the behavior tree interpreter is to execute a mission formulated as a behavior tree.

To launch the behavior tree interpreter (for example, for the robot namespace drone7 and the mission configuration folder $AEROSTACK_STACK/projects/my_project/configs/mission), the command is:

$ roslaunch behavior_tree_interpreter behavior_tree_interpreter.launch --wait robot_namespace:=drone7 drone_id:=7 mission_configuration_folder:=$AEROSTACK_STACK/projects/my_project/configs/mission catalog_path:=$AEROSTACK_STACK/config/mission/behavior_catalog.yaml

The interpreter loads a behavior tree from a yaml file and presents it graphically using a hierarchy browser.

When the user press the button 'start mission', the interpreter starts executing the behavior tree and shows graphically the dynamic evolution of the execution. The interpreter can show in an additional window the values of variables used by the behavior tree.

The interpreter also facilitates preemptive interaction between the user and the robot. Users can interrupt the mission at any point and they can continue the execution in another node of the behavior tree or can teleoperate the drone manually.