intrinsic.solutions.behavior_tree.Loop
![]() View source on GitHub |
BT node of type Loop for behavior_tree_pb2.BehaviorTree.LoopNode.
Inherits From: Node
intrinsic.solutions.behavior_tree.Loop(
max_times: int = 0,
do_child: Optional[Union['Node', actions.ActionBase]] = None,
while_condition: Optional['Condition'] = None,
name: Optional[str] = None,
loop_counter_key: Optional[str] = None,
*,
for_each_value_key: Optional[str] = None,
for_each_protos: Optional[List[Union[protobuf_message.Message, skill_utils.MessageWrapper]]] = None,
for_each_generator_cel_expression: Optional[str] = None
)
The loop node provides the ability to run a subtree repeatedly. It supports different bounding conditions: run until failure, run while a condition holds (while loop), or run a maximum number of times (for loops with break on error).
When selected and a while condition is set, the condition is immediately
evaluated. If it is satisfied, or if no while condition is given, the do
child is executed. If max_times is not given or zero, the parameter is
ignored.
Additionally, if no while condition is added, the loop will run
indefinitely until the child do child fails (taking on the semantics of a
for-loop). If max_times is set, the loop will end after the given number
of iterations, or if the do child fails.
Attributes | |
|---|---|
The child node of this node that is to be run repeatedly. | |
Maximal number of times to execute the child. | |
condition which indicates whether do should be executed. | |
The proto representation of the node. | |
A string label of the node type. | |
The key to access the loop counter on the blackboard, only available while inside the loop. | |
List of pre-defined protos to iterate over. | |
The key to access the current value on the blackboard during for each loops. | |
BlackboardValue that refers to the current iteration value. Only available when for_each_generator_cel_expression was set from a BlackboardValue via set_for_each_generator. | |
CEL expression to generate a list of protos. The loop iterates over the result of this list. | |
Methods
create_from_proto
View source
@classmethodcreate_from_proto( proto_object: behavior_tree_pb2.BehaviorTree.Node ) -> 'Node'
Instantiates a Node instance from a proto.
disable_execution
View source
disable_execution(
result_state: Optional[intrinsic.solutions.behavior_tree.DisabledResultState] = None
) -> 'Node'
Disables a node, so that it is not executed and appears to be skipped.
| Args | |
|---|---|
| Optionally force the result of the execution to this state. If not set, the resulting state is automatically determined, so that the node is skipped. |
| Returns | |
|---|---|
Builder pattern, returns self. |
dot_graph
View source
dot_graph(
node_id_suffix: str = ''
) -> Tuple[graphviz.Digraph, str]
Generates a graphviz subgraph with a single node for self.
| Args | |
|---|---|
| A little string of form |
| The label is typically just the type of the node. To use a different value, this argument can be used. |
| name of the node as set by the user. |
| Returns | |
|---|---|
A tuple of the generated graphviz dot graph and the name of the graph's root node. |
enable_execution
View source
enable_execution() -> 'Node'
Enables a node, so that it will be executed.
| Returns | |
|---|---|
Builder pattern, returns self. |
generate_and_set_unique_id
View source
generate_and_set_unique_id() -> int
Generates a new random id and sets it for this node.
set_breakpoint
View source
set_breakpoint(
breakpoint_type: Optional['BreakpointType']
) -> 'Node'
Sets the breakpoint type on the decorator.
| Args | |
|---|---|
| desired breakpoint type, None to remove type. |
| Returns | |
|---|---|
Builder pattern, returns self. |
set_decorators
View source
set_decorators(
decorators: Optional['Decorators']
) -> 'Node'
set_do_child
View source
set_do_child(
do_child: Union['Node', actions.ActionBase]
) -> 'Loop'
set_for_each_generator
View source
set_for_each_generator(
generator_value: blackboard_value.BlackboardValue
) -> 'Loop'
Sets the value to generate protos from to loop over in a for each loop.
The passed in value must refer to a list of protos to iterate over in this for each loop. A common example is a repeated field in a skill result. When the loop node is selected for execution the list of protos is copied from the referred value and then the loop node is cycled for each of the values in the list. The value can also result in an AnyList proto, in which case the loop node iterates over each entry in the AnyList items field. Setting it anything other than 'None', will make this loop node work as a for each loop.
| Args | |
|---|---|
| The value to iterate over. |
| Returns | |
|---|---|
The modified loop node. |
set_for_each_generator_cel_expression
View source
set_for_each_generator_cel_expression(
cel_expression: Optional[str]
) -> 'Loop'
Sets the CEL expression to generate protos for a for each loop.
When this loop node is selected for execution this CEL expression will be evaluated and it must either result in a list of protos to iterate over or an AnyList proto. Setting it anything other than 'None', will make this loop node work as a for each loop.
| Args | |
|---|---|
| The expression to generate protos to loop over. |
| Returns | |
|---|---|
The modified loop node. |
set_for_each_protos
View source
set_for_each_protos(
protos: Optional[List[Union[protobuf_message.Message, skill_utils.MessageWrapper,
object_world_resources.WorldObject, object_world_resources.Frame]]]
) -> 'Loop'
Sets the messages to iterate over in a for each loop.
The proto messages are packed into Any protos when the loop node is represented as a proto unless they are already an Any proto, in which case they are taken as is. Setting this make the loop node work as a for each loop.
| Args | |
|---|---|
| A list of protos to iterate over. If the list contains WorldObjects or Frames these are converted to a proto referencing the WorldObject or Frame. |
| Returns | |
|---|---|
The modified loop node. |
set_for_each_value_key
View source
set_for_each_value_key(
key: Optional[str]
) -> 'Loop'
Sets the blackboard key for the current value of a for each loop.
Setting it anything other than 'None', will make this loop node work as a for each loop.
| Args | |
|---|---|
| The blackboard key to set. Use 'None' to unset this property. |
| Returns | |
|---|---|
The modified loop node. |
set_while_condition
View source
set_while_condition(
while_condition: 'Condition'
) -> 'Loop'
Sets the while condition for the loop.
Setting it will make this loop node work as a while loop.
| Args | |
|---|---|
| The condition to set. |
| Returns | |
|---|---|
The modified loop node. |
show
View source
show() -> None
validate
View source
validate()
Validates the current loop node.
Checks that the loop node is properly defined, i.e., there are no inconsistent properties set and all required fields are set.
| Raises | |
|---|---|
| raised if the node is in a state that cannot be converted to a valid proto. |
visit
View source
visit(
containing_tree: 'BehaviorTree',
callback: Callable[['BehaviorTree', Union['BehaviorTree', 'Node', 'Condition']], None]
) -> None