BlackboardsΒΆ
Blackboards are not a necessary component, but are a fairly standard feature in most behaviour tree implementations. See, for example, the design notes for blackboards in Unreal Engine.
Implementations however, tend to vary quite a bit depending on the needs of the framework using them. Some of the usual considerations include scope and sharing of blackboards across multiple tree instances.
For this package, we’ve decided to keep blackboards extremely simple to fit with the same ‘rapid development for small scale systems’ principles that this library is designed for.
- No sharing between tree instances
- No locking for reading/writing
- Global scope, i.e. any behaviour can access any variable
- No external communications (e.g. to a database)
-
class
py_trees.blackboard.
Blackboard
[source] Borg style key-value store for sharing amongst behaviours.
Examples
You can instantiate the blackboard from anywhere in your program. Even disconnected calls will get access to the same data store. For example:
def check_foo(): blackboard = Blackboard() assert(blackboard.foo, "bar") if __name__ == '__main__': blackboard = Blackboard() blackboard.foo = "bar" check_foo()
If the key value you are interested in is only known at runtime, then you can set/get from the blackboard without the convenient variable style access:
blackboard = Blackboard() result = blackboard.set("foo", "bar") foo = blackboard.get("foo")
The blackboard can also be converted and printed (with highlighting) as a string. This is useful for logging and debugging.
print(Blackboard())
Warning
Be careful of key collisions. This implementation leaves this management up to the user.
See also
The py-trees-demo-blackboard program demos use of the blackboard along with a couple of the blackboard behaviours.