← Back to Main Portfolio

task_imu.py

Purpose

This file implements the IMU task. It reads heading and yaw rate from the BNO055, unwraps the heading so it remains continuous across angle rollover, filters the yaw rate, and supports IMU calibration load/save behavior.

Main Role

The task provides clean orientation information to the rest of the robot, especially the observer and the serial diagnostics.

Key Responsibilities

Important Attributes / Shares / Variables

NameDescription
imuBNO055 driver object.
psiOutput Share for measured heading.
psiDotOutput Share for measured yaw rate.
imuCalReqShare used to request calibration actions.
_unwrapEnables continuous-angle heading unwrapping.
_calib_fileFilename used to store calibration coefficients.
_yaw_limMaximum allowed yaw-rate magnitude.
_yaw_spike_dpsSpike threshold in degrees per second.
_psi_prev, _psi_contInternal variables used to maintain continuous heading.
_r_filtFiltered yaw-rate state.

Important Methods / Behavior

Method / LogicDescription
Heading unwrapMaintains continuous heading rather than a wrapped 0–360 degree signal.
Calibration loadAttempts to load stored coefficients from file at startup or on request.
Calibration saveSaves updated coefficients when calibration is complete.
Spike rejectionRejects unrealistic gyro spikes before publishing values.
Click to view engineering notes

Heading unwrapping is especially important for control and estimation. If the robot turns through 359 degrees to 0 degrees, a raw wrapped signal would jump abruptly. This file prevents that issue by maintaining a continuous heading state.

Why This File Matters

This file turns raw IMU data into something usable by the observer and by the debugging interface. Without it, heading and yaw-rate information would be less reliable and more difficult to interpret.

Open raw task_imu.py file