step.logic.defer ================ .. py:module:: step.logic.defer Classes ------- .. autoapisummary:: step.logic.defer.Defer step.logic.defer.Run Module Contents --------------- .. py:class:: Defer(factory: Callable[[raccoon.robot.api.GenericRobot], step.Step]) Bases: :py:obj:`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. :param 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) )), ]) .. py:attribute:: factory .. py:class:: Run(action: Callable[[raccoon.robot.api.GenericRobot], Union[None, Awaitable[None]]]) Bases: :py:obj:`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). :param 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), ]) .. py:attribute:: action