Why is there a huge discrepancy between MAGFit's predicted error reduction and actual flight results after in-flight compass calibration?

Hello everyone,

I have a question about ArduPilot MAGFit in-flight compass calibration, and I’m hoping to get some guidance from the community.

I have two flight logs analyzed with MAGFit, as shown in the attached screenshots:

  • First log (024): This is the flight data after performing a ground compass calibration. When I analyzed this log in MAGFit, it showed that the average heading error of the ground-calibrated compass was over 200 mGauss. MAGFit predicted that if I applied the “Offsets and iron + Battery 1 current” calibration (current compensation + soft iron correction), the average error could be reduced to around 24 mGauss.

  • Second log: I then uploaded the MAGFit-generated calibration parameters to the flight controller, performed a second flight (manually flying figure-8 patterns, with coverage >30% for both compasses as shown in the tool), and re-analyzed the new log with MAGFit. However, the actual average heading error after calibration is still around 150 mGauss, which is a huge difference from MAGFit’s predicted 24 mGauss.

I’m confused about why the predicted error reduction from MAGFit is not achieved in actual flight, even though I flew figure-8 patterns and the coverage percentage meets the requirement. Could anyone help me figure out the possible reasons for this discrepancy?

Thank you in advance for your help!:MAGFIT SCREEN SHOT IMAGE

I recently discovered that a real-world current calibration makes a big difference. For example, the default spec for one of my boards was BATT_AMP_PERVLT = 40.2.
But doing an actual current calibration with the motors on my build and running the motors at 20% throttle on the bench, revealed that it should be 14.6. You might find doing this will impact your compass calibration.

Are you using na analog power module?
They tend to underreport current by a fixed amount dependent on wiring and avionics power load.

Using a digital bench top DC power supply.

I was asking about the power module used not the source of current.

Ah, sorry, confused. For better clarity, I am providing voltage through the DC power supply and doing a motor test at 20% throttle on the bench. I am reading the amp draw off of the DC power supply and then inputting that into Mission Planner. So on the bird itself, I am using its onboard analog to read for ArduPilot purposes though using digital to provide and read for the initial battery param setup.

I have already calibrated the BATT_AMP_PERVLT parameter by the following method: I flew a fully charged battery for 10 minutes, checked the discharged capacity shown in the ground station, then recharged the battery to full and compared the charged capacity with the discharged one. After multiple flights, I found the difference between the discharged and charged capacity was within 100 mAh. After such calibration, is it still possible that inaccurate current readings from the current sensor are causing the poor compass correction results?

Thinking out loud and someone correct me if I’m wrong here… if the stock BATT_AMP_PERVLT was incorrect, then your discharge capacity would be incorrect on the ground station from the start. Wouldn’t you want to check how much discharged or, alternatively, how much got charged on the charger?

You used the correct battery current calibration method, that should not be an issue.

For magfit to work well do a flight with plenty of yaw, circle and some ascent and descent - generally give the copter a good work out.

Try choosing the “Offsets and scale, Battery 1 current” calibration. I’ve found that choosing the “iron” calibration can be overly sensitive particularly if changing payloads that may affect any magnetic fields.

If you mount your battery upside down, the magnetic field will reverse.

You need to mount you batteries always in the same way, with the positive side facing the exact same way.

Otherwise the battery magnetic field will be reversed.

Add that to your conops.

1 Like

My battery has a fixed battery compartment, so the placement position is basically the same every time. Meanwhile, the electricity discharged shown during my flight is consistent with the electricity actually charged back, meaning the current values are almost accurate. I manually perform figure-8 or circular flight paths, making frequent heading changes and altitude variations during flight to collect diverse current values for building the compass compensation model. I just can’t figure out why the issue persists.

Additionally, I tried to generate a standard figure-8 calibration flight path@YURI_RAGE(Scripted MagFit flightpath generation - ArduPilot Lua Scripting - ArduPilot Discourse using a dedicated script, but after loading the script and setting script_time=117 between two waypoints, it failed to generate the figure-8 route at all. This forces me to fly manually. By the way, why won’t the script generate the figure-8 path when loaded? Using this script would save me a lot of work.

Read all of the documentation. It will generate the path and probably did.

Do you have a rough number for the generic 3DR-like PMs?

Are there multiple ways to insert the battery?

Can it generate a magnetic field in another direction?

Most compartments allow two ways to insert a battery

no ,only one way