py_trees.visitors module
Visiting rights to behaviours.
Visitors are entities that can be passed to a tree implementation
(e.g. BehaviourTree
) and used to either visit
each and every behaviour in the tree, or visit behaviours as the tree is
traversed in an executing tick. At each behaviour, the visitor
runs its own method on the behaviour to do as it wishes - logging, introspecting, etc.
Warning
Visitors should not modify the behaviours they visit.
- class py_trees.visitors.DebugVisitor
Bases:
VisitorBase
Picks up and logs feedback messages and the behaviour’s status.
Logging is done with the behaviour’s logger.
- class py_trees.visitors.DisplaySnapshotVisitor(display_only_visited_behaviours: bool = False, display_blackboard: bool = False, display_activity_stream: bool = False)
Bases:
SnapshotVisitor
Visit the tree, capturing the visited path, it’s changes since the last tick.
Additionally print the snapshot to console.
- Args:
display_only_visited_behaviours: useful for cropping the unvisited part of a large tree display_blackboard: print to the console the relevant part of the blackboard associated with
behaviours on the visited path
- display_activity_stream: print to the console a log of the activity on the blackboard
over the last tick
- finalise() None
Print a summary on stdout after all behaviours have been visited.
- initialise() None
Reset and initialise all variables.
- run(behaviour: Behaviour) None
Track the root of the tree and run
SnapshotVisitor
.- Args:
behaviour: behaviour being visited.
- class py_trees.visitors.SnapshotVisitor
Bases:
VisitorBase
Creates a snapshot of the tree state (behaviour status’ only).
Visits the ticked part of a tree, checking off the status against the set of status results recorded in the previous tick. If there has been a change, it flags it. This is useful for determining when to trigger, e.g. logging.
- Attributes:
- changed (Bool): flagged if there is a difference in the visited path or
Status
of any behaviour on the path- visited (dict): dictionary of behaviour id (uuid.UUID) and status
(
Status
) pairs from the current tick- previously_visited (dict): dictionary of behaviour id (uuid.UUID)
and status (
Status
) pairs from the previous tick
running_nodes([uuid.UUID]): list of id’s for behaviours which were traversed in the current tick previously_running_nodes([uuid.UUID]): list of id’s for behaviours which were traversed in the last tick visited_blackboard_ids(typing.Set[uuid.UUID]): blackboard client id’s on the visited path visited_blackboard_keys(typing.Set[str]): blackboard variable keys on the visited path
See also
The py-trees-demo-logging-program program demonstrates use of this visitor to trigger logging of a tree serialisation.
- initialise() None
Store the last snapshot for comparison with the next incoming snapshot.
This should get called before a tree ticks.
- class py_trees.visitors.VisitorBase(full: bool = False)
Bases:
object
Parent template for visitor types.
Visitors are primarily designed to work with
BehaviourTree
but they can be used in the same way for other tree custodian implementations.- Args:
full: flag to indicate whether it should be used to visit only traversed nodes or the entire tree
- Attributes:
full: flag to indicate whether it should be used to visit only traversed nodes or the entire tree
- finalise() None
Override if any work needs to be performed after ticks (i.e. showing data).
- initialise() None
Override if any resetting of variables needs to be performed between ticks (i.e. visitations).