diff --git a/boards/agam/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld b/boards/agam/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld
index c27d1b61d3d..ae3172c7177 100644
--- a/boards/agam/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld
+++ b/boards/agam/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld
@@ -459,7 +459,7 @@
*(.text._ZN24ManualVelocitySmoothingZC1Ev) /* itcm-check-ignore */
*(.text._ZN3ADC6sampleEj)
*(.text._ZNK3Ekf22isTerrainEstimateValidEv)
-*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
+*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sRK24estimator_status_flags_sR16failsafe_flags_sR6Report)
*(.text._ZN15EstimatorChecks29warnOfImminentPositionFailureER6ReportRKyRK25vehicle_global_position_sfRK16failsafe_flags_s)
*(.text._ZN11ControlMath11addIfNotNanERff)
*(.text._ZN9Commander21checkForMissionUpdateEv)
@@ -601,13 +601,13 @@
*(.text._ZN12SafetyButton3RunEv)
*(.text._ZN3GPS8callbackE15GPSCallbackTypePviS1_)
*(.text._ZN13AnalogBattery19get_current_channelEv)
-*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_s8NavModes)
+*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_sRK24estimator_status_flags_sRK14vehicle_gnss_s8NavModes)
*(.text._ZN15EstimatorChecks25checkInnovationsPreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
*(.text._ZN15EstimatorChecks34checkMagneticInterferencePreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
-*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_s)
+*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_sRK24estimator_status_flags_sRK14vehicle_gnss_s)
*(.text._ZN15EstimatorChecks22reportGnssFusionChangeERK7ContextR6Reportb)
*(.text._ZN15EstimatorChecks22reportGnssInterferenceER6Reportt)
-*(.text._ZN15EstimatorChecks30reportFailedGnssCheckPreflightER6ReportRK18estimator_status_sb)
+*(.text._ZN15EstimatorChecks19reportGnssPreflightER6Reportht)
*(.text._ZN12FailsafeBase11updateDelayERKy)
*(.text._ZN10FlightTask25_evaluateDistanceToGroundEv)
*(.text._ZN4EKF218PublishGnssHgtBiasERKy)
diff --git a/boards/ark/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld b/boards/ark/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld
index e91e9cd1c65..cbe245da6e3 100644
--- a/boards/ark/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld
+++ b/boards/ark/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld
@@ -446,7 +446,7 @@
*(.text._ZN24ManualVelocitySmoothingZC1Ev) /* itcm-check-ignore */
*(.text._ZN3ADC6sampleEj)
*(.text._ZNK3Ekf22isTerrainEstimateValidEv)
-*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
+*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sRK24estimator_status_flags_sR16failsafe_flags_sR6Report)
*(.text._ZN15EstimatorChecks29warnOfImminentPositionFailureER6ReportRKyRK25vehicle_global_position_sfRK16failsafe_flags_s)
*(.text._ZN11ControlMath11addIfNotNanERff)
*(.text._ZN9Commander21checkForMissionUpdateEv)
@@ -586,13 +586,13 @@
*(.text._ZN11StickTiltXYC1EP12ModuleParams)
*(.text._ZN12SafetyButton3RunEv)
*(.text._ZN3GPS8callbackE15GPSCallbackTypePviS1_)
-*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_s8NavModes)
+*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_sRK24estimator_status_flags_sRK14vehicle_gnss_s8NavModes)
*(.text._ZN15EstimatorChecks25checkInnovationsPreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
*(.text._ZN15EstimatorChecks34checkMagneticInterferencePreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
-*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_s)
+*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_sRK24estimator_status_flags_sRK14vehicle_gnss_s)
*(.text._ZN15EstimatorChecks22reportGnssFusionChangeERK7ContextR6Reportb)
*(.text._ZN15EstimatorChecks22reportGnssInterferenceER6Reportt)
-*(.text._ZN15EstimatorChecks30reportFailedGnssCheckPreflightER6ReportRK18estimator_status_sb)
+*(.text._ZN15EstimatorChecks19reportGnssPreflightER6Reportht)
*(.text._ZN12FailsafeBase11updateDelayERKy)
*(.text._ZN10FlightTask25_evaluateDistanceToGroundEv)
*(.text._ZN4EKF218PublishGnssHgtBiasERKy)
diff --git a/boards/nxp/mr-tropic/nuttx-config/scripts/itcm_functions_includes.ld b/boards/nxp/mr-tropic/nuttx-config/scripts/itcm_functions_includes.ld
index 6f9141d6a96..c48b9026677 100644
--- a/boards/nxp/mr-tropic/nuttx-config/scripts/itcm_functions_includes.ld
+++ b/boards/nxp/mr-tropic/nuttx-config/scripts/itcm_functions_includes.ld
@@ -452,7 +452,7 @@
*(.text._ZN24ManualVelocitySmoothingZC1Ev) /* itcm-check-ignore */
*(.text._ZN3ADC6sampleEj)
*(.text._ZNK3Ekf22isTerrainEstimateValidEv)
-*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
+*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sRK24estimator_status_flags_sR16failsafe_flags_sR6Report)
*(.text._ZN15EstimatorChecks29warnOfImminentPositionFailureER6ReportRKyRK25vehicle_global_position_sfRK16failsafe_flags_s)
*(.text._ZN11ControlMath11addIfNotNanERff)
*(.text._ZN9Commander21checkForMissionUpdateEv)
@@ -590,13 +590,13 @@
*(.text._ZN6BMP38813RegisterWriteEN12Bosch_BMP3888RegisterEh)
*(.text._ZN3GPS8callbackE15GPSCallbackTypePviS1_)
*(.text._ZN13AnalogBattery19get_current_channelEv)
-*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_s8NavModes)
+*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_sRK24estimator_status_flags_sRK14vehicle_gnss_s8NavModes)
*(.text._ZN15EstimatorChecks25checkInnovationsPreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
*(.text._ZN15EstimatorChecks34checkMagneticInterferencePreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
-*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_s)
+*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_sRK24estimator_status_flags_sRK14vehicle_gnss_s)
*(.text._ZN15EstimatorChecks22reportGnssFusionChangeERK7ContextR6Reportb)
*(.text._ZN15EstimatorChecks22reportGnssInterferenceER6Reportt)
-*(.text._ZN15EstimatorChecks30reportFailedGnssCheckPreflightER6ReportRK18estimator_status_sb)
+*(.text._ZN15EstimatorChecks19reportGnssPreflightER6Reportht)
*(.text._ZN12FailsafeBase11updateDelayERKy)
*(.text._ZN10FlightTask25_evaluateDistanceToGroundEv)
*(.text._ZN4EKF218PublishGnssHgtBiasERKy)
diff --git a/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld b/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld
index 4aae975a259..19ade195e1a 100644
--- a/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld
+++ b/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld
@@ -452,7 +452,7 @@
*(.text._ZN24ManualVelocitySmoothingZC1Ev) /* itcm-check-ignore */
*(.text._ZN3ADC6sampleEj)
*(.text._ZNK3Ekf22isTerrainEstimateValidEv)
-*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
+*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sRK24estimator_status_flags_sR16failsafe_flags_sR6Report)
*(.text._ZN15EstimatorChecks29warnOfImminentPositionFailureER6ReportRKyRK25vehicle_global_position_sfRK16failsafe_flags_s)
*(.text._ZN11ControlMath11addIfNotNanERff)
*(.text._ZN9Commander21checkForMissionUpdateEv)
@@ -589,13 +589,13 @@
*(.text._ZN6BMP38813RegisterWriteEN12Bosch_BMP3888RegisterEh)
*(.text._ZN3GPS8callbackE15GPSCallbackTypePviS1_)
*(.text._ZN13AnalogBattery19get_current_channelEv)
-*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_s8NavModes)
+*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_sRK24estimator_status_flags_sRK14vehicle_gnss_s8NavModes)
*(.text._ZN15EstimatorChecks25checkInnovationsPreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
*(.text._ZN15EstimatorChecks34checkMagneticInterferencePreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
-*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_s)
+*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_sRK24estimator_status_flags_sRK14vehicle_gnss_s)
*(.text._ZN15EstimatorChecks22reportGnssFusionChangeERK7ContextR6Reportb)
*(.text._ZN15EstimatorChecks22reportGnssInterferenceER6Reportt)
-*(.text._ZN15EstimatorChecks30reportFailedGnssCheckPreflightER6ReportRK18estimator_status_sb)
+*(.text._ZN15EstimatorChecks19reportGnssPreflightER6Reportht)
*(.text._ZN12FailsafeBase11updateDelayERKy)
*(.text._ZN10FlightTask25_evaluateDistanceToGroundEv)
*(.text._ZN4EKF218PublishGnssHgtBiasERKy)
diff --git a/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld b/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld
index cba31d50340..de0f98ebb95 100644
--- a/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld
+++ b/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld
@@ -459,7 +459,7 @@
*(.text._ZN24ManualVelocitySmoothingZC1Ev) /* itcm-check-ignore */
*(.text._ZN3ADC6sampleEj)
*(.text._ZNK3Ekf22isTerrainEstimateValidEv)
-*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
+*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sRK24estimator_status_flags_sR16failsafe_flags_sR6Report)
*(.text._ZN15EstimatorChecks29warnOfImminentPositionFailureER6ReportRKyRK25vehicle_global_position_sfRK16failsafe_flags_s)
*(.text._ZN11ControlMath11addIfNotNanERff)
*(.text._ZN9Commander21checkForMissionUpdateEv)
@@ -601,13 +601,13 @@
*(.text._ZN12SafetyButton3RunEv)
*(.text._ZN3GPS8callbackE15GPSCallbackTypePviS1_)
*(.text._ZN13AnalogBattery19get_current_channelEv)
-*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_s8NavModes)
+*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_sRK24estimator_status_flags_sRK14vehicle_gnss_s8NavModes)
*(.text._ZN15EstimatorChecks25checkInnovationsPreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
*(.text._ZN15EstimatorChecks34checkMagneticInterferencePreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
-*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_s)
+*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_sRK24estimator_status_flags_sRK14vehicle_gnss_s)
*(.text._ZN15EstimatorChecks22reportGnssFusionChangeERK7ContextR6Reportb)
*(.text._ZN15EstimatorChecks22reportGnssInterferenceER6Reportt)
-*(.text._ZN15EstimatorChecks30reportFailedGnssCheckPreflightER6ReportRK18estimator_status_sb)
+*(.text._ZN15EstimatorChecks19reportGnssPreflightER6Reportht)
*(.text._ZN12FailsafeBase11updateDelayERKy)
*(.text._ZN10FlightTask25_evaluateDistanceToGroundEv)
*(.text._ZN4EKF218PublishGnssHgtBiasERKy)
diff --git a/src/lib/events/enums.json b/src/lib/events/enums.json
index d2e97ec0781..93297673986 100644
--- a/src/lib/events/enums.json
+++ b/src/lib/events/enums.json
@@ -346,53 +346,53 @@
},
"gnss_check_fail_t": {
"type": "uint16_t",
- "description": "Bitfield of failing GNSS quality checks, the bit numbers of estimator_status.gps_check_fail_flags",
+ "description": "Bitfield of failing GNSS receiver checks, the bits of vehicle_gnss.failed_checks",
"is_bitfield": true,
"entries": {
"1": {
- "name": "fix",
- "description": "Fix too low"
- },
- "2": {
"name": "nsats",
"description": "Not enough satellites"
},
- "4": {
+ "2": {
"name": "pdop",
"description": "PDOP too high"
},
- "8": {
+ "4": {
"name": "hacc",
"description": "Horizontal position error too high"
},
- "16": {
+ "8": {
"name": "vacc",
"description": "Vertical position error too high"
},
- "32": {
+ "16": {
"name": "sacc",
"description": "Speed accuracy too low"
},
- "64": {
+ "32": {
"name": "hdrift",
"description": "Horizontal position drift too high"
},
- "128": {
+ "64": {
"name": "vdrift",
"description": "Vertical position drift too high"
},
- "256": {
+ "128": {
"name": "hspeed",
"description": "Horizontal speed drift too high"
},
- "512": {
+ "256": {
"name": "vspeed",
"description": "Vertical speed drift too high"
},
- "1024": {
+ "512": {
"name": "spoofed",
"description": "Signal spoofed"
},
+ "1024": {
+ "name": "fix",
+ "description": "Fix too low"
+ },
"2048": {
"name": "jammed",
"description": "Signal jammed"
diff --git a/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp b/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp
index 80787eef624..19e996be875 100644
--- a/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp
+++ b/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp
@@ -66,6 +66,10 @@ void EstimatorChecks::checkAndReport(const Context &context, Report &reporter)
bool missing_data = false;
const NavModes required_groups = (NavModes)reporter.failsafeFlags().mode_req_attitude;
+ // Without a report from the estimator, GNSS counts as not in use
+ estimator_status_flags_s estimator_status_flags{};
+ estimator_status_flags.gnss_fusion_state = estimator_status_flags_s::GNSS_FUSION_INACTIVE;
+
// Change topics to primary estimator instance
if (_param_sens_imu_mode.get() == 0) { // multi-ekf
estimator_selector_status_s estimator_selector_status;
@@ -85,13 +89,19 @@ void EstimatorChecks::checkAndReport(const Context &context, Report &reporter)
}
if (!missing_data) {
+ estimator_status_flags_s flags;
+
+ if (_estimator_status_flags_sub.copy(&flags) && (hrt_elapsed_time(&flags.timestamp) < kEstimatorStatusFlagsTimeout)) {
+ estimator_status_flags = flags;
+ }
+
estimator_status_s estimator_status;
if (_estimator_status_sub.copy(&estimator_status)) {
pre_flt_fail_innov_vel_horiz = estimator_status.pre_flt_fail_innov_vel_horiz;
pre_flt_fail_innov_pos_horiz = estimator_status.pre_flt_fail_innov_pos_horiz;
- checkEstimatorStatus(context, reporter, estimator_status, required_groups);
+ checkEstimatorStatus(context, reporter, estimator_status, estimator_status_flags, vehicle_gnss, required_groups);
checkEstimatorStatusFlags(context, reporter, estimator_status, lpos);
} else {
@@ -122,20 +132,21 @@ void EstimatorChecks::checkAndReport(const Context &context, Report &reporter)
// set mode requirements
setModeRequirementFlags(context, pre_flt_fail_innov_vel_horiz, pre_flt_fail_innov_pos_horiz, lpos,
- vehicle_gnss, reporter.failsafeFlags(), reporter);
+ vehicle_gnss, estimator_status_flags, reporter.failsafeFlags(), reporter);
lowPositionAccuracy(context, reporter, lpos);
}
void EstimatorChecks::checkEstimatorStatus(const Context &context, Report &reporter,
- const estimator_status_s &estimator_status, NavModes required_groups)
+ const estimator_status_s &estimator_status, const estimator_status_flags_s &estimator_status_flags,
+ const vehicle_gnss_s &vehicle_gnss, NavModes required_groups)
{
checkInnovationsPreflight(context, reporter, estimator_status, required_groups);
checkMagneticInterferencePreflight(context, reporter, estimator_status, required_groups);
// If GPS aiding is required, declare fault condition if the required GPS quality checks are failing
if (_param_sys_has_gps.get()) {
- checkGnssFusion(context, reporter, estimator_status);
+ checkGnssFusion(context, reporter, estimator_status, estimator_status_flags, vehicle_gnss);
}
}
@@ -252,30 +263,38 @@ void EstimatorChecks::checkMagneticInterferencePreflight(const Context &context,
}
}
-void EstimatorChecks::checkGnssFusion(const Context &context, Report &reporter, const estimator_status_s &estimator_status)
+void EstimatorChecks::checkGnssFusion(const Context &context, Report &reporter, const estimator_status_s &estimator_status,
+ const estimator_status_flags_s &estimator_status_flags, const vehicle_gnss_s &vehicle_gnss)
{
const bool gnss_fused = estimator_status.control_mode_flags & (1 << estimator_status_s::CS_GNSS_POS);
- // The flags describe only the newest sample, while EKF2 keeps rejecting samples for a while
- // after one failed and keeps fusing for longer still, so the check that kept GNSS out may
- // have passed again by the time the position goes. Each check is remembered for a while after
- // it last failed, on its own, so one that keeps failing doesn't keep the others alive.
+ // A sample is marked usable again only after its checks passed for a while, and the estimator, a sample delay
+ // behind, keeps fusing for longer still, so the check that kept GNSS out may have passed again by the time the
+ // position goes. Each check is remembered for a while after it last failed, on its own, so one that keeps failing
+ // doesn't keep the others alive.
for (int i = 0; i < kNumGnssChecks; i++) {
- if (estimator_status.gps_check_fail_flags & (1 << i)) {
- _last_gnss_check_fail_time_us[i] = estimator_status.timestamp;
+ if (vehicle_gnss.failed_checks & (1 << i)) {
+ _last_gnss_check_fail_time_us[i] = vehicle_gnss.timestamp;
}
}
+ // The receiver's checks are reported only while the estimator intends to use GNSS and has data. A receiver
+ // the estimator ignores must not block arming.
+ const uint8_t gnss_fusion_state = estimator_status_flags.gnss_fusion_state;
+ const bool gnss_checks_apply = (gnss_fusion_state != estimator_status_flags_s::GNSS_FUSION_INACTIVE)
+ && (gnss_fusion_state != estimator_status_flags_s::GNSS_FUSION_NO_DATA);
+ const uint16_t failed_checks = gnss_checks_apply ? vehicle_gnss.failed_checks : 0;
+
if (gnss_fused) {
reporter.setIsPresent(health_component_t::gps); // should be based on the sensor data directly
_last_gnss_fusion_time_us = hrt_absolute_time();
}
reportGnssFusionChange(context, reporter, gnss_fused);
- reportGnssInterference(reporter, estimator_status.gps_check_fail_flags);
+ reportGnssInterference(reporter, failed_checks);
- if (!context.isArmed() && (estimator_status.gps_check_fail_flags > 0)) {
- reportFailedGnssCheckPreflight(reporter, estimator_status, gnss_fused);
+ if (!context.isArmed()) {
+ reportGnssPreflight(reporter, gnss_fusion_state, failed_checks);
}
}
@@ -307,10 +326,10 @@ void EstimatorChecks::reportGnssFusionChange(const Context &context, Report &rep
_gps_was_fused = gnss_fused;
}
-void EstimatorChecks::reportGnssInterference(Report &reporter, uint16_t gps_check_fail_flags)
+void EstimatorChecks::reportGnssInterference(Report &reporter, uint16_t failed_checks)
{
// Each is reported once, when it starts
- const bool spoofed = gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_SPOOFED);
+ const bool spoofed = failed_checks & vehicle_gnss_s::CHECK_SPOOFED;
if (spoofed && !_gnss_spoofed) {
if (reporter.mavlink_log_pub()) {
@@ -323,7 +342,7 @@ void EstimatorChecks::reportGnssInterference(Report &reporter, uint16_t gps_chec
_gnss_spoofed = spoofed;
- const bool jammed = gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_JAMMED);
+ const bool jammed = failed_checks & vehicle_gnss_s::CHECK_JAMMED;
if (jammed && !_gnss_jammed) {
if (reporter.mavlink_log_pub()) {
@@ -337,9 +356,15 @@ void EstimatorChecks::reportGnssInterference(Report &reporter, uint16_t gps_chec
_gnss_jammed = jammed;
}
-void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const estimator_status_s &estimator_status,
- bool gnss_fused)
+void EstimatorChecks::reportGnssPreflight(Report &reporter, uint8_t gnss_fusion_state, uint16_t failed_checks)
{
+ const bool rejected = (gnss_fusion_state == estimator_status_flags_s::GNSS_FUSION_REJECTED)
+ || (gnss_fusion_state == estimator_status_flags_s::GNSS_FUSION_VEL_LIMIT);
+
+ if ((failed_checks == 0) && !rejected) {
+ return;
+ }
+
// What COM_ARM_WO_GPS makes of a failing check: the modes it blocks and how loudly it is reported
NavModesMessageFail required_modes;
events::Log log_level;
@@ -371,7 +396,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
// Only report the first failure to avoid spamming
const char *message = nullptr;
- if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_GPS_FIX)) {
+ if (failed_checks & vehicle_gnss_s::CHECK_FIX) {
message = "Preflight%s: GPS fix too low";
/* EVENT
* @description
@@ -383,7 +408,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_fix_too_low"),
log_level, "GPS fix too low");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_MIN_SAT_COUNT)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_NSATS) {
message = "Preflight%s: not enough GPS Satellites";
/* EVENT
* @description
@@ -395,7 +420,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_num_sats_too_low"),
log_level, "Not enough GPS Satellites");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_MAX_PDOP)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_PDOP) {
message = "Preflight%s: GPS PDOP too high";
/* EVENT
* @description
@@ -407,7 +432,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_pdop_too_high"),
log_level, "GPS PDOP too high");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_MAX_HORZ_ERR)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_EPH) {
message = "Preflight%s: GPS Horizontal Pos Error too high";
/* EVENT
* @description
@@ -419,7 +444,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_hor_pos_err_too_high"),
log_level, "GPS Horizontal Position Error too high");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_MAX_VERT_ERR)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_EPV) {
message = "Preflight%s: GPS Vertical Pos Error too high";
/* EVENT
* @description
@@ -431,7 +456,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_vert_pos_err_too_high"),
log_level, "GPS Vertical Position Error too high");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_MAX_SPD_ERR)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_SACC) {
message = "Preflight%s: GPS Speed Accuracy too low";
/* EVENT
* @description
@@ -443,7 +468,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_speed_acc_too_low"),
log_level, "GPS Speed Accuracy too low");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_MAX_HORZ_DRIFT)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_HDRIFT) {
message = "Preflight%s: GPS Horizontal Pos Drift too high";
/* EVENT
* @description
@@ -455,7 +480,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_hor_pos_drift_too_high"),
log_level, "GPS Horizontal Position Drift too high");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_MAX_VERT_DRIFT)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_VDRIFT) {
message = "Preflight%s: GPS Vertical Pos Drift too high";
/* EVENT
* @description
@@ -467,7 +492,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_vert_pos_drift_too_high"),
log_level, "GPS Vertical Position Drift too high");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_MAX_HORZ_SPD_ERR)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_HSPEED) {
message = "Preflight%s: GPS Hor Speed Drift too high";
/* EVENT
* @description
@@ -479,7 +504,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_hor_speed_drift_too_high"),
log_level, "GPS Horizontal Speed Drift too high");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_MAX_VERT_SPD_ERR)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_VSPEED) {
message = "Preflight%s: GPS Vert Speed Drift too high";
/* EVENT
* @description
@@ -491,7 +516,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_vert_speed_drift_too_high"),
log_level, "GPS Vertical Speed Drift too high");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_SPOOFED)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_SPOOFED) {
message = "Preflight%s: GPS signal spoofed";
/* EVENT
* @description
@@ -503,7 +528,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_spoofed"),
log_level, "GPS signal spoofed");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_JAMMED)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_JAMMED) {
message = "Preflight%s: GPS signal jammed";
/* EVENT
* @description
@@ -515,7 +540,7 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_jammed"),
log_level, "GPS signal jammed");
- } else if (estimator_status.gps_check_fail_flags & (1 << estimator_status_s::GPS_CHECK_FAIL_HKIN)) {
+ } else if (failed_checks & vehicle_gnss_s::CHECK_HKIN) {
message = "Preflight%s: GPS position inconsistent with velocity";
/* EVENT
* @description
@@ -529,10 +554,12 @@ void EstimatorChecks::reportFailedGnssCheckPreflight(Report &reporter, const est
events::ID("check_estimator_gps_hkin"),
log_level, "GPS position inconsistent with velocity");
- } else if (!gnss_fused) {
- // Likely cause unknown
+ } else if (rejected) {
message = "Preflight%s: Estimator not using GPS";
/* EVENT
+ * @description
+ * The receiver passes its checks, but the estimator rejects its samples: they disagree with the estimate,
+ * or report a velocity above EKF2_VEL_LIM.
*/
reporter.armingCheckFailure(required_modes, health_component_t::gps,
events::ID("check_estimator_gps_not_fusing"),
@@ -720,41 +747,70 @@ void EstimatorChecks::checkGnss(const Context &context, Report &reporter, const
}
void EstimatorChecks::reportGnssReasonForPositionLoss(const Context &context, Report &reporter,
- const hrt_abstime &now, const vehicle_gnss_s &vehicle_gnss) const
+ const hrt_abstime &now, const vehicle_gnss_s &vehicle_gnss, const estimator_status_flags_s &estimator_status_flags) const
{
- // In flight only, and only when GNSS was in use. Without GNSS in the loop neither a failing
- // receiver check nor a silent receiver says anything about why the estimate went.
+ // In flight only, and only when GNSS was in use. Without GNSS in the loop nothing about it explains why the
+ // estimate went.
if (!context.isArmed() || (now > _last_gnss_fusion_time_us + kGnssRecentlyFusedTimeout)) {
return;
}
- uint16_t failed_checks = 0;
+ const uint8_t receiver = vehicle_gnss.selected_instance;
+ const uint8_t state = estimator_status_flags.gnss_fusion_state;
- for (int i = 0; i < kNumGnssChecks; i++) {
- if ((_last_gnss_check_fail_time_us[i] != 0) && (now <= _last_gnss_check_fail_time_us[i] + kGnssRecentlyFusedTimeout)) {
- failed_checks |= 1 << i;
- }
- }
+ // The estimator declares a fault after rejecting the samples for too long
+ const bool rejected = (state == estimator_status_flags_s::GNSS_FUSION_REJECTED)
+ || ((state == estimator_status_flags_s::GNSS_FUSION_INACTIVE)
+ && (estimator_status_flags.cs_gnss_fault || estimator_status_flags.cs_gnss_hgt_fault));
- // EKF2 runs the checks only on new samples, so a receiver that stopped keeps the flags of
- // its last sample. The silence is the reason then, and it is tested first.
- if ((vehicle_gnss.timestamp == 0) || (now > vehicle_gnss.timestamp + kGnssDataTimeout)) {
+ if (state == estimator_status_flags_s::GNSS_FUSION_NO_DATA) {
/* EVENT
* @description
* The receiver had stopped delivering samples when the local position estimate became invalid.
*/
- events::send(events::ID("check_estimator_position_lost_gnss_no_data"), events::Log::Error,
- "Local position lost, no GNSS data");
+ events::send(events::ID("check_estimator_position_lost_gnss_no_data"), events::Log::Error,
+ "Local position lost, no data from GNSS {1}", receiver);
+
+ } else if (state == estimator_status_flags_s::GNSS_FUSION_UNUSABLE) {
+ uint16_t failed_checks = 0;
+
+ for (int i = 0; i < kNumGnssChecks; i++) {
+ if ((_last_gnss_check_fail_time_us[i] != 0) && (now <= _last_gnss_check_fail_time_us[i] + kGnssRecentlyFusedTimeout)) {
+ failed_checks |= 1 << i;
+ }
+ }
- } else if (failed_checks != 0) {
/* EVENT
* @description
- * The GNSS quality checks that failed in the run up to the local position estimate becoming invalid.
- * In flight EKF2 checks the fix type, the horizontal, vertical and speed accuracy, spoofing and jamming.
+ * The receiver checks that failed in the run up to the local position estimate becoming invalid.
+ * In flight they test the fix type, the horizontal, vertical and speed accuracy, spoofing and jamming.
+ *
+ *
+ * The checks are selected with GNSS_CHECK.
+ *
*/
- events::send(events::ID("check_estimator_position_lost_gnss_reason"),
- events::Log::Error, "Local position lost, GNSS check failed: {1}",
+ events::send(events::ID("check_estimator_position_lost_gnss_reason"),
+ events::Log::Error, "Local position lost, GNSS {1} check failed: {2}", receiver,
static_cast(failed_checks));
+
+ } else if (rejected) {
+ /* EVENT
+ * @description
+ * The receiver passed its checks, but its samples disagreed with the estimate, and the estimator could not
+ * reset to them while another source constrained the position.
+ */
+ events::send(events::ID("check_estimator_position_lost_gnss_rejected"), events::Log::Error,
+ "Local position lost, GNSS {1} rejected by the estimator", receiver);
+
+ } else if (state == estimator_status_flags_s::GNSS_FUSION_VEL_LIMIT) {
+ /* EVENT
+ * @description
+ *
+ * The receiver reported a velocity above EKF2_VEL_LIM.
+ *
+ */
+ events::send(events::ID("check_estimator_position_lost_gnss_vel_limit"), events::Log::Error,
+ "Local position lost, GNSS {1} velocity above the limit", receiver);
}
}
@@ -798,7 +854,7 @@ void EstimatorChecks::lowPositionAccuracy(const Context &context, Report &report
void EstimatorChecks::setModeRequirementFlags(const Context &context, bool pre_flt_fail_innov_vel_horiz,
bool pre_flt_fail_innov_pos_horiz, const vehicle_local_position_s &lpos, const vehicle_gnss_s &vehicle_gnss,
- failsafe_flags_s &failsafe_flags, Report &reporter)
+ const estimator_status_flags_s &estimator_status_flags, failsafe_flags_s &failsafe_flags, Report &reporter)
{
// The following flags correspond to mode requirements, and are reported in the corresponding mode checks
vehicle_global_position_s gpos;
@@ -849,7 +905,7 @@ void EstimatorChecks::setModeRequirementFlags(const Context &context, bool pre_f
_last_lpos_fail_time_us, !failsafe_flags.local_position_invalid);
if (local_position_was_valid && failsafe_flags.local_position_invalid) {
- reportGnssReasonForPositionLoss(context, reporter, now, vehicle_gnss);
+ reportGnssReasonForPositionLoss(context, reporter, now, vehicle_gnss, estimator_status_flags);
}
// In some modes we assume that the operator will compensate for the drift so we do not need to check the position error
diff --git a/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.hpp b/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.hpp
index 53c4359cb91..bbba0203a20 100644
--- a/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.hpp
+++ b/src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.hpp
@@ -74,15 +74,19 @@ private:
// The checks on the estimator status: the preflight innovation and magnetic interference checks, and
// what the estimator makes of GNSS
void checkEstimatorStatus(const Context &context, Report &reporter, const estimator_status_s &estimator_status,
+ const estimator_status_flags_s &estimator_status_flags, const vehicle_gnss_s &vehicle_gnss,
NavModes required_groups);
void checkInnovationsPreflight(const Context &context, Report &reporter, const estimator_status_s &estimator_status,
NavModes required_groups);
void checkMagneticInterferencePreflight(const Context &context, Report &reporter,
const estimator_status_s &estimator_status, NavModes required_groups);
- void checkGnssFusion(const Context &context, Report &reporter, const estimator_status_s &estimator_status);
+ void checkGnssFusion(const Context &context, Report &reporter, const estimator_status_s &estimator_status,
+ const estimator_status_flags_s &estimator_status_flags, const vehicle_gnss_s &vehicle_gnss);
void reportGnssFusionChange(const Context &context, Report &reporter, bool gnss_fused);
- void reportGnssInterference(Report &reporter, uint16_t gps_check_fail_flags);
- void reportFailedGnssCheckPreflight(Report &reporter, const estimator_status_s &estimator_status, bool gnss_fused);
+ void reportGnssInterference(Report &reporter, uint16_t failed_checks);
+
+ // The failing receiver check, or the estimator rejecting a receiver that passes them
+ void reportGnssPreflight(Report &reporter, uint8_t gnss_fusion_state, uint16_t failed_checks);
void checkSensorBias(const Context &context, Report &reporter, NavModes required_groups);
void checkEstimatorStatusFlags(const Context &context, Report &reporter, const estimator_status_s &estimator_status,
@@ -90,15 +94,15 @@ private:
void checkGnss(const Context &context, Report &reporter, const vehicle_gnss_s &vehicle_gnss) const;
void lowPositionAccuracy(const Context &context, Report &reporter, const vehicle_local_position_s &lpos) const;
- // Names the receiver that had stopped, or the GNSS quality checks that kept GNSS out, when the
- // local position estimate became invalid
+ // Why the estimator wasn't fusing GNSS when the local position estimate became invalid, naming the receiver
void reportGnssReasonForPositionLoss(const Context &context, Report &reporter, const hrt_abstime &now,
- const vehicle_gnss_s &vehicle_gnss) const;
+ const vehicle_gnss_s &vehicle_gnss, const estimator_status_flags_s &estimator_status_flags) const;
// The mode requirement flags, with the warning of an imminent position failure on its own
void setModeRequirementFlags(const Context &context, bool pre_flt_fail_innov_vel_horiz,
bool pre_flt_fail_innov_pos_horiz, const vehicle_local_position_s &lpos,
- const vehicle_gnss_s &vehicle_gnss, failsafe_flags_s &failsafe_flags, Report &reporter);
+ const vehicle_gnss_s &vehicle_gnss, const estimator_status_flags_s &estimator_status_flags,
+ failsafe_flags_s &failsafe_flags, Report &reporter);
void warnOfImminentPositionFailure(Report &reporter, const hrt_abstime &now, const vehicle_global_position_s &gpos,
float lpos_eph_threshold, const failsafe_flags_s &failsafe_flags);
@@ -128,16 +132,17 @@ private:
bool _gps_was_fused{false};
hrt_abstime _last_gnss_fusion_time_us{0};
- // when each GNSS quality check last failed, indexed by its bit in estimator_status.gps_check_fail_flags
- static constexpr int kNumGnssChecks = estimator_status_s::GPS_CHECK_FAIL_HKIN + 1;
+ // when each GNSS quality check last failed, indexed by its bit in vehicle_gnss.failed_checks
+ static constexpr int kNumGnssChecks = sizeof(vehicle_gnss_s::failed_checks) * 8;
hrt_abstime _last_gnss_check_fail_time_us[kNumGnssChecks] {};
+ // estimator_status_flags is published at least once a second
+ static constexpr hrt_abstime kEstimatorStatusFlagsTimeout = 5_s;
+
// how long after GNSS fusion stops, or after a receiver check last failed, that check is still taken as
// the reason for losing position
static constexpr hrt_abstime kGnssRecentlyFusedTimeout = 10_s;
- // a receiver whose last sample is older than this had stopped
- static constexpr hrt_abstime kGnssDataTimeout = 1_s;
bool _gnss_spoofed{false};
bool _gnss_jammed{false};
diff --git a/src/modules/commander/HealthAndArmingChecks/estimatorChecksTest.cpp b/src/modules/commander/HealthAndArmingChecks/estimatorChecksTest.cpp
index c51fa001a6b..cfc03c18887 100644
--- a/src/modules/commander/HealthAndArmingChecks/estimatorChecksTest.cpp
+++ b/src/modules/commander/HealthAndArmingChecks/estimatorChecksTest.cpp
@@ -88,11 +88,9 @@ public:
_failsafe_flags.mode_req_global_position = ~0u;
// the topics keep their last sample across cases, so each case starts from the same clean state
- publishEstimatorStatus(false, 0);
- estimator_status_flags_s flags{};
- flags.timestamp = hrt_absolute_time();
- flags.cs_yaw_align = true;
- publishStatusFlags(flags);
+ publishEstimatorStatus(false);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_FUSED);
+ publishReceiver(0);
estimator_sensor_bias_s bias{};
bias.timestamp = hrt_absolute_time();
publishSensorBias(bias);
@@ -120,19 +118,28 @@ public:
void publishAttitude(const vehicle_attitude_s &attitude) { _attitude_pub.publish(attitude); }
void publishAngularVelocity(const vehicle_angular_velocity_s &rates) { _angular_velocity_pub.publish(rates); }
- // what the estimator reports: whether it fuses GNSS position, and which receiver checks fail.
- // An age stands in for a report seen that long ago.
- void publishEstimatorStatus(bool gnss_fused, uint16_t gps_check_fail_flags, hrt_abstime age = 0)
+ // what the estimator reports: whether it fuses GNSS position
+ void publishEstimatorStatus(bool gnss_fused)
{
estimator_status_s status{};
- status.timestamp = hrt_absolute_time() - age;
+ status.timestamp = hrt_absolute_time();
status.control_mode_flags = gnss_fused ? (1ULL << estimator_status_s::CS_GNSS_POS) : 0;
- status.gps_check_fail_flags = gps_check_fail_flags;
_estimator_status_pub.publish(status);
}
- // the receiver's last sample, fresh or from before it went silent
- void publishReceiver(hrt_abstime age)
+ // why the estimator fuses the GNSS samples or not, and whether it declared GNSS faulty
+ void publishFusionState(uint8_t gnss_fusion_state, bool gnss_fault = false)
+ {
+ estimator_status_flags_s flags{};
+ flags.timestamp = hrt_absolute_time();
+ flags.cs_yaw_align = true;
+ flags.cs_gnss_fault = gnss_fault;
+ flags.gnss_fusion_state = gnss_fusion_state;
+ _status_flags_pub.publish(flags);
+ }
+
+ // the selected receiver's last sample, fresh or from before it went silent, with the checks it failed
+ void publishReceiver(hrt_abstime age, uint16_t failed_checks = 0, uint8_t instance = 0)
{
vehicle_gnss_s gnss{};
gnss.timestamp = hrt_absolute_time() - age;
@@ -141,6 +148,9 @@ public:
gnss.receiver.timestamp_sample = gnss.timestamp;
gnss.receiver.device_id = 1;
gnss.receiver.fix_type = 3;
+ gnss.selected_instance = instance;
+ gnss.usable = (failed_checks == 0);
+ gnss.failed_checks = failed_checks;
_receiver_pub.publish(gnss);
}
@@ -230,10 +240,22 @@ public:
_events.clear();
}
+ // the receiver named by an event, its first argument
+ static uint8_t eventReceiver(const event_s &event) { return event.arguments[0]; }
+
+ // the checks named by a reason event, after the receiver
+ static uint16_t eventChecks(const event_s &event)
+ {
+ uint16_t checks = 0;
+ memcpy(&checks, event.arguments + 1, sizeof(checks));
+ return checks;
+ }
+
// a vehicle flying on GNSS with a valid position and a live receiver, the starting point of every case
void flyOnGnss()
{
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_FUSED);
publishReceiver(0);
publishLocalPosition(true);
runCheck(true);
@@ -244,15 +266,17 @@ public:
static constexpr uint32_t kReasonEvent = events::ID("check_estimator_position_lost_gnss_reason");
static constexpr uint32_t kNoDataEvent = events::ID("check_estimator_position_lost_gnss_no_data");
+ static constexpr uint32_t kRejectedEvent = events::ID("check_estimator_position_lost_gnss_rejected");
+ static constexpr uint32_t kVelLimitEvent = events::ID("check_estimator_position_lost_gnss_vel_limit");
static constexpr uint32_t kFusionStartedEvent = events::ID("check_estimator_gnss_fusion_started");
static constexpr uint32_t kFusionStoppedEvent = events::ID("check_estimator_gnss_fusion_stopped");
static constexpr uint32_t kSpoofingEvent = events::ID("check_estimator_gnss_warning_spoofing");
static constexpr uint32_t kJammingEvent = events::ID("check_estimator_gnss_warning_jamming");
static constexpr uint32_t kFailureImminentEvent = events::ID("check_estimator_position_failure_imminent");
- static constexpr uint16_t kSpeedAccuracy = 1 << estimator_status_s::GPS_CHECK_FAIL_MAX_SPD_ERR;
- static constexpr uint16_t kSpoofed = 1 << estimator_status_s::GPS_CHECK_FAIL_SPOOFED;
- static constexpr uint16_t kJammed = 1 << estimator_status_s::GPS_CHECK_FAIL_JAMMED;
- static constexpr uint16_t kFixTooLow = 1 << estimator_status_s::GPS_CHECK_FAIL_GPS_FIX;
+ static constexpr uint16_t kSpeedAccuracy = vehicle_gnss_s::CHECK_SACC;
+ static constexpr uint16_t kSpoofed = vehicle_gnss_s::CHECK_SPOOFED;
+ static constexpr uint16_t kJammed = vehicle_gnss_s::CHECK_JAMMED;
+ static constexpr uint16_t kFixTooLow = vehicle_gnss_s::CHECK_FIX;
uORB::PublicationMulti _estimator_status_pub{ORB_ID(estimator_status)};
uORB::PublicationMulti _status_flags_pub{ORB_ID(estimator_status_flags)};
@@ -274,40 +298,39 @@ TEST_F(EstimatorChecksTest, NamesTheFailingCheckWhenPositionIsLostInFlight)
{
flyOnGnss();
- // the receiver's speed accuracy fails the in-flight check and the position estimate goes with it
- publishEstimatorStatus(true, kSpeedAccuracy);
+ // the receiver's speed accuracy fails the in-flight check, the estimator skips its samples, and the position
+ // estimate goes with it
+ publishReceiver(0, kSpeedAccuracy, 1);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_UNUSABLE);
publishLocalPosition(false);
runCheck(true);
ASSERT_TRUE(_failsafe_flags.local_position_invalid);
event_s event{};
- EXPECT_EQ(countEvents(kReasonEvent, &event), 1);
- uint16_t reported_flags = 0;
- memcpy(&reported_flags, event.arguments, sizeof(reported_flags));
- EXPECT_EQ(reported_flags, kSpeedAccuracy);
+ ASSERT_EQ(countEvents(kReasonEvent, &event), 1);
+ EXPECT_EQ(eventReceiver(event), 1);
+ EXPECT_EQ(eventChecks(event), kSpeedAccuracy);
}
TEST_F(EstimatorChecksTest, NamesACheckThatFailedShortlyBeforePositionWasLost)
{
flyOnGnss();
- // the check fails on one sample, passes again on the next, and the position goes a cycle later.
- // EKF2 was still rejecting samples from the failure, so it is the reason even though the newest
- // sample is clean.
- publishEstimatorStatus(true, kSpeedAccuracy);
- publishReceiver(0);
+ // the check fails on one sample and passes again on the next. The receiver's samples stay unusable for a while
+ // after the failure, so the estimator skips them and the position goes a cycle later: the failed check is the
+ // reason even though the newest sample passes.
+ publishReceiver(0, kSpeedAccuracy);
publishLocalPosition(true);
runCheck(true);
- publishEstimatorStatus(true, 0);
publishReceiver(0);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_UNUSABLE);
publishLocalPosition(true);
runCheck(true);
ASSERT_FALSE(_failsafe_flags.local_position_invalid);
drainEvents();
- publishEstimatorStatus(true, 0);
publishReceiver(0);
publishLocalPosition(false);
runCheck(true);
@@ -315,9 +338,7 @@ TEST_F(EstimatorChecksTest, NamesACheckThatFailedShortlyBeforePositionWasLost)
ASSERT_TRUE(_failsafe_flags.local_position_invalid);
event_s event{};
ASSERT_EQ(countEvents(kReasonEvent, &event), 1) << "the check that kept GNSS out is the reason";
- uint16_t reported_flags = 0;
- memcpy(&reported_flags, event.arguments, sizeof(reported_flags));
- EXPECT_EQ(reported_flags, kSpeedAccuracy);
+ EXPECT_EQ(eventChecks(event), kSpeedAccuracy);
}
TEST_F(EstimatorChecksTest, ForgetsACheckThatStoppedFailingLongBefore)
@@ -326,36 +347,36 @@ TEST_F(EstimatorChecksTest, ForgetsACheckThatStoppedFailingLongBefore)
// spoofing was flagged once, well before the speed accuracy failed and the position went. Each
// check expires on its own, so the speed accuracy failing doesn't keep the spoofing in the reason.
- publishEstimatorStatus(true, kSpoofed, 15_s);
+ publishReceiver(15_s, kSpoofed);
runCheck(true);
ASSERT_FALSE(_failsafe_flags.local_position_invalid);
drainEvents();
- publishEstimatorStatus(true, kSpeedAccuracy);
- publishReceiver(0);
+ publishReceiver(0, kSpeedAccuracy);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_UNUSABLE);
publishLocalPosition(false);
runCheck(true);
ASSERT_TRUE(_failsafe_flags.local_position_invalid);
event_s event{};
ASSERT_EQ(countEvents(kReasonEvent, &event), 1);
- uint16_t reported_flags = 0;
- memcpy(&reported_flags, event.arguments, sizeof(reported_flags));
- EXPECT_EQ(reported_flags, kSpeedAccuracy);
+ EXPECT_EQ(eventChecks(event), kSpeedAccuracy);
}
TEST_F(EstimatorChecksTest, ReportsOnceWhilePositionStaysLost)
{
flyOnGnss();
- publishEstimatorStatus(true, kSpeedAccuracy);
+ publishReceiver(0, kSpeedAccuracy);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_UNUSABLE);
publishLocalPosition(false);
runCheck(true);
ASSERT_EQ(countEvents(kReasonEvent), 1);
drainEvents();
for (int i = 0; i < 5; i++) {
- publishEstimatorStatus(false, kSpeedAccuracy);
+ publishEstimatorStatus(false);
+ publishReceiver(0, kSpeedAccuracy);
publishLocalPosition(false);
runCheck(true);
}
@@ -367,23 +388,21 @@ TEST_F(EstimatorChecksTest, EveryFailingCheckIsInTheEvent)
{
flyOnGnss();
- publishEstimatorStatus(true, kSpeedAccuracy | kSpoofed);
+ publishReceiver(0, kSpeedAccuracy | kSpoofed);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_UNUSABLE);
publishLocalPosition(false);
runCheck(true);
event_s event{};
ASSERT_EQ(countEvents(kReasonEvent, &event), 1);
- uint16_t reported_flags = 0;
- memcpy(&reported_flags, event.arguments, sizeof(reported_flags));
- EXPECT_EQ(reported_flags, kSpeedAccuracy | kSpoofed) << "the event carries every failing check";
+ EXPECT_EQ(eventChecks(event), kSpeedAccuracy | kSpoofed) << "the event carries every failing check";
}
-TEST_F(EstimatorChecksTest, NothingWhenNoCheckIsFailing)
+TEST_F(EstimatorChecksTest, NothingWhileGnssIsFused)
{
flyOnGnss();
- // position lost with the receiver alive and every check passing, so nothing gets blamed on GNSS
- publishEstimatorStatus(true, 0);
+ // position lost while the estimator fuses every sample, so nothing gets blamed on GNSS
publishReceiver(0);
publishLocalPosition(false);
runCheck(true);
@@ -391,20 +410,25 @@ TEST_F(EstimatorChecksTest, NothingWhenNoCheckIsFailing)
ASSERT_TRUE(_failsafe_flags.local_position_invalid);
EXPECT_EQ(countEvents(kReasonEvent), 0);
EXPECT_EQ(countEvents(kNoDataEvent), 0);
+ EXPECT_EQ(countEvents(kRejectedEvent), 0);
+ EXPECT_EQ(countEvents(kVelLimitEvent), 0);
}
TEST_F(EstimatorChecksTest, NamesTheReceiverThatStoppedSending)
{
flyOnGnss();
- // the receiver goes silent: no sample, so no check runs and no check bit is set
- publishEstimatorStatus(false, 0);
- publishReceiver(2_s);
+ // the receiver goes silent, and so does vehicle_gnss
+ publishEstimatorStatus(false);
+ publishReceiver(2_s, 0, 1);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_NO_DATA);
publishLocalPosition(false);
runCheck(true);
ASSERT_TRUE(_failsafe_flags.local_position_invalid);
- EXPECT_EQ(countEvents(kNoDataEvent), 1);
+ event_s event{};
+ ASSERT_EQ(countEvents(kNoDataEvent, &event), 1);
+ EXPECT_EQ(eventReceiver(event), 1);
EXPECT_EQ(countEvents(kReasonEvent), 0) << "a silent receiver is not a failing check";
}
@@ -412,10 +436,9 @@ TEST_F(EstimatorChecksTest, NamesTheReceiverThatStoppedAfterAFailingSample)
{
flyOnGnss();
- // the last sample before the receiver went quiet failed a check, and EKF2 keeps those flags
- // since no newer sample replaces them. The silence is still the reason.
- publishEstimatorStatus(true, kSpeedAccuracy);
- publishReceiver(2_s);
+ // the last sample before the receiver went quiet failed a check. The silence is still the reason.
+ publishReceiver(2_s, kSpeedAccuracy);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_NO_DATA);
publishLocalPosition(false);
runCheck(true);
@@ -424,11 +447,68 @@ TEST_F(EstimatorChecksTest, NamesTheReceiverThatStoppedAfterAFailingSample)
EXPECT_EQ(countEvents(kReasonEvent), 0) << "flags left by the last sample do not outrank the silence";
}
+TEST_F(EstimatorChecksTest, NamesAReceiverTheEstimatorRejects)
+{
+ flyOnGnss();
+
+ // the receiver passes its checks, but its samples disagree with the estimate
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_REJECTED);
+ publishLocalPosition(false);
+ runCheck(true);
+
+ ASSERT_TRUE(_failsafe_flags.local_position_invalid);
+ EXPECT_EQ(countEvents(kRejectedEvent), 1);
+ EXPECT_EQ(countEvents(kReasonEvent), 0);
+}
+
+TEST_F(EstimatorChecksTest, NamesAReceiverTheEstimatorDeclaredFaulty)
+{
+ flyOnGnss();
+
+ // after rejecting the samples for too long, the estimator declares GNSS faulty and stops using it
+ publishEstimatorStatus(false);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_INACTIVE, true);
+ publishLocalPosition(false);
+ runCheck(true);
+
+ ASSERT_TRUE(_failsafe_flags.local_position_invalid);
+ EXPECT_EQ(countEvents(kRejectedEvent), 1);
+}
+
+TEST_F(EstimatorChecksTest, NothingWhenGnssWasDisabled)
+{
+ flyOnGnss();
+
+ // GNSS is turned off in flight, then the position goes: that is not a GNSS failure
+ publishEstimatorStatus(false);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_INACTIVE);
+ publishLocalPosition(false);
+ runCheck(true);
+
+ ASSERT_TRUE(_failsafe_flags.local_position_invalid);
+ EXPECT_EQ(countEvents(kRejectedEvent), 0);
+ EXPECT_EQ(countEvents(kReasonEvent), 0);
+ EXPECT_EQ(countEvents(kNoDataEvent), 0);
+}
+
+TEST_F(EstimatorChecksTest, NamesTheVelocityLimit)
+{
+ flyOnGnss();
+
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_VEL_LIMIT);
+ publishLocalPosition(false);
+ runCheck(true);
+
+ ASSERT_TRUE(_failsafe_flags.local_position_invalid);
+ EXPECT_EQ(countEvents(kVelLimitEvent), 1);
+}
+
TEST_F(EstimatorChecksTest, NothingWhenGnssWasNotInUse)
{
// a vehicle with a valid position from another source, the receiver failing its checks all along
- publishEstimatorStatus(false, kSpeedAccuracy);
- publishReceiver(2_s);
+ publishEstimatorStatus(false);
+ publishReceiver(0, kSpeedAccuracy);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_UNUSABLE);
publishLocalPosition(true);
runCheck(true);
runCheck(true);
@@ -451,8 +531,8 @@ TEST_F(EstimatorChecksTest, NothingWithoutGnssConfigured)
flyOnGnss();
- publishEstimatorStatus(true, kSpeedAccuracy);
- publishReceiver(2_s);
+ publishReceiver(2_s, kSpeedAccuracy);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_NO_DATA);
publishLocalPosition(false);
runCheck(true);
@@ -463,7 +543,7 @@ TEST_F(EstimatorChecksTest, NothingWithoutGnssConfigured)
TEST_F(EstimatorChecksTest, NothingWhileDisarmed)
{
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
publishReceiver(0);
publishLocalPosition(true);
runCheck(false);
@@ -472,7 +552,8 @@ TEST_F(EstimatorChecksTest, NothingWhileDisarmed)
drainEvents();
// on the ground the preflight checks already name the failing check
- publishEstimatorStatus(true, kSpeedAccuracy);
+ publishReceiver(0, kSpeedAccuracy);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_UNUSABLE);
publishLocalPosition(false);
runCheck(false);
@@ -544,7 +625,7 @@ TEST_F(EstimatorChecksTest, GnssFusionStartAndStopAreReportedInFlight)
runCheck(true);
drainEvents();
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
runCheck(true);
EXPECT_EQ(countEvents(kFusionStartedEvent), 1);
@@ -552,7 +633,7 @@ TEST_F(EstimatorChecksTest, GnssFusionStartAndStopAreReportedInFlight)
EXPECT_EQ(countEvents(kFusionStartedEvent), 1) << "reported on the change, not every cycle";
event_s event{};
- publishEstimatorStatus(false, 0);
+ publishEstimatorStatus(false);
runCheck(true);
ASSERT_EQ(countEvents(kFusionStoppedEvent, &event), 1);
EXPECT_EQ(event.log_levels & 0x0f, (uint8_t)events::Log::Error) << "an error while the position estimate is still valid";
@@ -568,7 +649,7 @@ TEST_F(EstimatorChecksTest, GnssFusionStopIsOnlyInformationOncePositionIsLost)
drainEvents();
event_s event{};
- publishEstimatorStatus(false, 0);
+ publishEstimatorStatus(false);
runCheck(true);
ASSERT_EQ(countEvents(kFusionStoppedEvent, &event), 1);
EXPECT_EQ(event.log_levels & 0x0f, (uint8_t)events::Log::Info);
@@ -576,15 +657,15 @@ TEST_F(EstimatorChecksTest, GnssFusionStopIsOnlyInformationOncePositionIsLost)
TEST_F(EstimatorChecksTest, GnssFusionChangesAreNotReportedOnTheGround)
{
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
runCheck(false);
- publishEstimatorStatus(false, 0);
+ publishEstimatorStatus(false);
runCheck(false);
EXPECT_EQ(countEvents(kFusionStartedEvent), 0);
EXPECT_EQ(countEvents(kFusionStoppedEvent), 0);
// the state is still followed, so arming does not report a change that happened on the ground
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
runCheck(false);
runCheck(true);
EXPECT_EQ(countEvents(kFusionStartedEvent), 0);
@@ -592,30 +673,41 @@ TEST_F(EstimatorChecksTest, GnssFusionChangesAreNotReportedOnTheGround)
TEST_F(EstimatorChecksTest, SpoofingAndJammingAreReportedOnceUntilTheyClear)
{
- publishEstimatorStatus(true, kSpoofed);
+ publishEstimatorStatus(true);
+ publishReceiver(0, kSpoofed);
runCheck(false);
runCheck(false);
EXPECT_EQ(countEvents(kSpoofingEvent), 1);
- publishEstimatorStatus(true, 0);
+ publishReceiver(0);
runCheck(false);
- publishEstimatorStatus(true, kSpoofed);
+ publishReceiver(0, kSpoofed);
runCheck(false);
EXPECT_EQ(countEvents(kSpoofingEvent), 2) << "reported again once it cleared in between";
- publishEstimatorStatus(true, kJammed);
+ publishReceiver(0, kJammed);
runCheck(false);
runCheck(false);
EXPECT_EQ(countEvents(kJammingEvent), 1);
}
+TEST_F(EstimatorChecksTest, NoInterferenceReportWhileGnssIsNotInUse)
+{
+ // the estimator doesn't use GNSS, so a receiver reporting spoofing is not reported
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_INACTIVE);
+ publishReceiver(0, kSpoofed);
+ runCheck(false);
+ EXPECT_EQ(countEvents(kSpoofingEvent), 0);
+}
+
TEST_F(EstimatorChecksTest, AFailingGnssCheckBlocksArmingAsConfigured)
{
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
runCheck(false);
const uint64_t can_arm_with_good_gnss = _report.can_arm_mode_flags;
- publishEstimatorStatus(true, kFixTooLow);
+ publishReceiver(0, kFixTooLow);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_UNUSABLE);
setParam("COM_ARM_WO_GPS", 0); // deny arming
runCheck(false);
@@ -638,20 +730,55 @@ TEST_F(EstimatorChecksTest, AFailingGnssCheckBlocksArmingAsConfigured)
EXPECT_FALSE(armingError(health_component_t::gps)) << "the quality checks are only judged on the ground";
}
+TEST_F(EstimatorChecksTest, AReceiverTheEstimatorIgnoresDoesNotBlockArming)
+{
+ setParam("COM_ARM_WO_GPS", 0); // deny arming
+ publishReceiver(0, kFixTooLow);
+
+ // GNSS fusion disabled
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_INACTIVE);
+ runCheck(false);
+ EXPECT_FALSE(armingError(health_component_t::gps));
+
+ // the last sample of a receiver that stopped
+ publishReceiver(2_s, kFixTooLow);
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_NO_DATA);
+ runCheck(false);
+ EXPECT_FALSE(armingError(health_component_t::gps));
+}
+
+TEST_F(EstimatorChecksTest, ARejectedReceiverIsReportedBeforeArming)
+{
+ setParam("COM_ARM_WO_GPS", 0); // deny arming
+
+ // the receiver passes its checks, but the estimator rejects its samples
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_REJECTED);
+ runCheck(false);
+ EXPECT_TRUE(armingError(health_component_t::gps));
+
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_VEL_LIMIT);
+ runCheck(false);
+ EXPECT_TRUE(armingError(health_component_t::gps));
+
+ publishFusionState(estimator_status_flags_s::GNSS_FUSION_FUSED);
+ runCheck(false);
+ EXPECT_FALSE(armingError(health_component_t::gps));
+}
+
TEST_F(EstimatorChecksTest, GnssIsPresentWhileTheEstimatorFusesIt)
{
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
runCheck(false);
EXPECT_TRUE(isPresent(health_component_t::gps));
- publishEstimatorStatus(false, 0);
+ publishEstimatorStatus(false);
runCheck(false);
EXPECT_FALSE(isPresent(health_component_t::gps));
}
TEST_F(EstimatorChecksTest, HighSensorBiasBlocksArming)
{
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
estimator_sensor_bias_s bias{};
bias.timestamp = hrt_absolute_time();
@@ -683,7 +810,7 @@ TEST_F(EstimatorChecksTest, HighSensorBiasBlocksArming)
TEST_F(EstimatorChecksTest, CompassFaultBlocksEveryMode)
{
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
estimator_status_flags_s flags{};
flags.timestamp = hrt_absolute_time();
@@ -698,7 +825,7 @@ TEST_F(EstimatorChecksTest, CompassFaultBlocksEveryMode)
TEST_F(EstimatorChecksTest, NoHeadingReferenceBlocksArmingOnlyWithAGlobalOrigin)
{
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
estimator_status_flags_s flags{};
flags.timestamp = hrt_absolute_time();
@@ -719,7 +846,7 @@ TEST_F(EstimatorChecksTest, NoHeadingReferenceBlocksArmingOnlyWithAGlobalOrigin)
TEST_F(EstimatorChecksTest, PositionFailureImminentIsWarnedOnceWhileDeadReckoning)
{
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
publishLocalPosition(true);
// a global position that is still valid but whose error is close to COM_POS_FS_EPH
@@ -756,7 +883,7 @@ TEST_F(EstimatorChecksTest, LowPositionAccuracyIsFlaggedAndReportedInFlight)
{
setParam("COM_POS_LOW_EPH", 1.f);
setParam("COM_POS_LOW_ACT", 1);
- publishEstimatorStatus(true, 0);
+ publishEstimatorStatus(true);
publishLocalPosition(true, 2.f);
runCheck(true);