From 7db998e017687f97ff1fb52bce3769006957f2d9 Mon Sep 17 00:00:00 2001 From: "G. Amponis" <71447362+g-ampo@users.noreply.github.com> Date: Thu, 7 May 2026 19:17:17 +0200 Subject: [PATCH] fix(ekf2/commander): split no-heading-source from heading-innovation-failure (#27215) * fix(ekf2,commander): split "no heading source" from heading-innovation-failure The pre_flt_fail_innov_heading flag conflated two distinct conditions: bad heading innovations and the absence of any heading source. Optical-flow-only quad setups (no magnetometer, no GNSS yaw, no external-vision yaw) never set yaw_align, so the flag latched true and produced a misleading "Preflight Fail: heading estimate invalid" message in modes that don't actually depend on heading. EKF2: pre_flt_fail_innov_heading now reports innovation failures only. Commander: a new branch consumes estimator_status_flags.cs_yaw_align (when fresh) to block heading-required modes (POSCTL, AUTO_*, ORBIT, AUTO_LAND, FW AUTO_TAKEOFF) when no source is present, with a new "no heading reference" message. The branch only fires for fresh estimator_status_flags data so external-INS drivers (MicroStrain, VectorNav, ILabs, sbgecom) that don't publish the flags topic retain prior behaviour. PR #26778's mode-scoping and PR #26596's silent-pass protection are both preserved. Resolves #27107. * style: trim source comments per review * Apply suggestions from code review Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> * refactor(commander): move no-heading-source check into checkEstimatorStatusFlags * Update src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> --------- Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> --- .../checks/estimatorCheck.cpp | 22 +++++++++++++++++++ src/modules/ekf2/EKF2.cpp | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp b/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp index eb545ad2ce9..b1e13740263 100644 --- a/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp +++ b/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp @@ -625,6 +625,28 @@ void EstimatorChecks::checkEstimatorStatusFlags(const Context &context, Report & mavlink_log_critical(reporter.mavlink_log_pub(), "GNSS heading not reliable - Land now!\t"); } } + + if (!context.isArmed() + && (hrt_absolute_time() - estimator_status_flags.timestamp < 5_s) + && !estimator_status_flags.cs_yaw_align) { + + const NavModes heading_required_groups = (NavModes)( + reporter.failsafeFlags().mode_req_local_position | + reporter.failsafeFlags().mode_req_local_position_relaxed | + (1u << vehicle_status_s::NAVIGATION_STATE_AUTO_TAKEOFF)); + + /* EVENT + * @description + * No heading source has aligned the EKF yaw + */ + reporter.armingCheckFailure(heading_required_groups, health_component_t::local_position_estimate, + events::ID("check_estimator_heading_no_source"), + events::Log::Error, "No heading reference"); + + if (reporter.mavlink_log_pub()) { + mavlink_log_critical(reporter.mavlink_log_pub(), "Preflight Fail: no heading reference"); + } + } } } diff --git a/src/modules/ekf2/EKF2.cpp b/src/modules/ekf2/EKF2.cpp index 919d0f9a7f9..3a42bc274f4 100644 --- a/src/modules/ekf2/EKF2.cpp +++ b/src/modules/ekf2/EKF2.cpp @@ -1987,7 +1987,7 @@ void EKF2::PublishStatus(const hrt_abstime ×tamp) status.time_slip = _last_time_slip_us * 1e-6f; static constexpr float kMinTestRatioPreflight = 0.5f; - status.pre_flt_fail_innov_heading = (kMinTestRatioPreflight < status.hdg_test_ratio) || !_ekf.control_status_flags().yaw_align; + status.pre_flt_fail_innov_heading = (kMinTestRatioPreflight < status.hdg_test_ratio); status.pre_flt_fail_innov_height = (kMinTestRatioPreflight < status.hgt_test_ratio); status.pre_flt_fail_innov_pos_horiz = (kMinTestRatioPreflight < status.pos_test_ratio); status.pre_flt_fail_innov_vel_horiz = (kMinTestRatioPreflight < vel_xy_test_ratio);