task_imu module¶
task_imu.py
Cooperative scheduler task that manages the BNO055 IMU sensor. The task moves through the following states:
- S0_BEGIN: Initialize the IMU and attempt to restore a saved
calibration from flash.
- S1_CALIBRATE: Wait until all subsystems reach full calibration,
then save offsets to flash.
- S2_IDLE: Dispatch mode commands (load/save calibration, tare,
read values, get calibration status, or run NDOF).
- S3_RUN_NDOF: Read heading and heading-rate from the IMU and publish
them to shares, then return to idle.
S4_SAVE_CALIB: Persist current calibration offsets and tare values.
S5_LOAD_CALIB: Restore calibration offsets and tare values from flash.
S6_TARE: Collect accelerometer/gyro tare samples and save them.
S7_READ_VALS: Perform a one-shot read of heading and heading-rate.
- S8_GET_CALIB_STATE: Pack calibration sub-system statuses into a single
byte and publish it to a share.
- class task_imu.task_imu(imuSensor, mode, calibration, heading, headingRate)[source]¶
Bases:
objectScheduler task that initializes, calibrates, and reads the BNO055 IMU. Heading and heading-rate are published to shared variables for use by other tasks (e.g., closed-loop motor control).
- clear_tare()[source]¶
Reset the IMU tare offsets to zero and persist the cleared values to flash.
Returns¶
- bool
True if the updated tare values were saved successfully, False otherwise.
- tare_accel_gyro(sample_count=100, sample_delay_ms=5)[source]¶
Collect tare samples from the accelerometer and gyroscope, then save the resulting tare offsets to flash.
This is a generator method; use
yield from tare_accel_gyro().Parameters¶
- sample_countint, optional
Number of samples to average for the tare (default 100).
- sample_delay_msint, optional
Delay in milliseconds between samples (default 5).
Returns¶
- bool
True if the tare values were saved successfully, False otherwise.