Skip to main content

intrinsic.solutions.behavior_tree.Loop

BT node of type Loop for behavior_tree_pb2.BehaviorTree.LoopNode.

Inherits From: Node

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.

do_child

The child node of this node that is to be run repeatedly.

max_times

Maximal number of times to execute the child.

while_condition

condition which indicates whether do should be executed.

proto

The proto representation of the node.

node_type

A string label of the node type.

loop_counter

The key to access the loop counter on the blackboard, only available while inside the loop.

for_each_protos

List of pre-defined protos to iterate over.

for_each_value_key

The key to access the current value on the blackboard during for each loops.

for_each_value

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.

for_each_generator_cel_expression

CEL expression to generate a list of protos. The loop iterates over the result of this list.

breakpoint

decorators

execution_mode

name

node_id

Methods

create_from_proto

View source

Instantiates a Node instance from a proto.

disable_execution

View source

Disables a node, so that it is not executed and appears to be skipped.

Args

result_state

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

Generates a graphviz subgraph with a single node for self.

Args

node_id_suffix

A little string of form _1_2, which is just a suffix to make a unique node name in the graph. If the node names clash within the graph, they are merged into one, and we do not want to merge unrelated nodes.

node_label

The label is typically just the type of the node. To use a different value, this argument can be used.

name

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

Enables a node, so that it will be executed.

Returns

Builder pattern, returns self.

generate_and_set_unique_id

View source

Generates a new random id and sets it for this node.

set_breakpoint

View source

Sets the breakpoint type on the decorator.

Args

breakpoint_type

desired breakpoint type, None to remove type.

Returns

Builder pattern, returns self.

set_decorators

View source

set_do_child

View source

set_for_each_generator

View source

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

generator_value

The value to iterate over.

Returns

The modified loop node.

set_for_each_generator_cel_expression

View source

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

cel_expression

The expression to generate protos to loop over.

Returns

The modified loop node.

set_for_each_protos

View source

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

protos

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

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

key

The blackboard key to set. Use 'None' to unset this property.

Returns

The modified loop node.

set_while_condition

View source

Sets the while condition for the loop.

Setting it will make this loop node work as a while loop.

Args

while_condition

The condition to set.

Returns

The modified loop node.

show

View source

validate

View source

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

InvalidArgumentError

raised if the node is in a state that cannot be converted to a valid proto.

visit

View source