diff --git a/src/drivers/imu/invensense/icm20602/ICM20602.cpp b/src/drivers/imu/invensense/icm20602/ICM20602.cpp index bb36426e0e..60d0b9313b 100644 --- a/src/drivers/imu/invensense/icm20602/ICM20602.cpp +++ b/src/drivers/imu/invensense/icm20602/ICM20602.cpp @@ -276,27 +276,28 @@ void ICM20602::ConfigureGyro() { const uint8_t FS_SEL = RegisterRead(Register::GYRO_CONFIG) & (Bit4 | Bit3); // [4:3] FS_SEL[1:0] + float range_dps = 0.f; + switch (FS_SEL) { case FS_SEL_250_DPS: - _px4_gyro.set_scale(math::radians(1.f / 131.f)); - _px4_gyro.set_range(math::radians(250.f)); + range_dps = 250.f; break; case FS_SEL_500_DPS: - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); - _px4_gyro.set_range(math::radians(500.f)); + range_dps = 500.f; break; case FS_SEL_1000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 32.8f)); - _px4_gyro.set_range(math::radians(1000.f)); + range_dps = 1000.f; break; case FS_SEL_2000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 16.4f)); - _px4_gyro.set_range(math::radians(2000.f)); + range_dps = 2000.f; break; } + + _px4_gyro.set_scale(math::radians(range_dps / 32768.f)); + _px4_gyro.set_range(math::radians(range_dps)); } void ICM20602::ConfigureSampleRate(int sample_rate) diff --git a/src/drivers/imu/invensense/icm20608g/ICM20608G.cpp b/src/drivers/imu/invensense/icm20608g/ICM20608G.cpp index bc15b98142..fe35898cd0 100644 --- a/src/drivers/imu/invensense/icm20608g/ICM20608G.cpp +++ b/src/drivers/imu/invensense/icm20608g/ICM20608G.cpp @@ -309,27 +309,28 @@ void ICM20608G::ConfigureGyro() { const uint8_t FS_SEL = RegisterRead(Register::GYRO_CONFIG) & (Bit4 | Bit3); // [4:3] FS_SEL[1:0] + float range_dps = 0.f; + switch (FS_SEL) { case FS_SEL_250_DPS: - _px4_gyro.set_scale(math::radians(1.f / 131.f)); - _px4_gyro.set_range(math::radians(250.f)); + range_dps = 250.f; break; case FS_SEL_500_DPS: - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); - _px4_gyro.set_range(math::radians(500.f)); + range_dps = 500.f; break; case FS_SEL_1000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 32.8f)); - _px4_gyro.set_range(math::radians(1000.f)); + range_dps = 1000.f; break; case FS_SEL_2000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 16.4f)); - _px4_gyro.set_range(math::radians(2000.f)); + range_dps = 2000.f; break; } + + _px4_gyro.set_scale(math::radians(range_dps / 32768.f)); + _px4_gyro.set_range(math::radians(range_dps)); } void ICM20608G::ConfigureSampleRate(int sample_rate) diff --git a/src/drivers/imu/invensense/icm20649/ICM20649.cpp b/src/drivers/imu/invensense/icm20649/ICM20649.cpp index 1161b3bbc1..2102c97998 100644 --- a/src/drivers/imu/invensense/icm20649/ICM20649.cpp +++ b/src/drivers/imu/invensense/icm20649/ICM20649.cpp @@ -291,27 +291,28 @@ void ICM20649::ConfigureGyro() { const uint8_t GYRO_FS_SEL = RegisterRead(Register::BANK_2::GYRO_CONFIG_1) & (Bit2 | Bit1); // 2:1 GYRO_FS_SEL[1:0] + float range_dps = 0.f; + switch (GYRO_FS_SEL) { case GYRO_FS_SEL_500_DPS: - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); - _px4_gyro.set_range(math::radians(500.f)); + range_dps = 500.f; break; case GYRO_FS_SEL_1000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 32.8f)); - _px4_gyro.set_range(math::radians(1000.f)); + range_dps = 1000.f; break; case GYRO_FS_SEL_2000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 16.4f)); - _px4_gyro.set_range(math::radians(2000.f)); + range_dps = 2000.f; break; case GYRO_FS_SEL_4000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 8.2f)); - _px4_gyro.set_range(math::radians(4000.f)); + range_dps = 4000.f; break; } + + _px4_gyro.set_scale(math::radians(range_dps / 32768.f)); + _px4_gyro.set_range(math::radians(range_dps)); } void ICM20649::ConfigureSampleRate(int sample_rate) diff --git a/src/drivers/imu/invensense/icm20689/ICM20689.cpp b/src/drivers/imu/invensense/icm20689/ICM20689.cpp index 874dfead4f..8a9ad86c4d 100644 --- a/src/drivers/imu/invensense/icm20689/ICM20689.cpp +++ b/src/drivers/imu/invensense/icm20689/ICM20689.cpp @@ -309,27 +309,28 @@ void ICM20689::ConfigureGyro() { const uint8_t FS_SEL = RegisterRead(Register::GYRO_CONFIG) & (Bit4 | Bit3); // [4:3] FS_SEL[1:0] + float range_dps = 0.f; + switch (FS_SEL) { case FS_SEL_250_DPS: - _px4_gyro.set_scale(math::radians(1.f / 131.f)); - _px4_gyro.set_range(math::radians(250.f)); + range_dps = 250.f; break; case FS_SEL_500_DPS: - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); - _px4_gyro.set_range(math::radians(500.f)); + range_dps = 500.f; break; case FS_SEL_1000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 32.8f)); - _px4_gyro.set_range(math::radians(1000.f)); + range_dps = 1000.f; break; case FS_SEL_2000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 16.4f)); - _px4_gyro.set_range(math::radians(2000.f)); + range_dps = 2000.f; break; } + + _px4_gyro.set_scale(math::radians(range_dps / 32768.f)); + _px4_gyro.set_range(math::radians(range_dps)); } void ICM20689::ConfigureSampleRate(int sample_rate) diff --git a/src/drivers/imu/invensense/icm20948/ICM20948.cpp b/src/drivers/imu/invensense/icm20948/ICM20948.cpp index 5e10f237b4..30b3cbd66e 100644 --- a/src/drivers/imu/invensense/icm20948/ICM20948.cpp +++ b/src/drivers/imu/invensense/icm20948/ICM20948.cpp @@ -325,27 +325,28 @@ void ICM20948::ConfigureGyro() { const uint8_t GYRO_FS_SEL = RegisterRead(Register::BANK_2::GYRO_CONFIG_1) & (Bit2 | Bit1); // 2:1 GYRO_FS_SEL[1:0] + float range_dps = 0.f; + switch (GYRO_FS_SEL) { case GYRO_FS_SEL_250_DPS: - _px4_gyro.set_scale(math::radians(1.f / 131.f)); - _px4_gyro.set_range(math::radians(250.f)); + range_dps = 250.f; break; case GYRO_FS_SEL_500_DPS: - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); - _px4_gyro.set_range(math::radians(500.f)); + range_dps = 500.f; break; case GYRO_FS_SEL_1000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 32.8f)); - _px4_gyro.set_range(math::radians(1000.f)); + range_dps = 1000.f; break; case GYRO_FS_SEL_2000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 16.4f)); - _px4_gyro.set_range(math::radians(2000.f)); + range_dps = 2000.f; break; } + + _px4_gyro.set_scale(math::radians(range_dps / 32768.f)); + _px4_gyro.set_range(math::radians(range_dps)); } void ICM20948::ConfigureSampleRate(int sample_rate) diff --git a/src/drivers/imu/invensense/icm40609d/ICM40609D.cpp b/src/drivers/imu/invensense/icm40609d/ICM40609D.cpp index 4f05c09c18..b3fa151991 100644 --- a/src/drivers/imu/invensense/icm40609d/ICM40609D.cpp +++ b/src/drivers/imu/invensense/icm40609d/ICM40609D.cpp @@ -277,32 +277,32 @@ void ICM40609D::ConfigureGyro() { const uint8_t GYRO_FS_SEL = RegisterRead(Register::BANK_0::GYRO_CONFIG0) & (Bit7 | Bit6 | Bit5); // 7:5 GYRO_FS_SEL + float range_dps = 0.f; + switch (GYRO_FS_SEL) { case GYRO_FS_SEL_125_DPS: - _px4_gyro.set_scale(math::radians(1.f / 262.f)); - _px4_gyro.set_range(math::radians(125.f)); + range_dps = 125.f; break; case GYRO_FS_SEL_250_DPS: - _px4_gyro.set_scale(math::radians(1.f / 131.f)); - _px4_gyro.set_range(math::radians(250.f)); + range_dps = 250.f; break; case GYRO_FS_SEL_500_DPS: - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); - _px4_gyro.set_range(math::radians(500.f)); + range_dps = 500.f; break; case GYRO_FS_SEL_1000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 32.8f)); - _px4_gyro.set_range(math::radians(1000.f)); + range_dps = 1000.f; break; case GYRO_FS_SEL_2000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 16.4f)); - _px4_gyro.set_range(math::radians(2000.f)); + range_dps = 2000.f; break; } + + _px4_gyro.set_scale(math::radians(range_dps / 32768.f)); + _px4_gyro.set_range(math::radians(range_dps)); } void ICM40609D::ConfigureSampleRate(int sample_rate) diff --git a/src/drivers/imu/invensense/icm42688p/ICM42688P.cpp b/src/drivers/imu/invensense/icm42688p/ICM42688P.cpp index 27b079e425..dc3787b117 100644 --- a/src/drivers/imu/invensense/icm42688p/ICM42688P.cpp +++ b/src/drivers/imu/invensense/icm42688p/ICM42688P.cpp @@ -279,32 +279,32 @@ void ICM42688P::ConfigureGyro() { const uint8_t GYRO_FS_SEL = RegisterRead(Register::BANK_0::GYRO_CONFIG0) & (Bit7 | Bit6 | Bit5); // 7:5 GYRO_FS_SEL + float range_dps = 0.f; + switch (GYRO_FS_SEL) { case GYRO_FS_SEL_125_DPS: - _px4_gyro.set_scale(math::radians(1.f / 262.f)); - _px4_gyro.set_range(math::radians(125.f)); + range_dps = 125.f; break; case GYRO_FS_SEL_250_DPS: - _px4_gyro.set_scale(math::radians(1.f / 131.f)); - _px4_gyro.set_range(math::radians(250.f)); + range_dps = 250.f; break; case GYRO_FS_SEL_500_DPS: - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); - _px4_gyro.set_range(math::radians(500.f)); + range_dps = 500.f; break; case GYRO_FS_SEL_1000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 32.8f)); - _px4_gyro.set_range(math::radians(1000.f)); + range_dps = 1000.f; break; case GYRO_FS_SEL_2000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 16.4f)); - _px4_gyro.set_range(math::radians(2000.f)); + range_dps = 2000.f; break; } + + _px4_gyro.set_scale(math::radians(range_dps / 32768.f)); + _px4_gyro.set_range(math::radians(range_dps)); } void ICM42688P::ConfigureSampleRate(int sample_rate) diff --git a/src/drivers/imu/invensense/mpu6000/MPU6000.cpp b/src/drivers/imu/invensense/mpu6000/MPU6000.cpp index 857bf6d2d0..a58f29f4c1 100644 --- a/src/drivers/imu/invensense/mpu6000/MPU6000.cpp +++ b/src/drivers/imu/invensense/mpu6000/MPU6000.cpp @@ -309,27 +309,28 @@ void MPU6000::ConfigureGyro() { const uint8_t GYRO_FS_SEL = RegisterRead(Register::GYRO_CONFIG) & (Bit4 | Bit3); // [4:3] FS_SEL[1:0] + float range_dps = 0.f; + switch (GYRO_FS_SEL) { case FS_SEL_250_DPS: - _px4_gyro.set_scale(math::radians(1.f / 131.f)); - _px4_gyro.set_range(math::radians(250.f)); + range_dps = 250.f; break; case FS_SEL_500_DPS: - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); - _px4_gyro.set_range(math::radians(500.f)); + range_dps = 500.f; break; case FS_SEL_1000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 32.8f)); - _px4_gyro.set_range(math::radians(1000.f)); + range_dps = 1000.f; break; case FS_SEL_2000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 16.4f)); - _px4_gyro.set_range(math::radians(2000.f)); + range_dps = 2000.f; break; } + + _px4_gyro.set_scale(math::radians(range_dps / 32768.f)); + _px4_gyro.set_range(math::radians(range_dps)); } void MPU6000::ConfigureSampleRate(int sample_rate) diff --git a/src/drivers/imu/invensense/mpu6500/MPU6500.cpp b/src/drivers/imu/invensense/mpu6500/MPU6500.cpp index 28c85a7066..f388a12691 100644 --- a/src/drivers/imu/invensense/mpu6500/MPU6500.cpp +++ b/src/drivers/imu/invensense/mpu6500/MPU6500.cpp @@ -284,27 +284,28 @@ void MPU6500::ConfigureGyro() { const uint8_t GYRO_FS_SEL = RegisterRead(Register::GYRO_CONFIG) & (Bit4 | Bit3); // [4:3] GYRO_FS_SEL[1:0] + float range_dps = 0.f; + switch (GYRO_FS_SEL) { case GYRO_FS_SEL_250_DPS: - _px4_gyro.set_scale(math::radians(1.f / 131.f)); - _px4_gyro.set_range(math::radians(250.f)); + range_dps = 250.f; break; case GYRO_FS_SEL_500_DPS: - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); - _px4_gyro.set_range(math::radians(500.f)); + range_dps = 500.f; break; case GYRO_FS_SEL_1000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 32.8f)); - _px4_gyro.set_range(math::radians(1000.f)); + range_dps = 1000.f; break; case GYRO_FS_SEL_2000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 16.4f)); - _px4_gyro.set_range(math::radians(2000.f)); + range_dps = 2000.f; break; } + + _px4_gyro.set_scale(math::radians(range_dps / 32768.f)); + _px4_gyro.set_range(math::radians(range_dps)); } void MPU6500::ConfigureSampleRate(int sample_rate) diff --git a/src/drivers/imu/invensense/mpu9250/MPU9250.cpp b/src/drivers/imu/invensense/mpu9250/MPU9250.cpp index 238cc19e1a..de3c06015a 100644 --- a/src/drivers/imu/invensense/mpu9250/MPU9250.cpp +++ b/src/drivers/imu/invensense/mpu9250/MPU9250.cpp @@ -317,27 +317,28 @@ void MPU9250::ConfigureGyro() { const uint8_t GYRO_FS_SEL = RegisterRead(Register::GYRO_CONFIG) & (Bit4 | Bit3); // [4:3] GYRO_FS_SEL[1:0] + float range_dps = 0.f; + switch (GYRO_FS_SEL) { case GYRO_FS_SEL_250_DPS: - _px4_gyro.set_scale(math::radians(1.f / 131.f)); - _px4_gyro.set_range(math::radians(250.f)); + range_dps = 250.f; break; case GYRO_FS_SEL_500_DPS: - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); - _px4_gyro.set_range(math::radians(500.f)); + range_dps = 500.f; break; case GYRO_FS_SEL_1000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 32.8f)); - _px4_gyro.set_range(math::radians(1000.f)); + range_dps = 1000.f; break; case GYRO_FS_SEL_2000_DPS: - _px4_gyro.set_scale(math::radians(1.f / 16.4f)); - _px4_gyro.set_range(math::radians(2000.f)); + range_dps = 2000.f; break; } + + _px4_gyro.set_scale(math::radians(range_dps / 32768.f)); + _px4_gyro.set_range(math::radians(range_dps)); } void MPU9250::ConfigureSampleRate(int sample_rate)