step.logic.if_then_dsl

Auto-generated step builders and DSL functions — DO NOT EDIT.

Source: if_then.py

Classes

IfThenBuilder

Builder for IfThen. Auto-generated — do not edit.

Functions

if_then([condition, then_step, else_step])

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.StepBuilder

Builder for IfThen. Auto-generated — do not edit.

condition(value: Callable[[GenericRobot], bool])
then_step(value: step.StepProtocol)
else_step(value: step.StepProtocol | None)
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 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.

Parameters:
  • condition – A callable taking a GenericRobot and returning a boolean. Called exactly once when the step runs.

  • then_step – The step to execute when condition returns True.

  • else_step – Optional step to execute when condition returns 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),
)