step.logic.defer

Classes

Defer

Defer step construction until execution time.

Run

Execute an arbitrary callable as a step.

Module Contents

class step.logic.defer.Defer(factory: Callable[[raccoon.robot.api.GenericRobot], step.Step])

Bases: step.Step

Defer step construction until execution time.

Wraps a factory callable that receives the robot instance and returns a step. The factory is called when the Defer step executes, not when the step tree is built. This allows steps to depend on runtime values such as sensor readings, odometry data, or results computed by earlier steps in a sequence.

Parameters:

factory – A callable that takes a GenericRobot and returns a Step to execute. Called exactly once when the deferred step runs.

Example:

from raccoon.step.logic import defer

# Turn by an angle computed from a sensor reading at runtime
seq([
    scan_step,
    defer(lambda robot: turn_left(
        compute_angle_from_scan(robot)
    )),
])
factory
class step.logic.defer.Run(action: Callable[[raccoon.robot.api.GenericRobot], None | Awaitable[None]])

Bases: step.Step

Execute an arbitrary callable as a step.

Wraps a sync or async callable so it can be used inline in a step sequence. This is useful for one-off side effects, logging, variable assignments, or any imperative code that does not warrant its own step class. The callable receives the robot instance and its return value is ignored (unless it returns an awaitable, which is then awaited).

Parameters:

action – A callable that takes a GenericRobot and optionally returns an awaitable. Sync and async callables are both supported.

Example:

from raccoon.step.logic import run

# Log the current heading between two drive steps
seq([
    drive_forward(25),
    run(lambda robot: print(f"Heading: {robot.odometry.get_heading()}")),
    drive_forward(25),
])
action