libstp.step.logic.loop¶
Classes¶
Base async action executed by missions and higher-level step combinators. |
|
Base async action executed by missions and higher-level step combinators. |
Functions¶
|
Repeat a step indefinitely until externally cancelled. |
|
Repeat a step a fixed number of times. |
Module Contents¶
- class libstp.step.logic.loop.LoopForeverStep(step: libstp.step.StepProtocol)¶
Bases:
libstp.step.StepBase async action executed by missions and higher-level step combinators.
- step¶
- class libstp.step.logic.loop.LoopForStep(step: libstp.step.StepProtocol, iterations: int)¶
Bases:
libstp.step.StepBase async action executed by missions and higher-level step combinators.
- step¶
- iterations¶
- libstp.step.logic.loop.loop_forever(step: libstp.step.StepProtocol) LoopForeverStep¶
Repeat a step indefinitely until externally cancelled.
Wraps the given step in an infinite loop. Each iteration awaits the child step to completion before starting the next. The loop only terminates when the enclosing context cancels it (e.g. via
do_while_activeordo_until_checkpoint).- Parameters:
step – The step to execute repeatedly. Must satisfy
StepProtocol.- Returns:
A step that runs
stepin an infinite loop.- Return type:
Example:
from libstp.step.logic import loop_forever from libstp.step.motor import set_motor_speed # Continuously toggle a motor on and off (until parent cancels) toggle = seq([ set_motor_speed(0, 1000), wait(0.5), set_motor_speed(0, 0), wait(0.5), ]) do_until_checkpoint(30.0, loop_forever(toggle))
- libstp.step.logic.loop.loop_for(step: libstp.step.StepProtocol, iterations: int) LoopForStep¶
Repeat a step a fixed number of times.
Wraps the given step in a counted loop. Each iteration awaits the child step to completion before starting the next. After all iterations complete, the step finishes normally.
- Parameters:
step – The step to execute repeatedly. Must satisfy
StepProtocol.iterations – Number of times to run the step. Must be a positive integer.
- Returns:
A step that runs
stepexactlyiterationstimes.- Return type:
Example:
from libstp.step.logic import loop_for from libstp.step.motor import set_motor_speed # Drive forward in three short bursts burst = seq([ set_motor_speed(0, 800), wait(0.3), set_motor_speed(0, 0), wait(0.2), ]) loop_for(burst, 3)