diff --git a/sw/airborne/subsystems/imu/imu_mpu9250_i2c.c b/sw/airborne/subsystems/imu/imu_mpu9250_i2c.c index 9529035a0f..1fd4f52c21 100644 --- a/sw/airborne/subsystems/imu/imu_mpu9250_i2c.c +++ b/sw/airborne/subsystems/imu/imu_mpu9250_i2c.c @@ -61,14 +61,7 @@ PRINT_CONFIG_VAR(IMU_MPU9250_SMPLRT_DIV) PRINT_CONFIG_VAR(IMU_MPU9250_GYRO_LOWPASS_FILTER) PRINT_CONFIG_VAR(IMU_MPU9250_ACCEL_LOWPASS_FILTER) -#ifndef IMU_MPU9250_GYRO_RANGE -#define IMU_MPU9250_GYRO_RANGE MPU9250_GYRO_RANGE_1000 -#endif PRINT_CONFIG_VAR(IMU_MPU9250_GYRO_RANGE) - -#ifndef IMU_MPU9250_ACCEL_RANGE -#define IMU_MPU9250_ACCEL_RANGE MPU9250_ACCEL_RANGE_8G -#endif PRINT_CONFIG_VAR(IMU_MPU9250_ACCEL_RANGE) #ifndef IMU_MPU9250_I2C_ADDR diff --git a/sw/airborne/subsystems/imu/imu_mpu9250_i2c.h b/sw/airborne/subsystems/imu/imu_mpu9250_i2c.h index 4c7ab0567c..c5cb7940dd 100644 --- a/sw/airborne/subsystems/imu/imu_mpu9250_i2c.h +++ b/sw/airborne/subsystems/imu/imu_mpu9250_i2c.h @@ -35,39 +35,38 @@ #include "peripherals/mpu9250_i2c.h" -/** default gyro sensitivy and neutral from the datasheet - * MPU with 1000 deg/s has 32.8 LSB/(deg/s) - * sens = 1/32.8 * pi/180 * 2^INT32_RATE_FRAC - * sens = 1/32.8 * pi/180 * 4096 = 2.17953 - I*/ -#if !defined IMU_GYRO_P_SENS & !defined IMU_GYRO_Q_SENS & !defined IMU_GYRO_R_SENS -// FIXME -#define IMU_GYRO_P_SENS 2.17953 -#define IMU_GYRO_P_SENS_NUM 18271 -#define IMU_GYRO_P_SENS_DEN 8383 -#define IMU_GYRO_Q_SENS 2.17953 -#define IMU_GYRO_Q_SENS_NUM 18271 -#define IMU_GYRO_Q_SENS_DEN 8383 -#define IMU_GYRO_R_SENS 2.17953 -#define IMU_GYRO_R_SENS_NUM 18271 -#define IMU_GYRO_R_SENS_DEN 8383 +#ifndef IMU_MPU9250_GYRO_RANGE +#define IMU_MPU9250_GYRO_RANGE MPU9250_GYRO_RANGE_1000 #endif -/** default accel sensitivy from the datasheet - * MPU with 8g has 4096 LSB/g - * sens = 9.81 [m/s^2] / 4096 [LSB/g] * 2^INT32_ACCEL_FRAC = 2.4525 - */ +#ifndef IMU_MPU9250_ACCEL_RANGE +#define IMU_MPU9250_ACCEL_RANGE MPU9250_ACCEL_RANGE_8G +#endif + +// Set default sensitivity based on range if needed +#if !defined IMU_GYRO_P_SENS & !defined IMU_GYRO_Q_SENS & !defined IMU_GYRO_R_SENS +#define IMU_GYRO_P_SENS MPU9250_GYRO_SENS[IMU_MPU9250_GYRO_RANGE] +#define IMU_GYRO_P_SENS_NUM MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][0] +#define IMU_GYRO_P_SENS_DEN MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][1] +#define IMU_GYRO_Q_SENS MPU9250_GYRO_SENS[IMU_MPU9250_GYRO_RANGE] +#define IMU_GYRO_Q_SENS_NUM MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][0] +#define IMU_GYRO_Q_SENS_DEN MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][1] +#define IMU_GYRO_R_SENS MPU9250_GYRO_SENS[IMU_MPU9250_GYRO_RANGE] +#define IMU_GYRO_R_SENS_NUM MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][0] +#define IMU_GYRO_R_SENS_DEN MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][1] +#endif + +// Set default sensitivity based on range if needed #if !defined IMU_ACCEL_X_SENS & !defined IMU_ACCEL_Y_SENS & !defined IMU_ACCEL_Z_SENS -// FIXME -#define IMU_ACCEL_X_SENS 2.4525 -#define IMU_ACCEL_X_SENS_NUM 981 -#define IMU_ACCEL_X_SENS_DEN 400 -#define IMU_ACCEL_Y_SENS 2.4525 -#define IMU_ACCEL_Y_SENS_NUM 981 -#define IMU_ACCEL_Y_SENS_DEN 400 -#define IMU_ACCEL_Z_SENS 2.4525 -#define IMU_ACCEL_Z_SENS_NUM 981 -#define IMU_ACCEL_Z_SENS_DEN 400 +#define IMU_ACCEL_X_SENS MPU9250_ACCEL_SENS[IMU_MPU9250_ACCEL_RANGE] +#define IMU_ACCEL_X_SENS_NUM MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][0] +#define IMU_ACCEL_X_SENS_DEN MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][1] +#define IMU_ACCEL_Y_SENS MPU9250_ACCEL_SENS[IMU_MPU9250_ACCEL_RANGE] +#define IMU_ACCEL_Y_SENS_NUM MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][0] +#define IMU_ACCEL_Y_SENS_DEN MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][1] +#define IMU_ACCEL_Z_SENS MPU9250_ACCEL_SENS[IMU_MPU9250_ACCEL_RANGE] +#define IMU_ACCEL_Z_SENS_NUM MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][0] +#define IMU_ACCEL_Z_SENS_DEN MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][1] #endif diff --git a/sw/airborne/subsystems/imu/imu_mpu9250_spi.c b/sw/airborne/subsystems/imu/imu_mpu9250_spi.c index 13cd64c5fe..746e530417 100644 --- a/sw/airborne/subsystems/imu/imu_mpu9250_spi.c +++ b/sw/airborne/subsystems/imu/imu_mpu9250_spi.c @@ -67,14 +67,7 @@ PRINT_CONFIG_VAR(IMU_MPU9250_SMPLRT_DIV) PRINT_CONFIG_VAR(IMU_MPU9250_GYRO_LOWPASS_FILTER) PRINT_CONFIG_VAR(IMU_MPU9250_ACCEL_LOWPASS_FILTER) -#ifndef IMU_MPU9250_GYRO_RANGE -#define IMU_MPU9250_GYRO_RANGE MPU9250_GYRO_RANGE_1000 -#endif PRINT_CONFIG_VAR(IMU_MPU9250_GYRO_RANGE) - -#ifndef IMU_MPU9250_ACCEL_RANGE -#define IMU_MPU9250_ACCEL_RANGE MPU9250_ACCEL_RANGE_8G -#endif PRINT_CONFIG_VAR(IMU_MPU9250_ACCEL_RANGE) // Default channels order diff --git a/sw/airborne/subsystems/imu/imu_mpu9250_spi.h b/sw/airborne/subsystems/imu/imu_mpu9250_spi.h index 3019a32b5c..22406bdca5 100644 --- a/sw/airborne/subsystems/imu/imu_mpu9250_spi.h +++ b/sw/airborne/subsystems/imu/imu_mpu9250_spi.h @@ -35,39 +35,38 @@ #include "peripherals/mpu9250_spi.h" -/** default gyro sensitivy and neutral from the datasheet - * MPU with 1000 deg/s has 32.8 LSB/(deg/s) - * sens = 1/32.8 * pi/180 * 2^INT32_RATE_FRAC - * sens = 1/32.8 * pi/180 * 4096 = 2.17953 - I*/ -#if !defined IMU_GYRO_P_SENS & !defined IMU_GYRO_Q_SENS & !defined IMU_GYRO_R_SENS -// FIXME -#define IMU_GYRO_P_SENS 2.17953 -#define IMU_GYRO_P_SENS_NUM 18271 -#define IMU_GYRO_P_SENS_DEN 8383 -#define IMU_GYRO_Q_SENS 2.17953 -#define IMU_GYRO_Q_SENS_NUM 18271 -#define IMU_GYRO_Q_SENS_DEN 8383 -#define IMU_GYRO_R_SENS 2.17953 -#define IMU_GYRO_R_SENS_NUM 18271 -#define IMU_GYRO_R_SENS_DEN 8383 +#ifndef IMU_MPU9250_GYRO_RANGE +#define IMU_MPU9250_GYRO_RANGE MPU9250_GYRO_RANGE_1000 #endif -/** default accel sensitivy from the datasheet - * MPU with 8g has 4096 LSB/g - * sens = 9.81 [m/s^2] / 4096 [LSB/g] * 2^INT32_ACCEL_FRAC = 2.4525 - */ +#ifndef IMU_MPU9250_ACCEL_RANGE +#define IMU_MPU9250_ACCEL_RANGE MPU9250_ACCEL_RANGE_8G +#endif + +// Set default sensitivity based on range if needed +#if !defined IMU_GYRO_P_SENS & !defined IMU_GYRO_Q_SENS & !defined IMU_GYRO_R_SENS +#define IMU_GYRO_P_SENS MPU9250_GYRO_SENS[IMU_MPU9250_GYRO_RANGE] +#define IMU_GYRO_P_SENS_NUM MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][0] +#define IMU_GYRO_P_SENS_DEN MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][1] +#define IMU_GYRO_Q_SENS MPU9250_GYRO_SENS[IMU_MPU9250_GYRO_RANGE] +#define IMU_GYRO_Q_SENS_NUM MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][0] +#define IMU_GYRO_Q_SENS_DEN MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][1] +#define IMU_GYRO_R_SENS MPU9250_GYRO_SENS[IMU_MPU9250_GYRO_RANGE] +#define IMU_GYRO_R_SENS_NUM MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][0] +#define IMU_GYRO_R_SENS_DEN MPU9250_GYRO_SENS_FRAC[IMU_MPU9250_GYRO_RANGE][1] +#endif + +// Set default sensitivity based on range if needed #if !defined IMU_ACCEL_X_SENS & !defined IMU_ACCEL_Y_SENS & !defined IMU_ACCEL_Z_SENS -// FIXME -#define IMU_ACCEL_X_SENS 2.4525 -#define IMU_ACCEL_X_SENS_NUM 981 -#define IMU_ACCEL_X_SENS_DEN 400 -#define IMU_ACCEL_Y_SENS 2.4525 -#define IMU_ACCEL_Y_SENS_NUM 981 -#define IMU_ACCEL_Y_SENS_DEN 400 -#define IMU_ACCEL_Z_SENS 2.4525 -#define IMU_ACCEL_Z_SENS_NUM 981 -#define IMU_ACCEL_Z_SENS_DEN 400 +#define IMU_ACCEL_X_SENS MPU9250_ACCEL_SENS[IMU_MPU9250_ACCEL_RANGE] +#define IMU_ACCEL_X_SENS_NUM MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][0] +#define IMU_ACCEL_X_SENS_DEN MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][1] +#define IMU_ACCEL_Y_SENS MPU9250_ACCEL_SENS[IMU_MPU9250_ACCEL_RANGE] +#define IMU_ACCEL_Y_SENS_NUM MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][0] +#define IMU_ACCEL_Y_SENS_DEN MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][1] +#define IMU_ACCEL_Z_SENS MPU9250_ACCEL_SENS[IMU_MPU9250_ACCEL_RANGE] +#define IMU_ACCEL_Z_SENS_NUM MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][0] +#define IMU_ACCEL_Z_SENS_DEN MPU9250_ACCEL_SENS_FRAC[IMU_MPU9250_ACCEL_RANGE][1] #endif