step.logic.if_then¶
Classes¶
Conditionally run one of two steps based on a runtime predicate. |
Module Contents¶
- class step.logic.if_then.IfThen(condition: Callable[[raccoon.robot.api.GenericRobot], bool], then_step: step.StepProtocol, else_step: step.StepProtocol | None = None)¶
Bases:
step.StepConditionally run one of two steps based on a runtime predicate.
Evaluates
conditiononce when the step executes and runsthen_stepif it returns truthy, otherwise runselse_step(or nothing, ifelse_stepis 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.
- Parameters:
condition – A callable taking a
GenericRobotand returning a boolean. Called exactly once when the step runs.then_step – The step to execute when
conditionreturns True.else_step – Optional step to execute when
conditionreturns 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), )
- condition¶
- then_step¶
- else_step¶
- collected_resources() frozenset[str]¶
Return all resources this step and its children require.
Used by
validate_no_overlapfor static conflict detection at construction time. Leaf steps don’t need to override this — the default delegates torequired_resources. Composite steps override to union their children’s collected resources.