From ca112fea8a8292e6892f7e551b4a3237779f6f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 31 May 2024 15:59:38 +0200 Subject: [PATCH] fix commander: make sure to count all valid mags in preflight check Previously, if a mag was not required (not index 0 and not used by ekf), it was not counted in num_enabled_and_valid_calibration. If a user set SYS_HAS_MAG to e.g. 3, it would then trigger a preflight failure, even if there were 3 calibrated and enabled mags. --- .../HealthAndArmingChecks/checks/magnetometerCheck.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/modules/commander/HealthAndArmingChecks/checks/magnetometerCheck.cpp b/src/modules/commander/HealthAndArmingChecks/checks/magnetometerCheck.cpp index 117a23a2b8..6716a8e06a 100644 --- a/src/modules/commander/HealthAndArmingChecks/checks/magnetometerCheck.cpp +++ b/src/modules/commander/HealthAndArmingChecks/checks/magnetometerCheck.cpp @@ -50,10 +50,6 @@ void MagnetometerChecks::checkAndReport(const Context &context, Report &reporter bool is_mag_fault = false; const bool is_required = instance == 0 || isMagRequired(instance, is_mag_fault); - if (!is_required) { - continue; - } - const bool exists = _sensor_mag_sub[instance].advertised(); bool is_valid = false; bool is_calibration_valid = false; @@ -83,6 +79,11 @@ void MagnetometerChecks::checkAndReport(const Context &context, Report &reporter reporter.setIsPresent(health_component_t::magnetometer); } + // Do not raise errors if a mag is not required + if (!is_required) { + continue; + } + const bool is_sensor_ok = is_valid && is_calibration_valid && !is_mag_fault; if (!is_sensor_ok) {