From 49624a6457858346d651c8ffb6a94a52d8026428 Mon Sep 17 00:00:00 2001 From: bresch Date: Tue, 25 Mar 2025 17:37:30 +0100 Subject: [PATCH] mag: synchronize calibration count with newly calibrated data The data contained a mix between the old and new calibration. This caused the EKF to reset to an incorrect (intermediate) heading. --- .../sensors/vehicle_magnetometer/VehicleMagnetometer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/modules/sensors/vehicle_magnetometer/VehicleMagnetometer.cpp b/src/modules/sensors/vehicle_magnetometer/VehicleMagnetometer.cpp index a0ba14bcfd..08afb1d57d 100644 --- a/src/modules/sensors/vehicle_magnetometer/VehicleMagnetometer.cpp +++ b/src/modules/sensors/vehicle_magnetometer/VehicleMagnetometer.cpp @@ -191,6 +191,13 @@ bool VehicleMagnetometer::ParametersUpdate(bool force) if (calibration_updated) { _last_calibration_update = hrt_absolute_time(); + + for (int instance = 0; instance < MAX_SENSOR_COUNT; instance++) { + // avoid mixing data currected using old calibration + _timestamp_sample_sum[instance] = 0; + _data_sum[instance].zero(); + _data_sum_count[instance] = 0; + } } }