Calibrating and getting readings
When you start up code using an IMU module with a controller, the sensors will not get correct readings. So, the IMU module will need to determine the sensitivity and correct states of the sensor, a process known as calibration. First, we need some code; then, we’ll need to take the robot through some motions to perform this.
Calibration code
Let’s start with the code. In a file called imu_calibration/code.py
, add the following:
import adafruit_bno055 import board import busio import time i2c = busio.I2C(sda=board.GP0, scl=board.GP1) sensor = adafruit_bno055.BNO055_I2C(i2c)
This code handles importing the module and setting it up. We also import time
so that we can use it in loops later.
Next, we must check the calibration state of the module:
def check_status(): sys_status, gyro, accel, mag = imu.calibration_status print(f"Sys: {sys_status}, Gyro: {gyro}, Accel: {accel}, Mag: {mag}"...