From 79e0e00d8c1c581a60630fbd244336beed9f2e41 Mon Sep 17 00:00:00 2001 From: bresch Date: Wed, 24 Jul 2024 15:09:17 +0200 Subject: [PATCH] ekf2: block process noise increment without constraining the variance The wind variance can be reset to a value larger than the wind init variance (e.g.: when the reset occurs when flying close to the N or E axis). Constraining the variance after a covariance initialization would artificially increase the correlation and could destabilize the filter. --- src/modules/ekf2/EKF/covariance.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/modules/ekf2/EKF/covariance.cpp b/src/modules/ekf2/EKF/covariance.cpp index 28decbc0d1..520b785544 100644 --- a/src/modules/ekf2/EKF/covariance.cpp +++ b/src/modules/ekf2/EKF/covariance.cpp @@ -201,14 +201,15 @@ void Ekf::predictCovariance(const imuSample &imu_delayed) #if defined(CONFIG_EKF2_WIND) // wind vel: add process noise - if (!_external_wind_init) { - float wind_vel_nsd_scaled = math::constrain(_params.wind_vel_nsd, 0.f, 1.f) - * (1.f + _params.wind_vel_nsd_scaler * fabsf(_height_rate_lpf)); - float wind_vel_process_noise = sq(wind_vel_nsd_scaled) * dt; + float wind_vel_nsd_scaled = math::constrain(_params.wind_vel_nsd, 0.f, 1.f) + * (1.f + _params.wind_vel_nsd_scaler * fabsf(_height_rate_lpf)); + float wind_vel_process_noise = sq(wind_vel_nsd_scaled) * dt; - for (unsigned index = 0; index < State::wind_vel.dof; index++) { - const unsigned i = State::wind_vel.idx + index; - P(i, i) = fminf(P(i, i) + wind_vel_process_noise, sq(_params.initial_wind_uncertainty)); + for (unsigned index = 0; index < State::wind_vel.dof; index++) { + const unsigned i = State::wind_vel.idx + index; + + if (P(i, i) < sq(_params.initial_wind_uncertainty)) { + P(i, i) += wind_vel_process_noise; } }