Skip to content

Commit

Permalink
drivers/accelerometer: adjust int16_t clipping threshold slightly
Browse files Browse the repository at this point in the history
 - 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)
  • Loading branch information
dagar committed Dec 15, 2021
1 parent ea29b45 commit d59d16a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/drivers/accelerometer/PX4Accelerometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
Expand Down

0 comments on commit d59d16a

Please sign in to comment.