Skip to content

Hardware configuration

Robot.configure() declares which sensors and effectors are connected to the robot. Call it exactly once, before Robot.run().

robot.configure(
    sensors={"S2": IMU, "S3": RadioBeacon},
    effectors={"A1": Thruster, "A5": Servo},
    pid={"A1": (0.8, 0.1, 0.0)},
)

Port declarations

The keys are port names and the values are HELM classes:

Mapping Required prefix Supported types
sensors S IMU, RadioBeacon
effectors A Thruster, Servo

The current Python validation checks the prefix, not a fixed numeric port list. For example, "S2" and "A1" have the expected form. The robot still verifies the complete declaration and can reject unsupported physical ports or hardware.

Pass the classes themselves, not instances:

# Correct
sensors={"S2": IMU}

# Incorrect
sensors={"S2": IMU("S2")}

PID gains

The optional pid mapping supplies (kp, ki, kd) current-loop gains for thrusters:

pid={"A1": (0.8, 0.1, 0.0)}

Each PID entry must:

  • refer to an effector declared in the same call;
  • refer to a Thruster, not a Servo;
  • contain exactly three numeric values.

Configuration verification

During configuration, the library:

  1. validates the local declarations;
  2. opens its local connection to the HELM extension;
  3. sends the configuration to the robot through the extension;
  4. waits for the parsed configuration to be echoed back;
  5. raises an error if the echo does not match.

This fail-loud behavior prevents a program from arming with a different hardware layout than the one the student declared.

Accessing configured hardware

Explicit accessors work for every configured object:

imu = robot.sensor("S2")
left_thruster = robot.thruster("A1")
arm_servo = robot.servo("A5")

robot.effector(port) returns either effector type. The typed accessors raise TypeError if the port contains the wrong kind.

Sensor shortcuts

When exactly one sensor of a given type is configured, the robot adds a lowercase shortcut:

robot.imu
robot.radiobeacon

If two sensors have the same type, that shortcut is not created because it would be ambiguous:

robot.configure(
    sensors={"S1": IMU, "S2": IMU},
    effectors={},
)

front_imu = robot.sensor("S1")
rear_imu = robot.sensor("S2")

Prefer robot.sensor(port) in reusable code and whenever multiple sensors of one type may be installed.