feat(sensors/gnss): report receiver switches

A switch moves the position the estimator sees, but nothing told the user it happened or why. The sensors module, which makes the selection and knows its reason, now sends one event per switch, as it does for its other sensor failovers.

Assisted-by: Claude:claude-opus-5-5
This commit is contained in:
Jacob Dahl authored and Jacob Dahl committed 2026-11-19 09:28:25 -09:00
1 parent 0ebe5ad7e4
commit 0085cfbe07
3 files changed
+62

No files matched your search

+34
View File
@@ -403,6 +403,40 @@
}
}
},
"gnss_selection_reason_t": {
"type": "uint8_t",
"description": "Why the sensors module selected a GNSS receiver, the values of vehicle_gnss.selection_reason",
"entries": {
"0": {
"name": "preferred",
"description": "Preferred receiver"
},
"1": {
"name": "only",
"description": "Only receiver"
},
"2": {
"name": "ranked",
"description": "No receiver ranks higher"
},
"3": {
"name": "timeout",
"description": "Previous receiver stopped publishing"
},
"4": {
"name": "unhealthy",
"description": "Previous receiver failed its checks or was late"
},
"5": {
"name": "requirements",
"description": "Meets the accuracy requirements, the previous receiver didn't"
},
"6": {
"name": "rtk_fixed",
"description": "RTK fixed, the previous receiver wasn't"
}
}
},
"arming_state_t": {
"type": "uint8_t",
"description": "State of the main arming state machine",
@@ -274,8 +274,13 @@ void VehicleGPSPosition::Run()
gnss_output.timestamp = hrt_absolute_time();
_vehicle_gnss_pub.publish(gnss_output);
if ((_published_instance >= 0) && (gnss_output.selection_count != _published_selection_count)) {
reportSwitch(_published_instance, selected, gnss_output.selection_reason);
}
_selected_device_id = gnss_output.receiver.device_id;
_published_instance = selected;
_published_selection_count = gnss_output.selection_count;
}
PublishStatus();
@@ -529,6 +534,25 @@ void VehicleGPSPosition::PublishStatus()
_sensors_status_gnss_pub.publish(status);
}
void VehicleGPSPosition::reportSwitch(int previous, int selected, uint8_t reason) const
{
// A failed receiver is a warning; a return to the preferred or a more accurate receiver is not
const bool failure = (reason == vehicle_gnss_s::SELECTION_TIMEOUT) || (reason == vehicle_gnss_s::SELECTION_UNHEALTHY);
/* EVENT
* @description
* The estimator uses the new receiver from now on.
*
* <profile name="dev">
* Set a preferred receiver with <param>SENS_GNSS_PRIME</param>.
* </profile>
*/
events::send<uint8_t, events::px4::enums::gnss_selection_reason_t, uint8_t>(events::ID("gnss_receiver_switched"),
{failure ? events::Log::Warning : events::Log::Info, events::LogInternal::Info},
"Switched from GNSS {3} to GNSS {1}: {2}", static_cast<uint8_t>(selected),
static_cast<events::px4::enums::gnss_selection_reason_t>(reason), static_cast<uint8_t>(previous));
}
matrix::Vector3f VehicleGPSPosition::antennaOffset(int instance) const
{
const GpsParamSlot *slot = findParamSlot(_latest_sample[instance].device_id, instance);
@@ -83,6 +83,9 @@ private:
void UpdateVehicleState();
void PublishStatus();
// One event per change of the receiver that vehicle_gnss carries
void reportSwitch(int previous, int selected, uint8_t reason) const;
// define max number of GPS receivers supported
static constexpr int GPS_MAX_RECEIVERS = 2;
static_assert(GPS_MAX_RECEIVERS == GnssSelector::GNSS_MAX_RECEIVERS,
@@ -179,6 +182,7 @@ private:
sensor_gnss_s _latest_sample[GPS_MAX_RECEIVERS] {}; ///< timestamp_sample corrected, timestamp 0 until it publishes
uint32_t _selected_device_id{0};
int8_t _published_instance{-1}; ///< receiver of the last vehicle_gnss sample, -1 before the first one
uint8_t _published_selection_count{0};
int8_t _preferred_instance{-1};
uint8_t _first_publication[GPS_MAX_RECEIVERS] {}; ///< 1 for the first receiver to publish, 2 for the next, 0 before
uint8_t _receivers_published{0};