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.
This commit is contained in:
Jacob Dahl authored and GitHub committed 2026-08-03 14:58:36 -06:00
1 parent 12ce34c2cf
commit fd88a612f2
3 files changed
+11 -9

No files matched your search

@@ -801,13 +801,13 @@ void ICM42688P::ProcessGyro(const hrt_abstime &timestamp_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 &timestamp_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));
@@ -777,8 +777,9 @@ void IIM42652::ProcessGyro(const hrt_abstime &timestamp_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)
@@ -778,8 +778,9 @@ void IIM42653::ProcessGyro(const hrt_abstime &timestamp_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)