[AIDriver] Simulator ready [AIDriver] Select a challenge to begin
Import once at the top of every challenge:
from aidriver import AIDriver, hold_state
from config_check import validate_config
import aidriver
import config
# Inside main(), before movement:
validate_config(config, AIDriver.MIN_MOTOR_SPEED)
aidriver.DEBUG_AIDRIVER = config.DEBUG_AIDRIVER
my_robot = AIDriver(
config.WALL_SIDE,
distance_sensor=config.DISTANCE_SENSOR,
min_approach_speed=config.MIN_APPROACH_SPEED,
kit_servo_pin=config.KIT_SERVO_PIN,
)
my_robot.read_distance()
Front ultrasonic. Returns mm (20–2000) or -1 if out
of range / no echo.
my_robot.read_distance_2()
Side ultrasonic (the wall-follow sensor). Same units, same
-1 sentinel — used to detect outside corners.
my_robot.drive(right_speed, left_speed)
Preferred for PID. Signed speeds (-255…255):
positive = forward, negative = backward. Anything with
abs(speed) < 120 stops that wheel (MIN_MOTOR_SPEED
dead zone).
my_robot.drive_forward(right_speed, left_speed)
Both wheels forward at unsigned speeds (0–255).
my_robot.drive_backward(right_speed, left_speed)
Both wheels backward at unsigned speeds (0–255).
my_robot.rotate_left(turn_speed)
Spin in place counter-clockwise at
turn_speed.
my_robot.rotate_right(turn_speed)
Spin in place clockwise at turn_speed.
my_robot.brake()
Cut power to both motors.
my_robot.wall_sign
Property: -1 when constructed with
"left", +1 for "right".
Multiply your steering term by it so the same code mirror-solves
both modes.
my_robot.get_motor_speeds()
Returns the last commanded
(right_speed, left_speed) tuple.
my_robot.is_moving()
Returns True if either wheel is currently
powered.
hold_state(seconds)
Pause for seconds while retaining the current motor
outputs. Use config.LOOP_DT for the normal control
loop.
config.DEBUG_AIDRIVER = True / False
Toggle verbose [AIDriver] log output. Off by default
in answers; turn it on while debugging your own code.
MIN_MOTOR_SPEED = 120 — library-owned motor floor.
steer() limits correction to keep the slower wheel at
or above that floor.
read_distance() and
read_distance_2() return -1.
Having issues? Download a debug log to share with your teacher or for troubleshooting.