Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Ardupilot/ardupilot/llms.txt
Use this file to discover all available pages before exploring further.
NavEKF3 (Extended Kalman Filter, version 3) is the primary navigation filter in ArduPilot. It fuses data from the IMU, GPS, barometer, compass, airspeed sensor, optical flow, rangefinder, and external navigation systems to produce continuous estimates of vehicle attitude, velocity, position, wind velocity, and magnetic field. All navigation modes — position hold, waypoint following, auto-landing — ultimately depend on the outputs of this filter. The older NavEKF2 remains available as a fallback but NavEKF3 is enabled by default.
What the EKF estimates
EKF3 maintains a 24-element state vector updated at approximately 83 Hz (everyEKF_TARGET_DT = 0.012 s). The states cover:
Attitude
Velocity
Position
Gyro and accel bias
Wind velocity
Magnetic field
EKF3 vs EKF2
NavEKF3 supersedes NavEKF2 and should be used for all new vehicles. Key differences:
| Feature | EKF2 | EKF3 |
|---|---|---|
| Number of IMU lanes | 1 | Up to MAX_EKF_CORES (controlled by EK3_IMU_MASK) |
| Lane switching | No | Yes — automatic and manual |
| Source sets | No | Yes — up to 3 switchable source sets |
| GSF yaw estimator | No | Yes — independent yaw fallback |
| Drag model | No | Yes — for multirotors with EK3_DRAG_* |
| Default | Previously default | Primary default since ArduPilot 4.1 |
EK3_ENABLE 1 (default). Disable EKF2 by setting EK2_ENABLE 0 to save memory on constrained hardware.
Sensor fusion inputs
EKF3 accepts data from a wide range of sensors. The active source for horizontal position, velocity, and yaw is configured through the source set system (EK3_SRC*_* parameters).
GPS / GNSS
GPS / GNSS
EK3_GPS_CHECK bitmask.Barometer
Barometer
EK3_ALT_SOURCE parameter selects alternatives such as rangefinder or GPS altitude. Baro noise is modelled by EK3_ALT_M_NSE.Compass / magnetometer
Compass / magnetometer
EK3_MAG_MASK), and automatic in-flight calibration. The filter detects magnetic anomalies and resets yaw using the EKFGSF estimator when needed.Optical flow
Optical flow
EK3_FLOW_USE. The filter compensates for vehicle angular rates using the IMU gyro.Rangefinder
Rangefinder
EK3_RNG_USE_HGT, the filter blends from baro to rangefinder below a configurable height threshold and speed limit.External navigation (visual odometry, mocap)
External navigation (visual odometry, mocap)
Airspeed
Airspeed
Key output methods
All outputs are accessed through theNavEKF3 instance held by AP_AHRS. In most ArduPilot code you interact with EKF3 through AP::ahrs(), but the methods below are available directly on the NavEKF3 object when lower-level access is needed.
getRotationBodyToNED() — attitude matrix
getRotationBodyToNED() — attitude matrix
getEulerAngles() — roll, pitch, yaw
getEulerAngles() — roll, pitch, yaw
getRotationBodyToNED() to avoid singularities at ±90° pitch.getPosNE() and getPosD() — NED position
getPosNE() and getPosD() — NED position
false if the solution is not valid enough for flight control — always check the return value.getVelNED() — NED velocity
getVelNED() — NED velocity
getWind() — wind velocity
getWind() — wind velocity
false if wind estimation is not active (requires airspeed sensor or sideslip fusion).getMagNED() and getMagXYZ() — magnetic field
getMagNED() and getMagXYZ() — magnetic field
getMagNED) and body-frame (getMagXYZ) magnetic field vectors in units of milligauss / 1000. Used for in-flight compass calibration feedback.getGyroBias() and getAccelBias()
getGyroBias() and getAccelBias()
-1 for the primary core. These values are logged and can be used to diagnose IMU quality.getInnovations() — sensor residuals
getInnovations() — sensor residuals
getVariances() — innovation consistency ratios
getVariances() — innovation consistency ratios
healthy() and getFilterStatus()
healthy() and getFilterStatus()
healthy() returns a consolidated pass/fail for the primary core. getFilterStatus() populates a detailed bitmask that reports individual flags such as attitude initialised, using GPS, velocity drift, etc. This bitmask is sent to the GCS as EKF_STATUS_REPORT.Lane switching
EKF3 can run multiple independent prediction cores simultaneously, each using a different IMU (controlled byEK3_IMU_MASK). This is called a “lane”. Each lane accumulates a relative error score based on its innovation consistency. When a lane’s score becomes significantly better than the current primary, the filter automatically switches lanes.
AP_AHRS so that vehicle position does not suddenly change from the flight controller’s perspective.EK3_OPTIONS bit 1 (ManualLaneSwitch) disables automatic switching and requires explicit commands — useful for testing individual IMU performance.
Innovation testing and failsafe integration
EKF3 performs chi-squared innovation consistency checks on every sensor measurement before fusing it. The test gate widths (in standard deviations) are tunable:| Parameter | Sensor |
|---|---|
EK3_VEL_I_GATE | GPS velocity |
EK3_POS_I_GATE | GPS position |
EK3_HGT_I_GATE | Barometric altitude |
EK3_MAG_I_GATE | Magnetometer |
EK3_TAS_I_GATE | True airspeed |
getFilterStatus() and healthy() to trigger RTL, land, or other protective actions when the navigation solution degrades.
EKFGSF yaw estimator
EKF3 runs a companion Gaussian Sum Filter (GSF) yaw estimator on each active lane. The GSF uses GPS velocity and IMU data to maintain a yaw estimate that is independent of the compass. If compass-based yaw becomes unreliable (large innovations, magnetic anomaly), EKF3 can reset its yaw to the GSF estimate:EK3_GSF_RST_MAX.
Usage example
In ArduPilot code, EKF3 is almost always accessed throughAP_AHRS rather than directly. The following example shows how to read navigation state safely:
Symbolic derivation
The EKF equations were derived symbolically in MATLAB and the derivation scripts are stored in:Key parameters
| Parameter | Description |
|---|---|
EK3_ENABLE | Enable EKF3 (1 = enabled, default) |
EK3_IMU_MASK | Bitmask of IMUs to run EKF3 lanes on |
EK3_ALT_SOURCE | Altitude measurement source (0 = baro, 1 = rangefinder, 2 = GPS, 3 = beacon) |
EK3_GPS_TYPE | GPS usage (0 = auto, 1 = no GPS, 3 = no vel) |
EK3_GPS_CHECK | Pre-arm GPS check bitmask |
EK3_MAG_CAL | In-flight magnetometer calibration mode |
EK3_MAG_MASK | Bitmask forcing simple compass fusion per lane |
EK3_FLOW_USE | Optical flow fusion mode (0 = off, 1 = nav, 2 = terrain) |
EK3_RNG_USE_HGT | Rangefinder altitude use threshold (% of max range) |
EK3_GSF_RUN_MASK | Bitmask enabling the GSF yaw estimator per lane |
EK3_OPTIONS | Processing option flags (jamming mode, manual lane switch, etc.) |
EK3_PRIMARY | Initial primary core index at startup |