# IMU Driver # BNO055 IMU driver # by Kai De La Cruz & Kenzie Goldman 2/20/25 import time from pyb import I2C import struct class BNO055: # Fusion mode values IMU_MODE = 0x08 COMPASS_MODE = 0x09 M4G_MODE = 0x0A NDOF_MODE = 0x0C NDOF_FMC_OFF_MODE = 0x0B imu_address = 0x28 config_mode = 0x00 def __init__(self, i2c, address=imu_address, mode=config_mode): self.i2c = i2c self.address = address def set_mode(self, mode): """Sets the operation mode of the BNO055.""" self.i2c.mem_write(mode, self.address, 0x3D) time.sleep(0.02) # Delay to ensure the mode change is processed def get_calibration_status(self): """A method to retrieve the calibration status byte from the BNO055. Ref page 47 of the datasheet for address.""" data = self.i2c.mem_read(1, self.address, 0x35) return data[0] def get_calibration_coefficients(self): """A method to retrieve the calibration coefficients from the BNO055. Ref page 47 of the datasheet for address.""" data = self.i2c.mem_read(22, self.address, 0x55) calibration_data = list(data) print(f"Calibration data: {calibration_data}") return calibration_data def get_euler_angles(self): """A method to retrieve the Euler angles from the BNO055. Ref in-class notes for the register addresses.""" buf = bytearray(6) data = self.i2c.mem_read(6, self.address, 0x1A) heading, roll, pitch = struct.unpack('\