From fd88a612f208c0addfca09c7b012ea421c73572a Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Mon, 3 Aug 2026 14:58:36 -0600 Subject: [PATCH] fix(drivers/invensense): use exact 20-bit gyro scale factors (#28133) The 20-bit high resolution scales were built from the datasheet's rounded sensitivity figures, 131 and 65.5 LSB/dps, rather than the exact FSR/2^18 the hardware produces (131.072 and 65.536). The published rate is 0.055% low as a result. Both branches decode the same measurement, so they must agree exactly: the high resolution branch publishes the 20 bit value shifted right by 1 and the fallback publishes it shifted right by 4, which is a factor of 8, not 7.996. Today the reported rate steps by 0.055% every time a batch crosses the threshold between them. Also spell the 686 fallback as 4000/32768 instead of the numerically identical 2000/16384, so it matches the +/-4000 dps range set for that part. --- src/drivers/imu/invensense/icm42688p/ICM42688P.cpp | 10 +++++----- src/drivers/imu/invensense/iim42652/IIM42652.cpp | 5 +++-- src/drivers/imu/invensense/iim42653/IIM42653.cpp | 5 +++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/drivers/imu/invensense/icm42688p/ICM42688P.cpp b/src/drivers/imu/invensense/icm42688p/ICM42688P.cpp index 4fef1647922..14cf4b945ff 100644 --- a/src/drivers/imu/invensense/icm42688p/ICM42688P.cpp +++ b/src/drivers/imu/invensense/icm42688p/ICM42688P.cpp @@ -801,13 +801,13 @@ void ICM42688P::ProcessGyro(const hrt_abstime ×tamp_sample, const FIFO::DAT } if (!scale_20bit) { - // On the 686, if highres enabled gyro data is always 65.5 LSB/dps - // On the 688, if highres enabled gyro data is always 131 LSB/dps + // published data is the 20 bit value shifted right by 1, so it spans the full range in + // 2^18 counts: 65.536 LSB/dps on the 686, 131.072 LSB/dps on the 688 if (isICM686) { - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); + _px4_gyro.set_scale(math::radians(4000.f / 262144.f)); } else { - _px4_gyro.set_scale(math::radians(1.f / 131.f)); + _px4_gyro.set_scale(math::radians(2000.f / 262144.f)); } } else { @@ -819,7 +819,7 @@ void ICM42688P::ProcessGyro(const hrt_abstime ×tamp_sample, const FIFO::DAT } if (isICM686) { - _px4_gyro.set_scale(math::radians(2000.f / 16384.f)); + _px4_gyro.set_scale(math::radians(4000.f / 32768.f)); } else { _px4_gyro.set_scale(math::radians(2000.f / 32768.f)); diff --git a/src/drivers/imu/invensense/iim42652/IIM42652.cpp b/src/drivers/imu/invensense/iim42652/IIM42652.cpp index cedd6bfe44c..757f8c2113b 100644 --- a/src/drivers/imu/invensense/iim42652/IIM42652.cpp +++ b/src/drivers/imu/invensense/iim42652/IIM42652.cpp @@ -777,8 +777,9 @@ void IIM42652::ProcessGyro(const hrt_abstime ×tamp_sample, const FIFO::DATA } if (!scale_20bit) { - // if highres enabled gyro data is always 131 LSB/dps - _px4_gyro.set_scale(math::radians(1.f / 131.f)); + // published data is the 20 bit value shifted right by 1, so it spans the full range in + // 2^18 counts: 131.072 LSB/dps + _px4_gyro.set_scale(math::radians(2000.f / 262144.f)); } else { // 20 bit data scaled to 16 bit (2^4) diff --git a/src/drivers/imu/invensense/iim42653/IIM42653.cpp b/src/drivers/imu/invensense/iim42653/IIM42653.cpp index d25f37fef1c..be6af1ed954 100644 --- a/src/drivers/imu/invensense/iim42653/IIM42653.cpp +++ b/src/drivers/imu/invensense/iim42653/IIM42653.cpp @@ -778,8 +778,9 @@ void IIM42653::ProcessGyro(const hrt_abstime ×tamp_sample, const FIFO::DATA } if (!scale_20bit) { - // if highres enabled gyro data is always 65.5 LSB/dps - _px4_gyro.set_scale(math::radians(1.f / 65.5f)); + // published data is the 20 bit value shifted right by 1, so it spans the full range in + // 2^18 counts: 65.536 LSB/dps + _px4_gyro.set_scale(math::radians(4000.f / 262144.f)); } else { // 20 bit data scaled to 16 bit (2^4)