Pixhawk Pre-arm check fails "Compass not healthy"

3DR DIY Quad 2014
APM 3.2

I have occasionally seen these and usually unplugging and plugging in the battery usuall fixes things. However, today it would not clear and I could not get off the ground. I had done a short test flight earlier without issues in a different location. The compass direction in the telemetry seemed steady, but was indicating a different direction each time I rebooted.

I recalibrated the compass very carefully without issue (selected Pixhawk in APMPlanner2). Calibration found two compasses - internal and external I assume - and the IDs were as documented in github.com/diydrones/ardupilot/issues/1355 - i.e. both had ID’s, compass 2 was NOT -1. Is this correct? The compass heading in APM is correct and responds quickly to movement. Applied power and same result “Compass not healthy”. Tried again and got “Compasses inconsistent”.

So here’s a weird thing. I connect the battery with the copter not moving (obviously). If I then rotate the copter a little so that the heading viewed in APMPlanner2 moves the error goes away! If a compass is faulty, how can I tell which one. How can I tell whether the calibration is reasonable?

Thanks for any help

Please provide tlogs and/or data flash logs to assist with troubleshooting your issue.

Ok here’s a dataflash log. This was actually a flyaway that resulted in the loss of my gimbal amongst other things. I believe I had the compass not healthy messages right at the beginning but they eventually cleared. Note that the copter is not armed when the messages occur - when does the log capture start? Is it when you arm/press the red button - in which case they won’t show anything useful?

Be good to know if the compass was the cause of my flyaway (although I also see a massive GPS glitch), as its going to be expensive to fix and I would like to avoid this in the future!