Skip to main content

Loop node

Loop node representation

The loop node has one child which will be repeated until either the condition, if given, returns False, or the number of repeats exceeds the max_count variable (if set). When the root loop node gets selected, it will immediately transition to Running (after checking the decorators). While in Running, it will select the child node. Once the child succeeds the sequence repeats until the stopping conditions are met. If the child fails during execution, the whole node will fail.

Properties

PropertyDescription
Child semanticsChild executed once for each loop iteration
Parametersname name of the node
do-child: child to execute (multiple times)
while: optional condition that if present must be satisfied to run another loop iteration
max_times: if zero has no impact on loop, if positive non-zero determines the maximum number of iterations to perform.
Success criterionEach execution of the do child succeeds and the boundary criterion (while is not satisfied or max_times is reached) is hit.
Failure criterionThe do-child failed.

Python API

The node can be constructed by parameterizing it either on creation or by using the builder pattern. For the while-condition, you can choose any condition from available from conditions and decorators .

# Use max_times condition -> for loop
loop_1 = BT.Loop(max_times=4).set_do_child(move_up)

# Use while condition -> pick blocks as long as blocks can be detected
loop_2 = BT.Loop(while_condition=estimate_block, do_child=pick_and_place_block)