High mag accuracy possible?

I am trying to achieve high heading accuracy with and without gps. With dual antenna gps (1m separation, septentrio mosaic go-h) sub 1 deg is achieved in flight but with only mag i seem to get within 5 deg of gps heading.

Using RM3100 on an arm, 35cm from any other electronics and motors for mag. Calibrated far from buildings etc.

Looking into the calibration for mag it seems like it doesn’t estimate rotational misalignment of the sensor, e.g yaw rotated 2deg. It only detects in the standard ”90deg” angles.
Could this be the reason and can it be calibrated away somehow? I don’t think I can garuantee sub degree rotation when mouting the magnetometer.

Any other ideas on how to achieve high heading accuracy using magnetometer and the EKF.

In my experience that’s very hard. I don’t think the mag signal is that accurate, only once you move around and fuse it with other sensors, the estimate gets better.

Starting to think so too, it would be nice if GPS dual antenna for heading (which is ~0.2-0.6 deg accuracy on 1m distance), could be used for calibrating the magnetometer. :thinking:

I have ~zero thrust to norm of mag field relationship and stable readings.

After some testing today, it seems like it’s mostly an offset error between the mag and the GPS heading, assuming the GPS heading is as accurate as it reports (30 sats gave ~0.3deg accuracy according to the Septentrio Mosaic Go-H).
I did a flight and recorded 8 evenly spaced measurements of the vehicle heading (not fusing GPS heading) and compared them to the reported GPS heading in steady state. The difference is close to constant at 3.6deg.

Adding this type of offset would in this scenario a lot more accurate. Doesn’t seem like a proper way of doing it.

Tried using custom euler angles and changed MAG0_ROT_YAW to 3.6deg. It brought the error down to an average of 2deg in steady state but not as good as just adding 3.6deg constantly to vehicle heading, so that parameter does not do what I want.

I had a look at the Dev talk How to Choose the Right Heading Source for your Next PX4 Platform, which had some interesting insights. For example, mag is only used for heading fusing when needed; otherwise, other sensors are used (e.g., gyro).

Perhaps @bresch could shed some light on the topic.
What accuracy of heading could reasonably be achieved in an GNSS denied area, e.g using mag, if mag placement and mag sensor could be optimized?

@ryanjAA Is there a reason we can’t calibrate magnetometers in flight - I mean if it is a problem for large vehicles is that it difficult to easily rotate them, why not fly them with an unreliable mag and calibrate it as we go. Or is that already done?

I think mag biases are always estimated with the EKF and saved on disarm, but not the soft/hard iron calibration that is done during normal calibration.

Ardupilot can calibrate while flying but I think it likes acrobatic style flying to get a good calibration. A simple hover is probably not enough.

I am currently working on a kalman filter for online offset parameter calibration that uses gps heading to estimate heading misalignment while flying around. With the few logs I have it seems the offset can wander around during firdt 30-120s and after that it stabilizes to a constant offset (while still and nontaw movement)

Will be doing some more flight testing on this in January.

1 Like

EKF does estimate mag biases online (it estimates and compensates mag bias states as part of the filter), but they are only saved on disarm to use later.

We do not currently estimate online the full hard-iron/soft-iron calibration and axis misalignment between the magnetometer and body frame during normal flight. That kind of calibration is normally done offline during the standard magnetometer calibration process.

It’s mainly because of a few factors:

1\. Lack of Excitation:

Mag calibration (especially yaw misalignment and soft/hard iron) requires the sensor to see the full 3-axis range of the Earth’s mag field. That usually means physically rotating through lots of orientations. A simple hover doesn’t provide enough excitation for the calibration states to become observable. We obviously get that excitation in the qgc cal routine (by doing the mag dance).

2\. Variable Interference:

In flight you have changing magnetic interference from motors, power wiring, ESCs, etc. The disturbance field changes with throttle, payload, and environment. That makes online estimation of hard/soft iron parameters tricky unless you model that interference explicitly and have sufficiently rich maneuvers. That said this is likely somewhat manageable

3\. Observability and Flight Safety:

Running full online calibration would add many extra states to the EKF and demand specific motion patterns for observability. If those motions aren’t present, calibration could diverge and destabilize heading estimation. I think thats basically a big one. Bec of this in-flight mag correction limited to bias estimation and rely on offline calibration for the full calibration. At least that is what my takeaway has always been as to why.

That all said, online calibration is done on ArduPilot with sufficient maneuvering, and I’ve def read of it being done on the research side using adaptive filters that jointly estimate hard/soft iron terms and orientation in motion. Incorporating similar methods into PX4 could improve mag-only heading accuracy as well as make life easier, but it’s not part of the core EKF yet.

A nice tradeoff would be just a good enough and confidence level but this is likely something @bresch would need to chime in on.

1 Like

I just read this after hitting reply on mine basically @hamishwillee ^^^^

Hahah

2 Likes