mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-30 02:00:35 +08:00
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:
@@ -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 ×tamp_sample, float x, float y, float z)
|
||||
{
|
||||
// Apply rotation (before scaling)
|
||||
|
||||
Reference in New Issue
Block a user