Diagnosing Compass Variance Errors in ArduPilot Logs
ardupilotcompassekflog-analysismagnetometer

Diagnosing Compass Variance Errors in ArduPilot Logs

LogHat Engineering TeamMarch 28, 20265 min read

Key Takeaway

Compass variance in ArduPilot logs is XKF4.SM — the EKF3 magnetometer test ratio. Above 1 means a measurement was rejected; sustained above 0.5 means heading confidence is degrading. Distinct from compass interference (the specific current-induced bias cause fixed by COMPASSMOT). Identify which cause drives the variance: interference, stale calibration, external structures, or failing hardware.

TL;DR: "Compass variance" in ArduPilot logs refers to XKF4.SM — the EKF’s normalised magnetometer test ratio. Above 1.0 means the EKF rejected a compass measurement; sustained above 0.5 means the EKF is downweighting compass and starting to mistrust heading. This is not the same as compass interference (which is about current-induced bias, fixed with COMPASSMOT) — variance is the consequence the EKF observes after interference, calibration drift, or external magnetic disturbance has affected the reading.

What "compass variance" actually means

The EKF runs an innovation-and-gate check on every sensor measurement. For the compass, the measured magnetic field is compared against the EKF’s prediction (from gyro integration plus the modelled magnetic field). The squared difference, normalised by the EKF’s expected uncertainty for that measurement, is written to the log as XKF4.SM.

  • XKF4.SM < 1 — the measurement was within the gate and was used.
  • XKF4.SM > 1 — the measurement was rejected; the EKF skipped that update.
  • Sustained XKF4.SM climbing past 0.5 — the EKF is filtering through marginal compass data and yaw confidence is degrading.

That single number, plotted over the flight, tells you whether the compass is contributing to navigation or being progressively de-weighted. The raw mag innovations live in XKF3.IMX, XKF3.IMY, XKF3.IMZ; the test ratio in XKF4.SM tells you whether they crossed the gate.

Where to look in Mission Planner

Open the log and plot the four signals that together identify a compass variance problem:

  • XKF4.SM — the test ratio.
  • XKF3.IMX, XKF3.IMY, XKF3.IMZ — the per-axis innovations.
  • MAG.MagX, MAG.MagY, MAG.MagZ — the raw compass readings. Sudden jumps without yaw change indicate external interference.
  • RCOU.C1C4 — correlate with current draw (and therefore expected magnetic disturbance) on Copter.

Mission Planner’s "EKF Status" HUD widget surfaces the compass variance live during flight too — the bar climbs visibly as the test ratio rises.

Confirming it in MAVExplorer

MAV> graph XKF4.SM
MAV> graph XKF3.IMX XKF3.IMY XKF3.IMZ
MAV> graph MAG.MagX MAG.MagY MAG.MagZ
MAV> graph RCOU.C1 RCOU.C2 RCOU.C3 RCOU.C4

Overlaying XKF4.SM against RCOU output reveals the relationship between throttle (current) and compass mistrust. If the variance climbs every time you punch out of hover, that’s a current-induced bias problem.

Why variance climbs — ranked

  1. Current-induced bias from ESC and power leads. Most common. XKF4.SM tracks RCOU output. Fix is COMPASSMOT calibration plus physical separation; covered in our compass motor interference post.
  2. Stale or poor compass calibration. The compass offsets stored in COMPASS_OFS_X/Y/Z no longer match the current magnetic environment. Variance climbs in clean air with no throttle correlation. Re-run the calibration in an open area away from metal.
  3. External magnetic interference. Flying near power lines, reinforced concrete, or large metallic structures. Variance climbs at specific geographic locations and clears when you leave them.
  4. Wrong COMPASS_DEC (declination). Manually-set declination wrong by more than a few degrees produces a constant bias the EKF interprets as variance.
  5. Failing compass hardware. An aging chip drifts; raw MAG readings show abnormal scaling or random spikes uncorrelated with anything. Replace the sensor or switch to an external module with COMPASS_USE = 0 on the bad one.

Fixing it

  1. Run COMPASSMOT calibration. Captures the current-vs-magnetic-bias curve so the EKF can subtract the expected interference. Re-run after any major wiring change. See the ArduPilot advanced compass setup page for the procedure.
  2. Move the compass. Even an extra 30 mm of separation between an external compass and the main power leads can drop XKF4.SM by half. For agri and survey rigs, a mast-mounted GPS+compass module is the durable solution.
  3. Calibrate in a clean environment. Onboard calibration runs anywhere will absorb local interference into the offsets and produce variance everywhere else you fly. Pick a field, not a hangar.
  4. Set COMPASS_AUTODEC = 1. Lets ArduPilot pull the magnetic declination from its world model rather than a stale manual value.
  5. Disable a failing compass. Set COMPASS_USE for the affected instance to 0 — the EKF falls back to the next healthy compass. Only do this if other compasses are present and clean.

Variance versus interference — they sound the same but aren’t

Compass variance is the EKF’s measurement of how badly the compass is disagreeing with everything else. Compass interference is a specific cause: current-induced magnetic bias from ESCs and power leads. You can have:

  • High variance from interference — fixable with COMPASSMOT and separation.
  • High variance from poor calibration — fixable with a fresh field calibration.
  • High variance from external structures — fixable only by changing where you fly.
  • Interference present but variance manageable — flying carefully in a high-throttle envelope while the EKF gates handle the rest.

Conflating the two leads to the wrong fix being applied. Read the variance trace first, then look for what’s driving it.

When this isn’t actually compass

  • Gyro bias. If the EKF’s yaw prediction is wrong because gyro integration has drifted, compass measurements look wrong by comparison. Cross-check XKF4.SS bits and XKF4.errRP — a real compass problem leaves them clean.
  • Vehicle frame magnetic memory. Carbon-fibre frames with steel hardware can magnetise. The compass reads a steady bias that ignores flight movement. Re-calibration usually catches it; if not, the frame itself has to change.
  • Compass / GPS-yaw confusion in dual-GPS setups. If EK3_SRC1_YAW is set to GPS but only one GPS is reporting, the EKF can fall back inconsistently. Check the yaw source configuration.

When LogHat helps — and when it doesn’t

LogHat plots XKF4.SM with the rejection threshold drawn, correlates it against RCOU output so you can see throttle-driven interference, and flags the specific cause family in the Root Cause Hypotheses section. What we can’t tell you is whether you were flying through a high-tension power corridor — that needs your flight-path knowledge, not the .bin.

About the author

LE

LogHat Engineering Team

The LogHat engineering team — drone-systems engineers who build and operate the LogHat flight analytics platform. Posts in this byline are written and reviewed by team members working on the parsers, analysis engine, and Vector AI that the post describes.

Tagged

ardupilotcompassekflog-analysismagnetometer

Try LogHat

Analyze your flight logs in seconds

Upload a .bin, .tlog, .log, or .ulg file. Get AI crash analysis, 3D replay, and forensic PDF reports instantly.

Try LogHat Free