From 82a482ec0bffe2b17de262a43717e178668dc379 Mon Sep 17 00:00:00 2001 From: bresch Date: Tue, 25 Mar 2025 14:27:19 +0100 Subject: [PATCH] ekf2: reset heading when mag calibration changed --- .../ekf2/EKF/aid_sources/magnetometer/mag_control.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/modules/ekf2/EKF/aid_sources/magnetometer/mag_control.cpp b/src/modules/ekf2/EKF/aid_sources/magnetometer/mag_control.cpp index e3ac4a9d82..dbf3d05989 100644 --- a/src/modules/ekf2/EKF/aid_sources/magnetometer/mag_control.cpp +++ b/src/modules/ekf2/EKF/aid_sources/magnetometer/mag_control.cpp @@ -75,6 +75,12 @@ void Ekf::controlMagFusion(const imuSample &imu_sample) _mag_lpf.reset(mag_sample.mag); _mag_counter = 1; + if (!_control_status.flags.in_air) { + // Assume that a reset on the ground is caused by a change in mag calibration + // Clear alignment to force a clean reset + _control_status.flags.yaw_align = false; + } + } else { _mag_lpf.update(mag_sample.mag); _mag_counter++;