Skip to content

Commit

Permalink
Read calibration status of BNO055
Browse files Browse the repository at this point in the history
  • Loading branch information
corruptbear committed Nov 14, 2023
1 parent 196b3dd commit b76ea67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion software/firmware/src/peripherals/include/imu.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ typedef enum {
POWER_MODE_SUSPEND = 0X02
} bno055_powermode_t;

typedef struct
{
int sys;
int gyro;
int accel;
int mag;
} bno55_calib_status_t;

// Peripheral Type Definitions -----------------------------------------------------------------------------------------

typedef void (*motion_change_callback_t)(bool in_motion);
Expand All @@ -206,5 +214,5 @@ void imu_read_quaternion_data(int16_t *w, int16_t *x, int16_t *y, int16_t *z);
void imu_read_gyro_data(int16_t *x, int16_t *y, int16_t *z);
void imu_read_temp(int8_t *temp);
void imu_read_fw_version(uint8_t *msb, uint8_t *lsb);

void imu_read_calibration_status(bno55_calib_status_t *status);
#endif // #ifndef __IMU_HEADER_H__
9 changes: 9 additions & 0 deletions software/firmware/src/peripherals/src/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,13 @@ void imu_read_temp(int8_t *temp){
void imu_read_fw_version(uint8_t *msb, uint8_t *lsb){
*msb = i2c_read8(BNO055_SW_REV_ID_MSB_ADDR);
*lsb = i2c_read8(BNO055_SW_REV_ID_LSB_ADDR);
}

void imu_read_calibration_status(bno55_calib_status_t *status) {
uint8_t reg_value = i2c_read8(BNO055_CALIB_STAT_ADDR);

status->mag = reg_value & 0x03;
status->accel = (reg_value >> 2) & 0x03;
status->gyro = (reg_value >> 4) & 0x03;
status->sys = (reg_value >> 6) & 0x03;
}
5 changes: 5 additions & 0 deletions software/firmware/tests/peripherals/test_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ int main(void)
int16_t w, x, y, z;
int8_t temp;
uint8_t rev_msb, rev_lsb;
bno55_calib_status_t status;
imu_register_motion_change_callback(motion_interrupt, OPERATION_MODE_NDOF);

imu_read_fw_version(&rev_msb, &rev_lsb);
Expand All @@ -37,6 +38,10 @@ int main(void)
print("gyro 1 = %d, gyro 2 = %d, gyro 3 = %d\n", (int32_t)x, (int32_t)y, (int32_t)z);
imu_read_temp(&temp);
print("temp:%d\n", (int32_t)temp);

//0: not calibrated; 3: fully calibrated
imu_read_calibration_status(&status);
print("Calibration status: sys %u, gyro %u, accel %u, mag %u\n",status.sys, status.gyro, status.accel, status.mag);
}

// Should never reach this point
Expand Down

0 comments on commit b76ea67

Please sign in to comment.