A library of subtree creators that build complex patterns of behaviours representing common behaviour tree idioms.
Common decision making patterns can often be realised using a specific combination of fundamental behaviours and the blackboard. Even if this somewhat verbosely populates the tree, this is preferable to creating new composites types or overriding existing composites since this will increase tree logic complexity and/or bury details under the hood (both of which add an exponential cost to introspection/visualisation).
In this package these patterns will be referred to as PyTree Idioms and in this module you will find convenience functions that assist in creating them.
The subsections below introduce each composite briefly. For a full listing of each composite’s methods, visit the py_trees.idioms module api documentation.
eternal_guard(name='Eternal Guard', conditions=, blackboard_variable_prefix=None)
The eternal guard idiom implements a stronger guard than the typical check at the beginning of a sequence of tasks. Here they guard continuously while the task sequence is being executed. While executing, if any of the guards should update with status
FAILURE, then the task sequence is terminated.
- subtree (
Behaviour) – behaviour(s) that actually do the work
- name (
str) – the name to use on the root behaviour of the idiom subtree
- conditions (
Behaviour]) – behaviours on which tasks are conditional
- blackboard_variable_prefix (
str]) – applied to condition variable results stored on the blackboard (default: derived from the idiom name)
Return type: Returns:
the root of the idiom subtree
- subtree (
oneshot(name='Oneshot', variable_name='oneshot', policy=<OneShotPolicy.ON_SUCCESSFUL_COMPLETION: [<Status.SUCCESS: 'SUCCESS'>]>)
Ensure that a particular pattern is executed through to completion just once. Thereafter it will just rebound with the completion status.
Set the policy to configure the oneshot to keep trying if failing, or to abort further attempts regardless of whether it finished with status
- behaviour (
Behaviour) – single behaviour or composited subtree to oneshot
- name (
str) – the name to use for the oneshot root (selector)
- variable_name (
str) – name for the variable used on the blackboard, may be nested
- policy (
OneShotPolicy) – execute just once regardless of success or failure, or keep trying if failing
the root of the oneshot subtree
- behaviour (
Pickup Where You left Off¶
Rudely interrupted while enjoying a sandwich, a caveman (just because they wore loincloths does not mean they were not civilised), picks up his club and fends off the sabre-tooth tiger invading his sanctum as if he were swatting away a gnat. Task accomplished, he returns to the joys of munching through the layers of his sandwich.
There are alternative ways to accomplish this idiom with their pros and cons.
a) The tasks in the sequence could be replaced by a factory behaviour that dynamically checks the state of play and spins up the tasks required each time the task sequence is first entered and invalidates/deletes them when it is either finished or invalidated. That has the advantage of not requiring much of the blackboard machinery here, but disadvantage in not making visible the task sequence itself at all times (i.e. burying details under the hood).
b) A new composite which retains the index between initialisations can also achieve the same pattern with fewer blackboard shenanigans, but suffers from an increased logical complexity cost for your trees (each new composite increases decision making complexity (O(n!)).
root of the generated subtree