Crates.io | bonsai-bt |
lib.rs | bonsai-bt |
version | 0.6.3 |
source | src |
created_at | 2022-07-12 16:20:22.596962 |
updated_at | 2024-02-07 21:17:01.185135 |
description | Behavior tree |
homepage | https://github.com/sollimann/bonsai |
repository | https://github.com/sollimann/bonsai.git |
max_upload_size | |
id | 624496 |
size | 89,145 |
Rust implementation of Behavior Trees
Bonsai is available on crates.io. The recommended way to use it is to add a line into your Cargo.toml such as:
[dependencies]
bonsai-bt = "*"
A Behavior Tree (BT) is a data structure in which we can set the rules of how certain behavior's can occur, and the order in which they would execute. BTs are a very efficient way of creating complex systems that are both modular and reactive. These properties are crucial in many applications, which has led to the spread of BT from computer game programming to many branches of AI and Robotics.
A Behavior Tree forms a tree structure where each node represents a process. When the process terminates, it signals Success
or Failure
. This can then be used by the parent node to select the next process. A signal Running
is used to tell the process is not done yet.
For example, if you have a state A
and a state B
:
A
to state B
if A
succeeds: Sequence([A, B])
A
to sequence of states [B]
if A
is running. If all states in the sequence [B]
succeed in order, check if A
is still running and repeat. Stop if A
succeeds or any of the states fail: RepeatSequence(A, [B])
A
first and then try B
if A
fails: Select([A, B])
condition
succeedes do A
, else do B
: If(condition, A, B)
A
succeeds, return failure (and vice-versa): Invert(A)
B
repeatedly while A
runs: While(A, [B])
A
, B
forever: While(WaitForever, [A, B])
A
and B
in parallell and wait for both to succeed: WhenAll([A, B])
A
and B
in parallell and wait for any to succeed: WhenAny([A, B])
A
and B
in parallell, but A
has to succeed before B
: After([A, B])
See the Behavior
enum for more information.
To make sure that the behavior tree is always responsive, it is important that the actions that are created executes instantly so that they do not block the tree traversal. If you have long-running tasks/functions that can take seconds or minutes to execute - either async
or sync
- then we can dispatch those jobs into background threads, and get status of the task through a channel.
see async drone example in the /examples
folder for more details.
See Examples folder.
Bonsai is inspired by many other crates out there, here's a few worth mentioning: