Magnetometer Calibration


Hi all,

I’d like to get feedback on whether PX4 would be interested in an optional in-flight magnetometer calibration path that continuously updates both hard-iron bias and soft-iron distortion during flight using the existing sensor suite.

Problem:

PX4 already has several useful magnetometer calibration workflows, but they are still mainly pre-flight or offline tools.

  • Complete calibration estimates offsets and per-axis scale factors, but it requires guided multi-orientation handling before flight.

  • Quick calibration runs while disarmed and only estimates hard-iron offsets.

  • Large-vehicle calibration uses GNSS, known vehicle orientation, and the World Magnetic Model, but it also targets hard-iron offsets rather than full soft-iron correction.

  • Power compensation is available for current-induced interference, but it is an offline log-based workflow rather than an automatic in-flight solution.

  • EKF2 can estimate magnetic bias when it is observable, but PX4 does not currently expose a user-facing in-flight full magnetometer calibration path that continuously adapts both bias and soft-iron terms.

In practice, this means calibration can become stale when the magnetic environment changes after setup. Common examples are payload changes, wiring changes, new mounts, temperature drift, frame modifications, or vehicles that are difficult to rotate fully on the ground. The result can be degraded heading performance, mag inconsistency warnings, or repeated manual recalibration.

Proposed Solution

Add an optional in-flight calibration path that continuously estimates and updates both hard-iron bias and soft-iron distortion during flight, using the existing gyroscope and magnetometer measurements.

The intent would not be to replace current calibration workflows. Instead, the goal would be to add an online correction layer that can improve calibration when the vehicle experiences enough rotational excitation and the solution is well-conditioned.

PX4 already has online hard-iron bias estimation via the mag_bias_estimator module (and EKF2 learns mag biases in-flight too) — the only genuinely new piece in your proposal is online soft-iron estimation, which needs much richer rotational excitation than typical flight provides; got a plan for that?

Thanks, fair point. I agree PX4 already covers the online hard-iron side, so the new part here is really online soft-iron estimation.

That said, I’m not convinced it needs extremely aggressive motion to be useful. My guess is it can still work under low to moderate multi-axis excitation over a longer window, as long as updates are gated by a confidence check.

What level of excitation do you think is actually needed in practice?