Skip to content

Commit 3365e34

Browse files
committed
refactor(gpsRedundancyCheck): address code review feedback
1 parent a98b6d2 commit 3365e34

File tree

7 files changed

+62
-62
lines changed

7 files changed

+62
-62
lines changed

msg/FailsafeFlags.msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ bool flight_time_limit_exceeded # Maximum flight time exceeded
5959
bool position_accuracy_low # Position estimate has dropped below threshold, but is currently still declared valid
6060
bool navigator_failure # Navigator failed to execute a mode
6161
bool parachute_unhealthy # Parachute system missing or unhealthy
62-
bool gps_redundancy_lost # Number of active GPS receivers dropped below COM_GPS_MIN
62+
bool gnss_lost # Active GNSS count dropped below SYS_HAS_NUM_GNSS, or two receivers report inconsistent positions

src/lib/systemlib/system_params.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,17 @@ parameters:
136136
type: boolean
137137
default: 1
138138
reboot_required: true
139-
SYS_HAS_NUM_GPS:
139+
SYS_HAS_NUM_GNSS:
140140
description:
141-
short: Control if and how many GPS receivers are expected
141+
short: Control if and how many GNSS receivers are expected
142142
long: |-
143-
0: Disable GPS redundancy check (any number of GPS is acceptable).
144-
1-N: Require the presence of N GPS receivers for arming and during flight.
143+
0: Disable GNSS redundancy check (any number of GNSS receivers is acceptable).
144+
1-N: Require the presence of N GNSS receivers for arming and during flight.
145145
If the active count drops below this value in flight, COM_GPS_LOSS_ACT is triggered.
146146
type: int32
147147
default: 0
148148
min: 0
149149
max: 2
150-
reboot_required: false
151150
SYS_HAS_MAG:
152151
description:
153152
short: Control if and how many magnetometers are expected

src/modules/commander/HealthAndArmingChecks/GpsRedundancyCheckTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class GpsRedundancyCheckTest : public ::testing::Test
8989
f = 0.f;
9090
param_set(param_find("SENS_GPS1_OFFY"), &f);
9191
int i = 0;
92-
param_set(param_find("SYS_HAS_NUM_GPS"), &i);
92+
param_set(param_find("SYS_HAS_NUM_GNSS"), &i);
9393
param_set(param_find("COM_GPS_LOSS_ACT"), &i);
9494

9595
// Construct check after params are set so ParamFloat reads correct initial values

src/modules/commander/HealthAndArmingChecks/checks/gpsRedundancyCheck.cpp

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ using namespace time_literals;
4040
// eph is firmware-dependent and not a rigorous 1-sigma, so 3 is a heuristic consistency gate
4141
// rather than a precise statistical claim. It relaxes the gate automatically when receivers degrade.
4242
static constexpr float GPS_DIVERGENCE_SIGMA = 3.0f;
43-
static constexpr uint64_t GPS_DIVERGENCE_SUSTAIN = 2_s; // must be sustained before warning
43+
44+
// Matches the 1 s staleness threshold used by other sensor checks in this framework.
45+
static constexpr uint64_t GNSS_ONLINE_TIMEOUT = 1_s;
46+
47+
// Multipath spikes typically resolve within 1 s; 2 s filters these out while still
48+
// detecting real receiver faults promptly.
49+
static constexpr uint64_t GNSS_DIVERGENCE_SUSTAIN = 2_s;
4450

4551
void GpsRedundancyChecks::checkAndReport(const Context &context, Report &reporter)
4652
{
4753
// Always reset — will be set below only when the condition is active
48-
reporter.failsafeFlags().gps_redundancy_lost = false;
54+
reporter.failsafeFlags().gnss_lost = false;
4955

5056
// Separate "online" (present + fresh data) from "fixed" (online + 3D fix).
5157
// online_count tracks receivers that are communicating; fixed_count tracks those
@@ -60,7 +66,7 @@ void GpsRedundancyChecks::checkAndReport(const Context &context, Report &reporte
6066

6167
if (_sensor_gps_sub[i].copy(&gps)
6268
&& (gps.device_id != 0)
63-
&& (hrt_elapsed_time(&gps.timestamp) < 2_s)) {
69+
&& (hrt_elapsed_time(&gps.timestamp) < GNSS_ONLINE_TIMEOUT)) {
6470
online_count++;
6571

6672
if (gps.fix_type >= 3) {
@@ -92,7 +98,7 @@ void GpsRedundancyChecks::checkAndReport(const Context &context, Report &reporte
9298

9399
// Pre-arm: trigger immediately so the operator can decide before takeoff.
94100
// In-flight: require sustained divergence to avoid false alarms from transient multipath.
95-
const uint64_t sustain = context.isArmed() ? GPS_DIVERGENCE_SUSTAIN : 0_s;
101+
const uint64_t sustain = context.isArmed() ? GNSS_DIVERGENCE_SUSTAIN : 0_s;
96102

97103
if (divergence_m > gate_m) {
98104
if (_divergence_since == 0) {
@@ -124,58 +130,52 @@ void GpsRedundancyChecks::checkAndReport(const Context &context, Report &reporte
124130
}
125131
}
126132

127-
// Track the highest fixed count seen — used to detect any GPS loss regardless of SYS_HAS_NUM_GPS
133+
// Track the highest fixed count seen — used to detect any GPS loss regardless of SYS_HAS_NUM_GNSS
128134
if (fixed_count > _peak_fixed_count) {
129135
_peak_fixed_count = fixed_count;
130136
}
131137

132-
const int required = _param_sys_has_num_gps.get();
138+
const int required = _param_sys_has_num_gnss.get();
133139
const bool below_required = (required > 0 && fixed_count < required);
134140
const bool dropped_below_peak = (_peak_fixed_count > 1 && fixed_count < _peak_fixed_count);
135141

136-
if (!below_required && !dropped_below_peak && !divergence_active) {
137-
return;
138-
}
139-
140-
reporter.failsafeFlags().gps_redundancy_lost = below_required || divergence_active;
142+
reporter.failsafeFlags().gnss_lost = below_required || divergence_active;
143+
144+
if (below_required || dropped_below_peak) {
145+
// act==0: warn only, never blocks arming; act>0: blocks arming and shows red
146+
const bool block_arming = below_required && (_param_com_gps_loss_act.get() > 0);
147+
const NavModes nav_modes = block_arming ? NavModes::All : NavModes::None;
148+
const events::Log log_level = block_arming ? events::Log::Error : events::Log::Warning;
149+
const uint8_t expected = below_required ? (uint8_t)required : (uint8_t)_peak_fixed_count;
150+
151+
// Differentiate: if online_count is also low the receiver is offline; otherwise it lost fix.
152+
if (online_count < fixed_count || online_count < required) {
153+
/* EVENT
154+
* @description
155+
* <profile name="dev">
156+
* Configure the minimum required GPS count with <param>SYS_HAS_NUM_GNSS</param>.
157+
* Configure the failsafe action with <param>COM_GPS_LOSS_ACT</param>.
158+
* </profile>
159+
*/
160+
reporter.healthFailure<uint8_t, uint8_t>(nav_modes, health_component_t::gps,
161+
events::ID("check_gps_redundancy_offline"),
162+
log_level,
163+
"GPS receiver offline: {1} of {2} online",
164+
(uint8_t)online_count, expected);
141165

142-
if (!below_required && !dropped_below_peak) {
143-
return;
144-
}
145-
146-
// act==0: warn only, never blocks arming; act>0: blocks arming and shows red
147-
const bool block_arming = below_required && (_param_com_gps_loss_act.get() > 0);
148-
const NavModes nav_modes = block_arming ? NavModes::All : NavModes::None;
149-
const events::Log log_level = block_arming ? events::Log::Error : events::Log::Warning;
150-
const uint8_t expected = below_required ? (uint8_t)required : (uint8_t)_peak_fixed_count;
151-
152-
// Differentiate: if online_count is also low the receiver is offline; otherwise it lost fix.
153-
if (online_count < fixed_count || online_count < required) {
154-
/* EVENT
155-
* @description
156-
* <profile name="dev">
157-
* Configure the minimum required GPS count with <param>SYS_HAS_NUM_GPS</param>.
158-
* Configure the failsafe action with <param>COM_GPS_LOSS_ACT</param>.
159-
* </profile>
160-
*/
161-
reporter.healthFailure<uint8_t, uint8_t>(nav_modes, health_component_t::gps,
162-
events::ID("check_gps_redundancy_offline"),
163-
log_level,
164-
"GPS receiver offline: {1} of {2} online",
165-
(uint8_t)online_count, expected);
166-
167-
} else {
168-
/* EVENT
169-
* @description
170-
* <profile name="dev">
171-
* Configure the minimum required GPS count with <param>SYS_HAS_NUM_GPS</param>.
172-
* Configure the failsafe action with <param>COM_GPS_LOSS_ACT</param>.
173-
* </profile>
174-
*/
175-
reporter.healthFailure<uint8_t, uint8_t>(nav_modes, health_component_t::gps,
176-
events::ID("check_gps_redundancy_no_fix"),
177-
log_level,
178-
"GPS receiver lost 3D fix: {1} of {2} fixed",
179-
(uint8_t)fixed_count, expected);
166+
} else {
167+
/* EVENT
168+
* @description
169+
* <profile name="dev">
170+
* Configure the minimum required GPS count with <param>SYS_HAS_NUM_GNSS</param>.
171+
* Configure the failsafe action with <param>COM_GPS_LOSS_ACT</param>.
172+
* </profile>
173+
*/
174+
reporter.healthFailure<uint8_t, uint8_t>(nav_modes, health_component_t::gps,
175+
events::ID("check_gps_redundancy_no_fix"),
176+
log_level,
177+
"GPS receiver lost 3D fix: {1} of {2} fixed",
178+
(uint8_t)fixed_count, expected);
179+
}
180180
}
181181
}

src/modules/commander/HealthAndArmingChecks/checks/gpsRedundancyCheck.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (c) 2024 PX4 Development Team. All rights reserved.
3+
* Copyright (c) 2026 PX4 Development Team. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -56,7 +56,7 @@ class GpsRedundancyChecks : public HealthAndArmingCheckBase
5656
hrt_abstime _divergence_since{0};
5757

5858
DEFINE_PARAMETERS_CUSTOM_PARENT(HealthAndArmingCheckBase,
59-
(ParamInt<px4::params::SYS_HAS_NUM_GPS>) _param_sys_has_num_gps,
59+
(ParamInt<px4::params::SYS_HAS_NUM_GNSS>) _param_sys_has_num_gnss,
6060
(ParamInt<px4::params::COM_GPS_LOSS_ACT>) _param_com_gps_loss_act,
6161
(ParamFloat<px4::params::SENS_GPS0_OFFX>) _param_gps0_offx,
6262
(ParamFloat<px4::params::SENS_GPS0_OFFY>) _param_gps0_offy,

src/modules/commander/commander_params.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ parameters:
133133
default: 1
134134
COM_GPS_LOSS_ACT:
135135
description:
136-
short: GPS redundancy loss failsafe mode
136+
short: GPS loss failsafe mode
137137
long: |-
138-
Action the system takes when the number of active GPS receivers drops
139-
below SYS_HAS_NUM_GPS during flight.
138+
Action the system takes when a GNSS failure is detected during flight.
139+
Triggers when the active GNSS count drops below SYS_HAS_NUM_GNSS or when
140+
two receivers report positions inconsistent with their reported accuracy.
140141
type: enum
141142
values:
142143
0: Warning

src/modules/commander/failsafe/failsafe.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ void Failsafe::checkStateAndMode(const hrt_abstime &time_us, const State &state,
664664

665665
CHECK_FAILSAFE(status_flags, fd_imbalanced_prop, fromImbalancedPropActParam(_param_com_imb_prop_act.get()));
666666
CHECK_FAILSAFE(status_flags, fd_motor_failure, fromActuatorFailureActParam(_param_com_actuator_failure_act.get()));
667-
CHECK_FAILSAFE(status_flags, gps_redundancy_lost, fromGpsRedundancyActParam(_param_com_gps_loss_act.get()));
667+
CHECK_FAILSAFE(status_flags, gnss_lost, fromGpsRedundancyActParam(_param_com_gps_loss_act.get()));
668668

669669

670670

0 commit comments

Comments
 (0)