On the Implementation of Behavior Trees in Robotics

Michele Colledanchise, Lorenzo Natale

TL;DR

While Behavior Trees (BTs) originated in the gaming industry to control NPCs, applying them to physical robots requires significant architectural shifts. This paper outlines the practical implementation challenges—such as asynchronicity, safe preemption, and memory management—and provides a roadmap for integrating BTs into modern robotic software stacks.

What Problem Does This Paper Address?

Behavior Trees have become a popular alternative to Finite State Machines (FSMs) because they are modular, flexible, and easy to reuse. However, there is a fundamental difference between a virtual agent in a video game and a physical robot: robots operate in uncertain, high-latency environments where actions (like moving to a room) take time and can fail in complex ways.

Standard BT implementations often struggle with:

  1. Asynchronicity: How do you "tick" a tree at 100Hz when a single action takes 30 seconds to complete?
  2. Reactivity: How do you safely interrupt a running robot action if a higher-priority safety condition is triggered?
  3. Data Flow: How do different nodes share information (like an object's 6D pose) without creating "spaghetti code"?

The authors address these gaps by defining the implementation choices necessary to make BTs "robot-ready."

Methods

The paper doesn't propose a single new algorithm but rather formalizes a set of implementation patterns and architectural layers:

  • Composition Nodes with Memory: The authors describe "stateful" nodes that remember which children have already succeeded. This prevents a robot from needlessly re-detecting an object it has already found, saving computational resources.
  • Asynchronous Action Execution: They contrast "synchronous" execution (splitting actions into tiny steps) with "asynchronous" execution (running actions in separate threads or using coroutines). They specifically highlight Coroutines as an elegant way to yield control back to the BT engine without blocking.
  • The Halting Procedure: A critical addition for robotics is a formal Halt() or Abort() routine. This ensures that when a BT switches tasks, the robot is left in a stable state (e.g., a bipedal robot placing both feet on the ground before stopping).
  • Layered Architecture: They propose a four-layer model:
  • Mission Layer: High-level goal (e.g., "Serve a customer").
  • Task Layer: The BT itself, describing the logic.
  • Skill Layer: The implementation of leaf nodes (e.g., "Grasp Object").
  • Service Layer: The low-level drivers and middleware (e.g., ROS).

Datasets

Not discussed in the paper. As a technical letter focused on implementation and architecture, it does not rely on a specific benchmark dataset but rather demonstrates its concepts through a physical robot use case.

Key Insights and Ideas

  • Reactivity vs. Memory: There is a constant tension between being reactive (re-checking everything every tick) and being efficient (using memory nodes). The authors argue that while memory nodes save power, they can make a robot "blind" to environmental changes if not used carefully.
  • The Blackboard Dilemma: Most BTs use a "Blackboard" (shared memory) for communication. The authors warn that for large trees, this can jeopardize modularity. They suggest scoped variables or middleware-based parameter servers (like the ROS Parameter Server) as more robust alternatives.
  • BTs as FSM Generalizations: Theoretically, any BT can be represented as an FSM, but the BT representation is significantly more readable and maintainable as task complexity grows.
  • Library Maturity: The paper reveals a surprising lack of consistency across open-source libraries. For instance, some libraries (like py_trees) only implement the memory-version of a Sequence node, which fundamentally changes how the robot reacts to its environment.

Key Results

The paper provides a valuable comparison of six popular open-source BT libraries (BehaviorTree.CPP, py_trees, CoSTAR, etc.) based on features like reactiveness, argument passing, and asynchronous support.

BehaviorTree.CPP is identified as the most feature-complete for robotics, supporting both classical and memory nodes, explicit port-based data flow, and asynchronous execution via coroutines.

The authors also demonstrate a successful "Fetch and Deliver" use case on the R1 humanoid robot. By using a layered architecture, they show how a complex behavior can be broken down into reusable "Skills" (implemented as State Charts or RFModules) orchestrated by a high-level BT.

Limitations and Future Work

  • The Blocking Halt: The authors note that the "blocking" nature of the Halt() function is still a point of contention. If a Halt() takes too long, it can delay the entire BT's execution.
  • Formal Verification: While BTs are easier to read than FSMs, formally proving that a robot will always behave safely in a BT remains a complex challenge that the authors suggest is a key area for future research.
  • Tooling: Compared to FSMs, the software tools for debugging and visually designing BTs in a robotics context are still relatively immature.

Summary updated

Abstract

There is a growing interest in Behavior Trees (BTs) as a tool to describe and implement robot behaviors. BTs were devised in the video game industry and their adoption in robotics resulted in the development of ad-hoc libraries to design and execute BTs that fit complex robotics software architectures. While there is broad consensus on how BTs work, some characteristics rely on the implementation choices done in the specific software library used. In this letter, we outline practical aspects in the adoption of BTs and the solutions devised by the robotics community to fully exploit the advantages of BTs in real robots. We also overview the solutions proposed in open-source libraries used in robotics, we show how BTs fit in a robotic software architecture, and we present a use case example.
BibTeX
@article{colledanchise2021implementation,
  author = {Michele Colledanchise and Lorenzo Natale},
  title = {{On the Implementation of Behavior Trees in Robotics}},
  journal = {IEEE Robotics Autom. Lett.},
  year = {2021},
  url = {https://openreview.net/forum?id=wN7mcsDDSx},
}

Loading related content...

Figure