From d59d16a6cda98db6b10c26951e087ad9963d5082 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Mon, 13 Dec 2021 12:18:53 -0500 Subject: [PATCH] drivers/accelerometer: adjust int16_t clipping threshold slightly - consider data clipped/saturated if it's INT16_MIN/INT16_MAX or within 1 - this accommodates rotated data (|INT16_MIN| = INT16_MAX + 1) and sensors that may re-use the lowest bit for other purposes (sync indicator, etc) --- src/lib/drivers/accelerometer/PX4Accelerometer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/drivers/accelerometer/PX4Accelerometer.cpp b/src/lib/drivers/accelerometer/PX4Accelerometer.cpp index e63d48ce88c1..9994745a0216 100644 --- a/src/lib/drivers/accelerometer/PX4Accelerometer.cpp +++ b/src/lib/drivers/accelerometer/PX4Accelerometer.cpp @@ -55,7 +55,10 @@ static constexpr uint8_t clipping(const int16_t samples[], uint8_t len) unsigned clip_count = 0; for (int n = 0; n < len; n++) { - if ((samples[n] == INT16_MIN) || (samples[n] == INT16_MAX)) { + // - consider data clipped/saturated if it's INT16_MIN/INT16_MAX or within 1 + // - this accommodates rotated data (|INT16_MIN| = INT16_MAX + 1) + // and sensors that may re-use the lowest bit for other purposes (sync indicator, etc) + if ((samples[n] <= INT16_MIN + 1) || (samples[n] >= INT16_MAX - 1)) { clip_count++; } }