Skip to content

Commit

Permalink
read linear_acc, gravity_acc, quaternion, gyro, temperature from BNO055
Browse files Browse the repository at this point in the history
  • Loading branch information
corruptbear committed Nov 14, 2023
1 parent 6d15d1f commit 761df65
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 43,170 deletions.
11 changes: 11 additions & 0 deletions software/firmware/src/peripherals/include/imu.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ typedef enum {
ACC_INT_SET = 0x12,
ACC_NM_THRE = 0x15,
ACC_NM_SET = 0x16

//configs
BNO055_MAG_CONFIG_ADDR = 0X09,
BNO055_GYRO_CONFIG_ADDR =0X0A,
BNO055_GYRO_MODE_CONFIG_ADDR = 0X0B,

} bno055_reg_t;

typedef enum {
Expand Down Expand Up @@ -194,5 +200,10 @@ void imu_init(void);
void imu_deinit(void);
void imu_register_motion_change_callback(motion_change_callback_t callback, bno055_opmode_t mode);
void imu_read_accel_data(int16_t *x, int16_t *y, int16_t *z);
void imu_read_linear_accel_data(int16_t *x, int16_t *y, int16_t *z);
void imu_read_gravity_accel_data(int16_t *x, int16_t *y, int16_t *z);
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);

#endif // #ifndef __IMU_HEADER_H__
40 changes: 39 additions & 1 deletion software/firmware/src/peripherals/src/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ static void enable_motion_interrupts(void)
i2c_write8(BNO055_PAGE_ID_ADDR, 0);
}


// Public API Functions ------------------------------------------------------------------------------------------------

void imu_init(void)
Expand Down Expand Up @@ -230,4 +229,43 @@ void imu_read_accel_data(int16_t *x, int16_t *y, int16_t *z)
*x = (int16_t)(accel_data[0] << 2) / 4;
*y = (int16_t)(accel_data[1] << 2) / 4;
*z = (int16_t)(accel_data[2] << 2) / 4;
}

void imu_read_linear_accel_data(int16_t *x, int16_t *y, int16_t *z){
static int16_t accel_data[3];
i2c_read(BNO055_LINEAR_ACCEL_DATA_X_LSB_ADDR, (uint8_t*)accel_data, sizeof(accel_data));
*x = (int16_t)(accel_data[0] << 2) / 4;
*y = (int16_t)(accel_data[1] << 2) / 4;
*z = (int16_t)(accel_data[2] << 2) / 4;
}

void imu_read_gravity_accel_data(int16_t *x, int16_t *y, int16_t *z){
static int16_t accel_data[3];
i2c_read(BNO055_GRAVITY_DATA_X_LSB_ADDR, (uint8_t*)accel_data, sizeof(accel_data));
*x = (int16_t)(accel_data[0] << 2) / 4;
*y = (int16_t)(accel_data[1] << 2) / 4;
*z = (int16_t)(accel_data[2] << 2) / 4;
}

void imu_read_quaternion_data(int16_t *w, int16_t *x, int16_t *y, int16_t *z){
static int16_t quaternion_data[4];
i2c_read(BNO055_QUATERNION_DATA_W_LSB_ADDR, (uint8_t*)quaternion_data, sizeof(quaternion_data));
*w = (int16_t)(quaternion_data[0] << 2) / 4;
*x = (int16_t)(quaternion_data[1] << 2) / 4;
*y = (int16_t)(quaternion_data[2] << 2) / 4;
*z = (int16_t)(quaternion_data[3] << 2) / 4;
}

void imu_read_gyro_data(int16_t *x, int16_t *y, int16_t *z){
static int16_t gyro_data[3];
i2c_read(BNO055_GYRO_DATA_X_LSB_ADDR, (uint8_t*)gyro_data, sizeof(gyro_data));
*x = (int16_t)(gyro_data[0] << 2) / 4;
*y = (int16_t)(gyro_data[1] << 2) / 4;
*z = (int16_t)(gyro_data[2] << 2) / 4;
}

void imu_read_temp(int8_t *temp){
static int8_t temp_data;
i2c_read(BNO055_TEMP_ADDR, (uint8_t*)&temp_data, 1);
*temp = (int8_t)temp_data;
}
Binary file removed software/firmware/tests/bin/TestIMU.axf
Binary file not shown.
Binary file removed software/firmware/tests/bin/TestIMU.bin
Binary file not shown.
Loading

0 comments on commit 761df65

Please sign in to comment.