MAVLINKHUD

GPS Glitch Protection

Executive Summary

GPS is imperfect. Multipath errors (signals bouncing off buildings) can cause the GPS reported position to jump 10 meters instantly. If the flight controller trusted this blindly, the drone would violently roll to "correct" its position, crashing into the obstacle. Glitch Protection allows the EKF to reject these sudden jumps and transition to inertial flight (Dead Reckoning) until the GPS stabilizes.

Theory & Concepts

1. Multipath Interference

The biggest cause of GPS glitches is Multipath. This happens when the satellite signal bounces off a building or the ground before reaching the antenna.

  • The Physics: Radio waves travel at the speed of light. If the signal bounces, it travels a longer path.
  • The Error: The GPS receiver thinks the satellite is further away than it is. This shifts the calculated position.
  • The Glitch: As you fly past the building, the bounce angle changes, causing the position to "jump."

2. Time-of-Flight vs. Inertial Certainty

The EKF knows exactly how much force the drone is applying (via IMU). If the GPS says the drone moved 10m East, but the IMU says we only accelerated by 0.1G, the EKF knows the GPS is lying. It trusts its Inertial Certainty over the "Glitched" GPS time-of-flight.

Detection Architecture (Engineer's View)

The EKF3 detection logic in SelectVelPosFusion() is a two-layer defense.

1. The Innovation Check (Immediate Defense)

  • Concept: "Physics says you can't teleport."
  • Mechanism: The EKF compares the GPS Measurement against the IMU-based Prediction.
  • Trigger: If the difference (Innovation) exceeds the gate (EK3_POS_I_GATE, default 5 sigma), the measurement is flagged as invalid.
  • Result: The GPS data is completely ignored for that frame. The EKF relies 100% on the IMU (Dead Reckoning).

2. The Glitch Radius (Long-Term Defense)

What if the GPS drifts slowly (sub-gate) but persistently? Or what if the IMU drifts?

  • Parameter: EK3_GLITCH_RAD (default 25m).
  • Concept: "I might be wrong, but I'm not that wrong."
  • Mechanism: If the estimated uncertainty (Variance) of the EKF's position grows larger than EK3_GLITCH_RAD, the EKF admits defeat.
  • Result: It performs a Position Reset, snapping its internal state to the GPS coordinate. This prevents the "Runaway Drone" scenario where the EKF thinks it is right and the GPS is wrong forever.

Dead Reckoning

When a Glitch is detected, the drone enters Dead Reckoning.

  • Behavior: It uses the Accelerometers to calculate velocity and position.
  • Duration: High-quality IMUs (like in the Cube) can maintain position accuracy for 10-30 seconds. Cheap IMUs drift faster.
  • Wind: Without GPS, the drone cannot estimate wind. It assumes the last known wind vector is constant.

Key Parameters

Parameter Default Description
EK3_POS_I_GATE 500 (5 sigma) The threshold for rejecting a position jump. Lower = Stricter (safer against glitches, but risks rejecting good data during 10G turns).
EK3_GLITCH_RAD 25 (m) The maximum "Trust Bubble" the EKF will build around itself. If the GPS is outside this bubble for too long, the EKF resets.

Source Code Reference

Practical Guide: The AltHold Rescue

If you see "EKF Variance" or "GPS Glitch" on your HUD, your drone is confused.

The Problem

  • Mode: Loiter (GPS).
  • Situation: The drone starts leaning 20 degrees sideways, but the HUD says it is perfectly flat and stationary.
  • Diagnosis: The GPS has drifted (multipath). The EKF thinks the world moved, so it is leaning to "hold position" against a phantom movement.

The Fix

  1. Switch to AltHold: Immediately.
    • Why? AltHold ignores GPS. It uses the Barometer (Z) and the Gyro (Pitch/Roll).
    • Result: The drone will level out instantly. It will drift with the wind, but it will stop fighting the ghost GPS data.
  2. Wait: Let the GPS stabilize (usually takes 10-30 seconds).
  3. Check HUD: When the "EKF" status turns Red to White, you can switch back to Loiter.