step.motion.drive_to_analog_target¶
Drive until an analog sensor reaches its calibrated reference value.
Loads the target raw value stored by calibrate_analog_sensor() and drives
the robot forward or backward until the sensor reading crosses that threshold.
Direction is determined automatically at start time by comparing the current
reading to the calibrated target.
Classes¶
Drive until an analog sensor reaches its calibrated reference value. |
Module Contents¶
- class step.motion.drive_to_analog_target.DriveToAnalogTarget(sensor: raccoon.hal.AnalogSensor, speed: float = 0.3, set_name: str = 'default', timeout_cm: float | None = None)¶
Bases:
step.motion.motion_step.MotionStepDrive until an analog sensor reaches its calibrated reference value.
Reads the reference raw value stored by
calibrate_analog_sensor()for the given sensor and set name, then drives forward or backward at the specified speed untilsensor.read()crosses that threshold. Direction is chosen automatically: if the current reading is below the target the robot drives forward (toward the target); if it is already above the target the robot drives backward.A
timeout_cmcan be provided as a safety backstop — the step stops after that distance even if the sensor has not reached the target.- Prerequisites:
calibrate_analog_sensor(sensor, set_name=...)must have been run (or a stored calibration must exist) before this step executes. RaisesRuntimeErrorif no calibration data is found.
- Parameters:
sensor – The analog sensor used to detect the target position.
speed – Drive speed as a fraction of maximum (0.0–1.0, default 0.3). Use a slow speed for precise positioning.
set_name – Which stored calibration point to target (default
"default").timeout_cm – Maximum distance to drive in centimetres before giving up.
Nonedisables the distance limit (default).
- Returns:
A DriveToAnalogTarget instance.
- Raises:
RuntimeError – If no calibration data exists for the given sensor and set name.
Example:
from raccoon.step.motion import drive_to_analog_target # Drive to the default calibrated ET-sensor position drive_to_analog_target(robot.defs.et_sensor) # Slower approach to a named position with 30 cm safety backstop drive_to_analog_target( robot.defs.et_sensor, speed=0.2, set_name="near", timeout_cm=30, )