Behavior Tree Base
The Vultron behavior tree base module defines the basic building blocks of any behavior tree. This page covers the basic Tree and Blackboard classes, as well as the basic error classes. Detailed descriptions of Node types are provided in Behavior Tree Basic Node Types.
vultron.bt.base
This package implements a basic Behavior Tree library.
vultron.bt.base.bt
This module defines a Behavior Tree object.
BehaviorTree
BehaviorTree is the base class for all bt trees. It is responsible for setting up the tree and running the root node.
Attributes:
| Name | Type | Description |
|---|---|---|
root |
BtNode | None
|
the root node of the tree |
bb |
Any
|
the blackboard object |
__enter__()
Runtime context for the BehaviorTree object.
Returns:
| Name | Type | Description |
|---|---|---|
self |
Self
|
the BehaviorTree object |
__exit__(exc_type, exc_val, exc_tb)
Runtime context for the BehaviorTree object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
type[BaseException] | None
|
the exception type |
required |
exc_val
|
BaseException | None
|
the exception value |
required |
exc_tb
|
TracebackType | None
|
the exception traceback |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
Literal[False]
|
True if the exception was handled, False otherwise |
__init__(root=None, bbclass=None)
Initialize the BehaviorTree object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
BtNode | None
|
the root node of the tree |
None
|
bbclass
|
type[Any] | None
|
the blackboard class to use |
None
|
add_root(node)
Adds a root node to the tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
BtNode
|
the root node to add |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
setup()
Recursively calls the setup() method on all nodes in the tree starting at the root.
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises: BehaviorTreeError: if the tree has no root node
tick()
tick() is the main entry point for running the bt tree. It calls the root node's tick() method. Two callbacks are provided for subclasses to override: _pre_tick() and _post_tick().
Returns:
| Name | Type | Description |
|---|---|---|
NodeStatus |
NodeStatus
|
the status of the root node after the tick |
vultron.bt.base.blackboard
This module defines Blackboard class for sharing data between nodes in the tree.
The default Blackboard class is a dict, which is good enough if you just want to run a single tree in a single process.
If you want multiple trees in a single process with shared state, just use the same Blackboard object instance for each tree.
If you want to run multiple trees in a single process without shared state, you'll need to use a different Blackboard object instance for each tree. You can still do that with the default Blackboard class, but you'll need to create a new Blackboard object instance for each tree.
If you want to run multiple trees in multiple processes with shared state,
you'll need to use a Blackboard object that can communicate with some external
data store, such as a key-value store on a server. The default Blackboard
class is not designed for that use case, but you can subclass it to use
any object that implements the __getitem__ and __setitem__ methods
to provide a python dict-like interface.
For example, mongodict and redis-dict provide such an interface for MongoDb and Redis,
respectively.
Blackboard
Bases: dict
Provides a blackboard object for sharing data between nodes in the tree. To use a custom blackboard object, subclass this class and set the BehaviorTree's bbclass attribute to your subclass.
vultron.bt.base.errors
This module defines error classes for the vultron.bt.base module
ActionNodeError
Bases: LeafNodeError
Raised when an action node encounters an error
BehaviorTreeError
Bases: VultronError
Raised when a BehaviorTree encounters an error
BehaviorTreeFuzzerError
Bases: BehaviorTreeError
Raised when a BehaviorTreeFuzzer encounters an error
ConditionCheckError
Bases: LeafNodeError
Raised when a condition check encounters an error
LeafNodeError
Bases: BehaviorTreeError
Raised when a leaf node encounters an error