libstp.step.logic.loop

Classes

LoopForeverStep

Base async action executed by missions and higher-level step combinators.

LoopForStep

Base async action executed by missions and higher-level step combinators.

Functions

loop_forever(→ LoopForeverStep)

Repeat a step indefinitely until externally cancelled.

loop_for(→ LoopForStep)

Repeat a step a fixed number of times.

Module Contents

class libstp.step.logic.loop.LoopForeverStep(step: libstp.step.StepProtocol)

Bases: libstp.step.Step

Base 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.Step

Base 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_active or do_until_checkpoint).

Parameters:

step – The step to execute repeatedly. Must satisfy StepProtocol.

Returns:

A step that runs step in an infinite loop.

Return type:

LoopForeverStep

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 step exactly iterations times.

Return type:

LoopForStep

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)