step.logic.if_then ================== .. py:module:: step.logic.if_then Classes ------- .. autoapisummary:: step.logic.if_then.IfThen Module Contents --------------- .. py:class:: IfThen(condition: Callable[[raccoon.robot.api.GenericRobot], bool], then_step: step.StepProtocol, else_step: Optional[step.StepProtocol] = None) Bases: :py:obj:`step.Step` Conditionally run one of two steps based on a runtime predicate. Evaluates ``condition`` once when the step executes and runs ``then_step`` if it returns truthy, otherwise runs ``else_step`` (or nothing, if ``else_step`` is not provided). The branch decision is made at runtime, so the predicate can read sensors, odometry, or any state computed by earlier steps in the sequence. Resource usage is reported as the union of both branches because either may execute. The condition itself is not allowed to launch long-running work — it should return a boolean quickly. :param condition: A callable taking a ``GenericRobot`` and returning a boolean. Called exactly once when the step runs. :param then_step: The step to execute when ``condition`` returns True. :param else_step: Optional step to execute when ``condition`` returns False. If omitted, the step does nothing on the false branch. Example:: from raccoon.step.logic import if_then # Pick a branch based on a sensor reading at runtime if_then( lambda robot: robot.front_ir.read() > 500, drive_backward(20), drive_forward(20), ) .. py:attribute:: condition .. py:attribute:: then_step .. py:attribute:: else_step .. py:method:: collected_resources() -> frozenset[str] Return all resources this step *and its children* require. Used by ``validate_no_overlap`` for static conflict detection at construction time. Leaf steps don't need to override this — the default delegates to ``required_resources``. Composite steps override to union their children's collected resources.