Managing Variance (horiz_accuracy)
The Blue Circle is Math
When you look at Google Maps on your phone, you see a blue dot (your position) surrounded by a light blue circle. That circle represents the Horizontal Accuracy (68% confidence interval). To the casual user, it means "I am somewhere in this circle." To the Extended Kalman Filter (EKF), it is a critical statistical weight that defines the Observation Noise Covariance.
MAVLink GPS passes this radius (in meters) directly to ArduPilot via the horiz_accuracy field in the GPS_INPUT message.
The Kalman Gain Equation
The EKF3 is constantly arbitrating a debate between two sensors:
- The IMU (Prediction): "I felt us accelerate forward at $2 m/s^2$, so we must be at position $x_{k|k-1}$."
- The GPS (Observation): "I see us at position $z_k$."
The arbiter of this debate is the Kalman Gain ($K_k$). The simplified equation for the gain is:
$$ K_k = \frac{P_{k|k-1} H^T}{H P_{k|k-1} H^T + R_k} $$
Where:
- $P_{k|k-1}$: The Error Covariance of the IMU prediction (How much we trust the gyro/accel).
- $R_k$: The Measurement Noise Covariance (How much we trust the GPS).
The horiz_accuracy value from your phone drives $R_k$ directly.
- Small Accuracy Circle (e.g., 2m): $R_k$ is small. The denominator decreases. $K_k$ approaches 1. The EKF trusts the GPS.
- Large Accuracy Circle (e.g., 20m): $R_k$ is large. The denominator increases. $K_k$ approaches 0. The EKF trusts the IMU.
Flight Behavior & Tuning
Understanding this math explains the "feel" of the drone in flight.
Scenario A: High Confidence ($R_k \downarrow$)
- Environment: Open atrium, glass roof, clear line of sight to APs.
- Phone Report:
horiz_accuracy = 1.5m. - Flight Feel: "Tight." The drone locks into position. However, if the GPS solution "jumps" by 1 meter due to a reflection, the drone will jerk 1 meter to match it because $K_k$ is high.
Scenario B: Low Confidence ($R_k \uparrow$)
- Environment: Concrete hallway, sparse WiFi.
- Phone Report:
horiz_accuracy = 15.0m. - Flight Feel: "Loose" or "Drifty." The drone resists rapid position corrections. It relies heavily on the IMU integration. It is smoother, but it may drift 1-2 meters before the GPS "pulls" it back.
Practical "How To": Synthetic Tuning
If you are developing a custom MAVLink application, you can "hack" the flight feel by manipulating the horiz_accuracy before sending it to the drone.
-
The Clamp Strategy: If you want smoother flight and trust your optical flow more than your network location, mathematically inflate the reported accuracy:
$$ \text{ReportedAcc} = \max(\text{RealAcc}, 5.0) $$
This forces the EKF to treat the position as a "soft suggestion" rather than a hard truth. -
The Lock Strategy: If you are hovering over a charging pad and need precision, you might artificially clamp the accuracy down to 1.0m (dangerously trusting the signal) to force the EKF to converge tightly. Use with caution.
The Safety Gate
ArduPilot has a hard limit to prevent EKF blowouts.
- Threshold: If
horiz_accuracy > 5.0m(default), the EKF declares a GPS Glitch or prevents Arming (PreArm: GPS Horiz Accuracy). - Indoor Implication: If your phone reports 10m accuracy indoors, you might not be able to arm, even if the position looks stable on the map. This is a safety feature to prevent fly-aways when the "Circle of Confusion" is larger than the room you are flying in.
Source Code Reference
- Observation Noise:
libraries/AP_NavEKF3/AP_NavEKF3_PosVelFusion.cpp- Usessq(gpsPosAccuracy). - Safety Check:
libraries/AP_NavEKF3/AP_NavEKF3_VehicleStatus.cpp- The 5.0m check.