Sensors and readings¶
Sensor objects are created by Robot.configure(). Their read() methods return
the latest cached sample without blocking.
Sensor¶
Base class for sensor types. It is public for extension and advanced use, but
students normally pass concrete classes to configure() instead of
constructing sensors.
Attributes¶
read¶
Returns a base reading. Concrete sensor subclasses return their typed reading.
Reading¶
Base dataclass shared by every reading.
| Field | Type | Meaning |
|---|---|---|
timestamp |
int |
Brain sample time in milliseconds |
age |
float |
Approximate sample age in milliseconds |
ok |
bool |
Payload is valid and age is at most 250 ms |
IMU¶
Nine-axis inertial measurement unit. Heading is relative to the robot's arming pose, not absolute north.
ImuReading¶
ImuReading(
timestamp: int,
age: float,
ok: bool,
accel_x: float,
accel_y: float,
accel_z: float,
gyro_x: float,
gyro_y: float,
gyro_z: float,
mag_x: int,
mag_y: int,
mag_z: int,
heading: float,
)
| Fields | Unit |
|---|---|
accel_x, accel_y, accel_z |
g |
gyro_x, gyro_y, gyro_z |
degrees per second |
mag_x, mag_y, mag_z |
raw integer values |
heading |
degrees relative to arming |
RadioBeacon¶
Reads distance reported by a radio beacon.
RadioBeaconReading¶
distance_m is the measured distance in meters.
reading = robot.radiobeacon.read()
if reading.ok and reading.distance_m < 1.0:
print("Beacon is nearby")
Missing and stale samples¶
Before a sample arrives, typed readings contain zero-valued sensor fields,
timestamp == 0, age == math.inf, and ok == False.
After a sample becomes older than 250 ms, its values remain available but
ok becomes false. Always check ok before using a reading to command motion.