One of my quad-copters has been having compass problems for a while now. These events are rare, you can have 5 or 10 successful flights in a row. Then a new flight, in the same location, on the same day as a prior successful flight, with a good compass calibration and you get a severe “toilet bowl” event.
When I first started to analyze the logs of these flights I saw the obvious characteristics of an “toilet bowl” event. You can fly the drone in “Stabilized” or “AltHold” mode without any problem, and it’s when you put the copter in “Loiter” or “Auto” that it starts to drift strongly to one side and loses control completely. You can also see how the compass innovations (IMX, IMY, IMZ) go to extreme values.
Then I noticed that in all successful flights the readings of the MAG.MagZ are always positive, indicating that the drone is upside up, with a small variation due to the angle of inclination of the drone on the roll and pitch axes during the flight.
Example of a positive reading in a successful flight (Sruvey Mission):
But in the flights that suffered the compass issues, the readings of MAG.MagZ are always negative. This is obviously incorrect because a negative reading must only appear if the copter was upside down.
Example of a negative reading in an unsuccessful flight (“toilet bowl” landed in althold):
The problem is that the compass readings are fine most of the time, but every 5 or 10 flights when the drone is boot up these readings are reversed, and the craft becomes unflyable. When this happens, the compass can be recalibrated. The COMPASS_AUTO_ROT function will recognize the incorrect orientation of the compass during its calibration and correct it by giving it an orientation of for example Roll180Yaw90.
Then you’ll be able to fly without a problem. But when you reboot the drone these compass readings can change and become correct again, making the craft unflyable again due to the wrong calibration with the orientation offset than is no longer needed.
Has this happened to anyone, too? Do any of you know why this happens?
Ardupilot version: AC 3.6.11 ChibiOS and AC 3.6.6 NuttX (UPDATE: Also tested in AC 4.0)
Hardware: Pixhawk1 and external GPS+Compass module (HMC5883)