[RFC] Replace GNSS blending with receiver selection and per-receiver checks
Summary
This RFC proposes a new design for how PX4 turns GNSS receiver data into the position and velocity that EKF2 fuses. It matters most for vehicles with two receivers, such as dual RTK, or a moving base and rover for heading.
The proposal makes the following changes:
- The sensors module selects one receiver instead of blending two. You set a preferred receiver, and the sensors module switches to another receiver only when the preferred one fails.
- The sensors module runs the GNSS quality checks once per receiver. Today EKF2 runs them on the blended output, in every EKF instance.
- Each sample that EKF2 receives carries its own check result, so EKF2 fuses exactly the samples that passed.
- Commander and the logs show which receiver the vehicle uses and why GNSS was lost.
- GNSS messages, topics, and parameters use
gnssinstead ofgps.
A prerequisite, moving dual-antenna heading to its own topic, is in review as #27102 refactor(ekf2): separate GNSS heading from position into independent topic.
Background notes: GNSS selection, fusion, and heading covers the case against blending in detail, and GNSS pipeline migration is the execution plan.
Terms
- Receiver: one GNSS receiver. Its driver publishes it as one
sensor_gpsinstance. - Sensors module:
src/modules/sensors. It publishesvehicle_gps_positionfrom thesensor_gpsinstances. - Blending: the weighted average of two receivers that the sensors module publishes when
SENS_GPS_MASKis non-zero. The default is 7, so blending is on. - Moving base and rover: a receiver pair that measures heading. The moving base sends corrections to the rover, and the rover reports the baseline between the two antennas.
- Preferred receiver: the receiver that
SENS_GPS_PRIMEnames. - Selected receiver: the receiver that the vehicle navigates on.
Problems
Blending hides receiver faults
Blending weights each receiver by the accuracy that the receiver reports. When the weights change, the output doesn't step; it slews toward the new weighted mean over SENS_GPS_TAU (10 s). An RTK fixed-to-float transition on one receiver therefore becomes slow drift, slow enough to pass EKF2's innovation checks, so EKF2 follows the drift instead of rejecting it.
Blending also has these side effects:
- The output reports the better accuracy and fix type of the two receivers, while the worse receiver still contributes to the position.
- When the receivers run at different rates, the output runs at the slower rate.
- The output's
device_idis 0, so logs and the GCS can't tell which receiver the vehicle used. - The jamming and spoofing flags come from only one receiver.
Blending became the default in #19907 Enable GPS Blending by default, mainly to keep heading working on DroneCAN moving-base setups. The heading prerequisite removes that dependency.
GNSS checks run in the wrong place
EKF2's GnssChecks decides whether a sample is good enough to fuse. It uses only the sample and the vehicle's armed, in-air, and at-rest state, not the EKF state. Today it runs:
- on the blended output instead of on each receiver,
- in every EKF instance, and every instance computes the same result,
- at the EKF's delayed time horizon.
Other code repeats parts of this logic with its own thresholds: GpsBlending, commander's gnssRedundancyCheck, and several of the roughly 30 consumers of vehicle_gps_position, which test the fix type themselves.
Users don't learn why GNSS was lost
#24355 [Bug] GPS failure, notify user shows the gap. In a v1.15 log attached there, the RTK stream stopped and the horizontal accuracy rose above EKF2_REQ_EPH. EKF2 stopped fusing GNSS, local position became invalid, and the vehicle switched to blind land. The failsafe message gave no reason. The only GNSS message, "GNSS data fusion stopped", arrived 2 s later at Info level.
#24909 [EKF2] Run simplified GNSS checks after initial fix relaxed the in-flight thresholds in v1.17, so the same conditions no longer stop GNSS fusion on main. The reporting gap remains: apart from jamming and spoofing, commander reports GNSS check failures only before arming.
Telemetry and the estimator disagree
Since #27868 fix(mavlink): select GPS_RAW_INT/GPS2_RAW instance via SENS_GPS_PRIME, GPS_RAW_INT shows the preferred receiver, while EKF2 fuses the blend.
Proposal
The following diagram shows the proposed data flow:
flowchart LR
drivers["GNSS drivers"]
subgraph sensors["sensors module"]
checks["GnssChecks<br/>one per receiver"] --> selector["SensorGnssSelector"]
heading["Heading selection"]
end
ekf2["EKF2<br/>every instance"]
commander["commander"]
mavlink["MAVLink"]
drivers -- "sensor_gnss" --> checks
drivers -- "sensor_gnss_relative" --> heading
selector -- "vehicle_gnss" --> ekf2
heading -- "vehicle_gnss_heading" --> ekf2
checks -- "sensors_status_gnss" --> commander
ekf2 -- "gnss_fusion_state" --> commander
drivers -- "sensor_gnss" --> mavlinkvehicle_gnss carries the selected receiver's sample and its check result. sensors_status_gnss carries the health and check diagnostics of every receiver.
Select one receiver instead of blending
The sensors module selects one receiver and publishes its data unchanged:
SENS_GNSS_PRIMEnames the preferred receiver, by instance or DroneCAN node ID. The sensors module selects it while it passes its checks.- The sensors module switches receivers only when the selected receiver fails its checks for a set time or stops publishing, and only to a receiver that passes its checks. It returns to the preferred receiver with hysteresis. While the vehicle is armed, only a failure causes a switch.
SENS_GNSS_PRIME = -1ranks the receivers, for setups with no natural preference such as dual independent RTK. The ranking uses horizontal and vertical accuracy, update rate, and latency. Fix type and satellite count don't compare well across receivers.- For a moving base and rover, make the moving base the preferred receiver. It has a higher rate and lower latency than the rover, and it reaches RTK accuracy when a fixed base sends it corrections. The rover often reports a better fix type, but it is the worse position source.
A switch causes a real step in position: an RTK receiver reports positions in the frame of its correction source, and receivers compute altitude above mean sea level with different geoid models. When the selected receiver changes, EKF2 therefore resets its horizontal position, and its height if it fuses GNSS height, to the new receiver and publishes the reset through its reset counters.
Run the checks once per receiver
GnssChecks moves to src/lib/gnss. The sensors module runs one instance per receiver, with the same behavior as today:
- Strict thresholds apply until the receiver first passes, and again whenever the vehicle is disarmed on the ground.
- Relaxed thresholds apply after arming.
A receiver that has never passed stays on the strict thresholds, so a standby receiver must meet them before the sensors module selects it. The thresholds move with the checks: EKF2_GPS_CHECK and EKF2_REQ_* become GNSS_CHECK and GNSS_REQ_*.
EKF2 keeps the checks that depend on the estimator: innovation gating, fusion timeouts, and the EKF2_VEL_LIM sample limit. The hold-off after EKF2 stops GNSS fusion, today a reset of GnssChecks, becomes a timer on the usable flag in each EKF instance. The sensors module publishes vehicle_gnss_heading only from a receiver that passes its own checks, so heading is gated by its own receiver instead of the position receiver.
Put the check result on the sample
A new VehicleGnss message replaces vehicle_gps_position as the sensors module's output. It nests the selected receiver's SensorGnss sample unchanged and adds the values that the sensors module computes:
- the measurement time, corrected for the receiver's delay or by PPS
- the antenna position of the selected receiver
- the selection state: selected instance, reason, and a counter that increments on every switch
- the check result:
usableand the failed checks
EKF2 fuses a sample only if the sample's usable flag is set. A separate status topic can't gate fusion reliably: it describes the newest sample, which runs ahead of the sample that EKF2 fuses by the GNSS delay plus the EKF buffer. With the result on the sample, the gate is exact, and EKF2 replay reproduces it.
This follows the other sensor paths, where vehicle_imu, vehicle_air_data, and vehicle_magnetometer each have their own message type instead of reusing the driver message.
Report receiver health and GNSS loss
The proposal changes reporting as follows:
sensors_status_gnssreports each receiver's health and check diagnostics: failed checks, whether strict thresholds apply, drift rates and filtered speed. It also carries the horizontal distance of each receiver to the selected one, which commander's divergence check reads. It has its ownSensorsStatusGnssmessage, as IMUs haveSensorsStatusImu, because the diagnostics don't fit the genericSensorsStatus.- EKF2 publishes
gnss_fusion_stateonestimator_status_flags: whether it fused the latest sample, and if not, why. - Commander reports the failed checks of each receiver before arming. When local position becomes invalid, commander sends one event with the reason.
GPS_RAW_INTandGPS2_RAWstay on fixed receivers for the whole session: the preferred receiver, or instance 0 withSENS_GNSS_PRIME = -1, and the other one. Commander reports each switch as an event. Per-receiver GNSS messages wait for mavlink/mavlink#2146 development.xml: add GNSS message.- Consumers that depend on GNSS quality, such as home position, use the
usableflag instead of their own fix-type checks.
Rename gps to gnss
The following table lists the renames. Parameters migrate through param_translation.
| Current | Proposed |
|---|---|
SensorGps.msg, sensor_gps |
SensorGnss.msg, sensor_gnss |
vehicle_gps_position |
vehicle_gnss, with the new VehicleGnss message |
Field names with units, such as latitude_deg and s_variance_m_s |
Field names without units, such as latitude and speed_accuracy |
SENS_GPS_PRIME, SENS_GPSn_* |
SENS_GNSS_PRIME, SENS_GNSSn_* |
EKF2_GPS_CHECK, EKF2_REQ_*, EKF2_REQ_GPS_H |
GNSS_CHECK, GNSS_REQ_*, GNSS_REQ_TIME |
Driver parameters (GPS_*) keep their names. The field names come from #24399 Update SensorGps.msg to improve naming, and #16999 Proposal: Rename GPS(unspecitied) word to GNSS proposed the rename in 2021.
Compatibility
This proposal changes behavior and interfaces:
- Blending off by default.
SENS_GPS_MASKdefaults to 0 right after #27102, which removes blending's role in keeping heading available. PX4 warns if a non-zero value is set.SENS_GPS_MASKandSENS_GPS_TAUare removed one release after selection lands. - Parameters.
param_translationmigrates saved parameters and airframe files. QGroundControl parameter files that use the old names don't restore those parameters. - ROS 2.
/fmu/out/vehicle_gps_positionbecomes/fmu/out/vehicle_gnss.SensorGpsisn't a versioned message, so the translation node can't bridge the change. - Logs. Log tools such as Flight Review, pyulog scripts, and PlotJuggler layouts must read both the old and the new names.
- Open PRs. Open PRs that publish or subscribe to
sensor_gpsneed a rebase.
Rollout
The work lands in this order:
- Heading moves to its own topic, in #27102 refactor(ekf2): separate GNSS heading from position into independent topic.
SENS_GPS_MASKdefaults to 0 right after it. - The rename lands, with
VehicleGnssas the sensors module output. Behavior doesn't change. Every consumer, ROS 2 user, and log tool migrates once. GnssChecksmoves tosrc/lib/gnss, and the sensors module runs one per receiver and reports them onsensors_status_gnss. EKF2 still runs its own checks, so behavior doesn't change. In #28520 feat(sensors): Move gnss checks to vehicle_gps_position file.- Selection replaces blending, using the per-receiver check result, in #28798 feat(sensors/gps): Improve GPS selection.
- The check result moves onto the sample, EKF2 stops running
GnssChecks, and the reporting changes land. - Blending is removed, one release after step 4.
Steps 2 and 3 are independent. The rename goes early so that later work uses the final names. Selection comes before step 5 so that the sensors module never computes a check result for a blended output.
Alternatives considered
- Keep blending and fix its bugs. The drift comes from the blending design, not from a bug that a fix could remove. Co-located receivers also share most of their error sources, so averaging them improves accuracy little.
- Rank receivers by fix type and satellite count. On a moving base and rover, the rover reports a better fix type but is the worse position source.
- Publish the check results on a separate status topic that EKF2 gates on, as #28520 first did. The status runs ahead of the sample that EKF2 fuses, so EKF2 has to check each sample again.
- Run the checks in the drivers. Every driver would need them, and DroneCAN receivers would run them in node firmware, away from the vehicle's configuration.
- Run one EKF instance per receiver (
EKF2_MULTI_GPS). This isolates a faulty receiver completely, but costs memory and CPU for each instance. It can build on this proposal later.
Future work
- Reconfigure a promoted rover. When the sensors module selects the rover of a moving-base pair, the rover can switch to standard mode: disable its correction input and reset its position solution. The rover then recovers in 1–2 s instead of navigating on data that goes about 900 ms stale when corrections degrade. #25516 Concept: Separate GNSS position and heading topics describes this, and aviant-tech/PX4-Autopilot#104 Dual F9P for yaw with proper redundancy behaviour implements it.
- One EKF instance per receiver, as described under alternatives.
- Ellipsoid height on a switch. EKF2 fuses altitude above mean sea level, so a switch between receivers with different geoid models steps the height. Fusing ellipsoid height would remove the step.
- Per-receiver innovation checks. Comparing each receiver against the EKF state would show which receiver is wrong when two disagree, at the cost of a feedback loop from EKF2 into selection.
- ROS 2 versioning of
VehicleGnss. Versioning it also versions the nestedSensorGnss, so every driver message change would need a translation.
Prototype messages
SensorGnss.msg, renamed from SensorGps.msg# GNSS receiver report
#
# One instance per receiver, published by its driver: the receiver's own solution, unmodified.
# The sensors module publishes the selected receiver on vehicle_gnss.
uint64 timestamp # [us] Time since system start
uint64 timestamp_sample # [us] Measurement time if the driver knows it, else 0. vehicle_gnss carries the corrected value
uint32 device_id # [-] Unique device ID for the sensor that does not change between power cycles
float64 latitude # [deg] Latitude, allows centimeter level RTK precision
float64 longitude # [deg] Longitude, allows centimeter level RTK precision
float64 altitude_msl # [m] Altitude above MSL, from the receiver's own geoid model
float64 altitude_ellipsoid # [m] Altitude above the ellipsoid
float32 speed_accuracy # [m/s] Speed accuracy estimate
float32 course_accuracy # [rad] Course accuracy estimate
uint8 fix_type # [@enum FIX_TYPE] Value 0 is also valid to represent no fix
uint8 FIX_TYPE_NONE = 1
uint8 FIX_TYPE_2D = 2
uint8 FIX_TYPE_3D = 3
uint8 FIX_TYPE_RTCM_CODE_DIFFERENTIAL = 4
uint8 FIX_TYPE_RTK_FLOAT = 5
uint8 FIX_TYPE_RTK_FIXED = 6
uint8 FIX_TYPE_EXTRAPOLATED = 8
float32 eph # [m] Horizontal position accuracy
float32 epv # [m] Vertical position accuracy
float32 hdop # [-] Horizontal dilution of precision
float32 vdop # [-] Vertical dilution of precision
int32 noise # [-] Noise level per millisecond
uint16 automatic_gain_control # [-] Automatic gain control monitor
uint8 jamming_state # [@enum JAMMING_STATE]
uint8 JAMMING_STATE_UNKNOWN = 0
uint8 JAMMING_STATE_OK = 1
uint8 JAMMING_STATE_MITIGATED = 2
uint8 JAMMING_STATE_DETECTED = 3
int32 jamming_indicator # [-] Jamming indicator
uint8 spoofing_state # [@enum SPOOFING_STATE]
uint8 SPOOFING_STATE_UNKNOWN = 0
uint8 SPOOFING_STATE_OK = 1
uint8 SPOOFING_STATE_MITIGATED = 2
uint8 SPOOFING_STATE_DETECTED = 3
uint8 authentication_state # [@enum AUTHENTICATION_STATE] Combined signal authentication state (e.g. Galileo OSNMA)
uint8 AUTHENTICATION_STATE_UNKNOWN = 0
uint8 AUTHENTICATION_STATE_INITIALIZING = 1
uint8 AUTHENTICATION_STATE_ERROR = 2
uint8 AUTHENTICATION_STATE_OK = 3
uint8 AUTHENTICATION_STATE_DISABLED = 4
float32 ground_speed # [m/s] Ground speed
float32 vel_north # [m/s] North velocity
float32 vel_east # [m/s] East velocity
float32 vel_down # [m/s] Down velocity
float32 course # [rad] [@range -PI, PI] Course over ground, not heading
bool vel_ned_valid # NED velocity is valid
int32 timestamp_time_relative # [us] timestamp + timestamp_time_relative = time of the UTC timestamp since system start
uint64 time_utc_usec # [us] UTC time from the receiver, 0 until known
uint8 satellites_used # [-] Satellites used in the solution
uint32 system_error # [@enum SYSTEM_ERROR] Bitmask of receiver errors
uint32 SYSTEM_ERROR_OK = 0
uint32 SYSTEM_ERROR_INCOMING_CORRECTIONS = 1
uint32 SYSTEM_ERROR_CONFIGURATION = 2
uint32 SYSTEM_ERROR_SOFTWARE = 4
uint32 SYSTEM_ERROR_ANTENNA = 8
uint32 SYSTEM_ERROR_EVENT_CONGESTION = 16
uint32 SYSTEM_ERROR_CPU_OVERLOAD = 32
uint32 SYSTEM_ERROR_OUTPUT_CONGESTION = 64
float32 heading # [rad] [@range -PI, PI] [@invalid NaN] Measured dual-antenna baseline heading, for receivers without sensor_gnss_relative. Use vehicle_gnss_heading, rotated by SENS_GNSSn_ROT
float32 heading_accuracy # [rad] Heading accuracy
float32 rtcm_injection_rate # [Hz] Correction injection rate
uint8 selected_rtcm_instance # [-] uORB instance used for corrections
uint8 corrections_protocol # [@enum CORRECTIONS_PROTOCOL] Protocol of the last correction message the receiver parsed
uint8 CORRECTIONS_PROTOCOL_UNKNOWN = 0
uint8 CORRECTIONS_PROTOCOL_RTCM3 = 1
uint8 CORRECTIONS_PROTOCOL_SPARTN = 2
uint8 CORRECTIONS_PROTOCOL_HAS = 3 # Galileo High Accuracy Service, received on E6
uint8 CORRECTIONS_PROTOCOL_PMP = 4 # SPARTN over L-band (u-blox NEO-D9S)
uint8 CORRECTIONS_PROTOCOSource: PX4/PX4-Autopilot