step.logic.if_then_dsl¶
Auto-generated step builders and DSL functions — DO NOT EDIT.
Source: if_then.py
Classes¶
Builder for IfThen. Auto-generated — do not edit. |
Functions¶
|
Conditionally run one of two steps based on a runtime predicate. |
Module Contents¶
- class step.logic.if_then_dsl.IfThenBuilder¶
Bases:
raccoon.step.step_builder.StepBuilderBuilder for IfThen. Auto-generated — do not edit.
- condition(value: Callable[[GenericRobot], bool])¶
- then_step(value: step.StepProtocol)¶
- step.logic.if_then_dsl.if_then(condition: Callable[[GenericRobot], bool] = _UNSET, then_step: step.StepProtocol = _UNSET, else_step: step.StepProtocol | None = None)¶
Conditionally 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.
- Returns:
A IfThenBuilder (chainable via
.condition(),.then_step(),.else_step(),.on_anomaly(),.skip_timing()).
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), )