From 768d1ce3161a23b81ddce53a1a80dd4cf1df210f Mon Sep 17 00:00:00 2001 From: bresch Date: Thu, 20 Aug 2026 14:33:58 +0200 Subject: [PATCH] fix(ekf2): map GNSS check param bits to fail status bits explicitly The published gps_check_fail_flags mask was derived from EKF2_GPS_CHECK with a positional shift, assuming param bit N corresponds to fail status bit N+1. That only holds up to kSpoofed: the fix check sits at param bit 10 but status bit 0, so the shift made param bit 10 (Fix type) publish status bit 11 (jammed), and param bit 11 (Jamming) map to a status bit no check ever sets. With the default EKF2_GPS_CHECK of 2047 the published mask was therefore 4095, which reports a jamming failure even though the jamming check is disabled, while enabling the jamming check published nothing. Map the two layouts one by one in GnssChecks, which owns both, so appending a check to one enum can no longer silently misassign the others. The fix bit is now gated on kFix like every other check, matching how it is already gated when computing whether the checks passed. --- .../ekf2/EKF/aid_sources/gnss/gnss_checks.hpp | 26 ++++++++++++++++++- src/modules/ekf2/EKF/ekf.h | 1 + src/modules/ekf2/EKF2.cpp | 5 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/modules/ekf2/EKF/aid_sources/gnss/gnss_checks.hpp b/src/modules/ekf2/EKF/aid_sources/gnss/gnss_checks.hpp index 0d2fe978e75..e01d0e47764 100644 --- a/src/modules/ekf2/EKF/aid_sources/gnss/gnss_checks.hpp +++ b/src/modules/ekf2/EKF/aid_sources/gnss/gnss_checks.hpp @@ -68,6 +68,30 @@ public: uint16_t value; }; + /** + * Fail-status flags (gps_check_fail_status_u layout) of the checks enabled by EKF2_GPS_CHECK. + * The param bit order (GnssChecksMask) and the status bit order are not parallel, so they are + * mapped one by one: a positional shift silently misassigns every check that is appended to + * one of the two enums but not the other. + */ + uint16_t getEnabledChecksFailStatusMask() const + { + gps_check_fail_status_u mask{}; + mask.flags.fix = isCheckEnabled(GnssChecksMask::kFix); + mask.flags.nsats = isCheckEnabled(GnssChecksMask::kNsats); + mask.flags.pdop = isCheckEnabled(GnssChecksMask::kPdop); + mask.flags.hacc = isCheckEnabled(GnssChecksMask::kHacc); + mask.flags.vacc = isCheckEnabled(GnssChecksMask::kVacc); + mask.flags.sacc = isCheckEnabled(GnssChecksMask::kSacc); + mask.flags.hdrift = isCheckEnabled(GnssChecksMask::kHdrift); + mask.flags.vdrift = isCheckEnabled(GnssChecksMask::kVdrift); + mask.flags.hspeed = isCheckEnabled(GnssChecksMask::kHspd); + mask.flags.vspeed = isCheckEnabled(GnssChecksMask::kVspd); + mask.flags.spoofed = isCheckEnabled(GnssChecksMask::kSpoofed); + mask.flags.jammed = isCheckEnabled(GnssChecksMask::kJammed); + return mask.value; + } + void resetHard() { _initial_checks_passed = false; @@ -113,7 +137,7 @@ private: kJammed = (1 << 11) }; - bool isCheckEnabled(GnssChecksMask check) { return (_params.check_mask & static_cast(check)); } + bool isCheckEnabled(GnssChecksMask check) const { return (_params.check_mask & static_cast(check)); } bool runSimplifiedChecks(const gnssSample &gnss); bool runInitialFixChecks(const gnssSample &gnss); diff --git a/src/modules/ekf2/EKF/ekf.h b/src/modules/ekf2/EKF/ekf.h index 558e1dcf66d..b73c16d09b7 100644 --- a/src/modules/ekf2/EKF/ekf.h +++ b/src/modules/ekf2/EKF/ekf.h @@ -406,6 +406,7 @@ public: const GnssChecks::gps_check_fail_status_u &gps_check_fail_status() const { return _gnss_checks.getFailStatus(); } const decltype(GnssChecks::gps_check_fail_status_u::flags) &gps_check_fail_status_flags() const { return _gnss_checks.getFailStatus().flags; } + uint16_t gps_check_fail_status_enabled_mask() const { return _gnss_checks.getEnabledChecksFailStatusMask(); } bool gps_checks_passed() const { return _gnss_checks.passed(); }; diff --git a/src/modules/ekf2/EKF2.cpp b/src/modules/ekf2/EKF2.cpp index 5a1bbace04b..091f473da0f 100644 --- a/src/modules/ekf2/EKF2.cpp +++ b/src/modules/ekf2/EKF2.cpp @@ -1948,9 +1948,8 @@ void EKF2::PublishStatus(const hrt_abstime ×tamp) _ekf.getOutputTrackingError().copyTo(status.output_tracking_error); #if defined(CONFIG_EKF2_GNSS) - // only report enabled GPS check failures (the param indexes are shifted by 1 bit, because they don't include - // the GPS Fix bit, which is always checked) - status.gps_check_fail_flags = _ekf.gps_check_fail_status().value & (((uint16_t)_params->ekf2_gps_check << 1) | 1); + // only report enabled GPS check failures + status.gps_check_fail_flags = _ekf.gps_check_fail_status().value & _ekf.gps_check_fail_status_enabled_mask(); #endif // CONFIG_EKF2_GNSS status.control_mode_flags = _ekf.control_status().value;