sensors/vehicle_angular_velocity: properly handle filter reset on FIFO data scale changes

For the sake of efficiency (at 8 kHz) all filtering is performed on the raw data before the calibration and rotation is applied to only the final output. As a result we have to be a bit more careful when switching between sensors or in cases where the gyro scale factor changes (eg icm42688p 20 bit data rescaled to fit in int16 output).
This commit is contained in:
Daniel Agar
2021-04-25 14:20:32 -04:00
committed by GitHub
parent ed0fa99198
commit 8478d1ea37
6 changed files with 146 additions and 103 deletions
@@ -93,6 +93,22 @@ void PX4Accelerometer::set_device_type(uint8_t devtype)
_device_id = device_id.devid;
}
void PX4Accelerometer::set_scale(float scale)
{
if (fabsf(scale - _scale) > FLT_EPSILON) {
// rescale last sample on scale change
float rescale = _scale / scale;
for (auto &s : _last_sample) {
s = roundf(s * rescale);
}
_scale = scale;
UpdateClipLimit();
}
}
void PX4Accelerometer::update(const hrt_abstime &timestamp_sample, float x, float y, float z)
{
// Apply rotation (before scaling)