diff --git a/msg/SensorsStatusGnss.msg b/msg/SensorsStatusGnss.msg index a2d66d81c76..2d581b7bb58 100644 --- a/msg/SensorsStatusGnss.msg +++ b/msg/SensorsStatusGnss.msg @@ -5,6 +5,7 @@ uint64 timestamp # [us] Time since system start uint32 device_id_selected # [-] Receiver that vehicle_gnss carries +bool primary_offline # A primary receiver is configured and is not publishing uint8 MAX_RECEIVERS = 4 # Length of the per-receiver arrays diff --git a/src/modules/commander/HealthAndArmingChecks/checks/gnssRedundancyCheck.cpp b/src/modules/commander/HealthAndArmingChecks/checks/gnssRedundancyCheck.cpp index 7f892722087..8ae19184878 100644 --- a/src/modules/commander/HealthAndArmingChecks/checks/gnssRedundancyCheck.cpp +++ b/src/modules/commander/HealthAndArmingChecks/checks/gnssRedundancyCheck.cpp @@ -182,4 +182,19 @@ void GnssRedundancyChecks::checkAndReport(const Context &context, Report &report "GPS receivers disagree by {1:.1}m horizontally, {2:.1}m vertically", _divergence_h_m, _divergence_v_m); } + + // The selection falls back to another receiver, so like any other receiver the primary blocks arming only when + // SYS_HAS_NUM_GNSS counts it + if (!context.isArmed() && status_valid && status.primary_offline) { + /* EVENT + * @description + * Another receiver, if any, is used until the primary one publishes. + * + * + * The primary receiver is set with SENS_GNSS_PRIME, or is the moving base of a moving base pair. + * + */ + reporter.armingCheckFailure(NavModes::None, health_component_t::gps, events::ID("check_gnss_primary_offline"), + events::Log::Warning, "Primary GNSS receiver offline"); + } } diff --git a/src/modules/commander/HealthAndArmingChecks/gnssRedundancyChecksTest.cpp b/src/modules/commander/HealthAndArmingChecks/gnssRedundancyChecksTest.cpp index 56b345ab7d6..2a349b94cc3 100644 --- a/src/modules/commander/HealthAndArmingChecks/gnssRedundancyChecksTest.cpp +++ b/src/modules/commander/HealthAndArmingChecks/gnssRedundancyChecksTest.cpp @@ -141,6 +141,9 @@ public: // Capture any GPS health issue regardless of log level (Warning or Error). _health_warning_gps = (reporter.healthResults().warning | reporter.healthResults().error) & health_component_t::gps; _can_arm_all_modes = reporter.armingCheckResults().can_arm == NavModes::All; + _arming_warning_gps = reporter.armingCheckResults().warning & health_component_t::gps; + _arming_error_gps = reporter.armingCheckResults().error & health_component_t::gps; + _can_arm = reporter.armingCheckResults().can_arm; } // The receivers report the given disagreement past the hysteresis time @@ -161,6 +164,9 @@ public: failsafe_flags_s _failsafe_flags{}; bool _health_warning_gps{false}; bool _can_arm_all_modes{false}; + bool _arming_warning_gps{false}; + bool _arming_error_gps{false}; + NavModes _can_arm{NavModes::None}; GnssRedundancyChecks _check; }; @@ -492,3 +498,24 @@ TEST_F(GnssRedundancyChecksTest, StaleStatusDoesNotCount) runCheck(); EXPECT_TRUE(_failsafe_flags.gnss_lost); } + +// A configured primary receiver that is not publishing is a warning before arming, not a reason to refuse it. +TEST_F(GnssRedundancyChecksTest, PrimaryOfflineWarnsBeforeArming) +{ + publishGnss(1); + runCheck(); + ASSERT_FALSE(_arming_warning_gps); + const NavModes can_arm = _can_arm; + + _status.primary_offline = true; + publishGnss(1); + runCheck(); + EXPECT_TRUE(_arming_warning_gps); + EXPECT_FALSE(_arming_error_gps); + EXPECT_EQ(_can_arm, can_arm); + EXPECT_FALSE(_failsafe_flags.gnss_lost); + + // in flight the switch away from it is reported instead + runCheck(true); + EXPECT_FALSE(_arming_warning_gps); +} diff --git a/src/modules/sensors/vehicle_gps_position/VehicleGPSPosition.cpp b/src/modules/sensors/vehicle_gps_position/VehicleGPSPosition.cpp index bf0e13cb8a3..5c69d0527e5 100644 --- a/src/modules/sensors/vehicle_gps_position/VehicleGPSPosition.cpp +++ b/src/modules/sensors/vehicle_gps_position/VehicleGPSPosition.cpp @@ -289,6 +289,10 @@ void VehicleGPSPosition::Run() // A receiver that stopped publishing still has to time out and lose availability when no other one publishes _gnss_selector.update(hrt_absolute_time()); PublishStatus(); + + } else if (hasConfiguredPreference()) { + // A configured primary is reported offline even when no receiver ever published + PublishStatus(); } #if defined(CONFIG_SENSORS_VEHICLE_GNSS_HEADING) @@ -505,6 +509,11 @@ void VehicleGPSPosition::PublishStatus() const matrix::Quatf attitude_q = (compare && _vehicle_attitude_sub.copy(&attitude)) ? matrix::Quatf(attitude.q) : matrix::Quatf(); + if (hasConfiguredPreference()) { + const int primary = resolvePreferredInstance(); + status.primary_offline = (primary < 0) || !publishing[primary]; + } + for (int i = 0; i < GPS_MAX_RECEIVERS; i++) { const GnssChecks &checks = _gnss_checks[i]; const sensor_gnss_s &sample = _latest_sample[i];