Compass Heading changes when arming vehicle?

Brief question, does anyone have any ideas as to why my compass heading would change when arming or disarming the vehicle? motors are not connected, and all of the “motor offset” parameters are zero, and the heading still changes, sometimes by as much as 40 degrees when I arm the vehicle. When I disarm, it returns to the previous value.

Thank you in advance.

Does the GCS give you any messages? Particularly there might be something about “ground mag anomaly,” “yaw realigned,” or “heading reset.”

None as far as I can tell. It’s also important to note that the heading estimate when disarmed drifts over time. If I start up the PX4 and immediately arm and disarm it, the two heading values are the same, or very close. As time goes on, the “disarmed” heading value drifts slowly, while the value that it jumps to when armed stays the same

Interesting, what do you have your EK2_MAG_CAL parameter set to? Default is 3 for Copters.

Heading drift is normal if it’s using gyros only, but I don’t recall this kind of heading reset on arming to be typical behavior.

To dig into this more, it might be good to set LOG_DISARMED = 1 (to record logs while the vehicle is disarmed) and then download the log after a flight in which the issue occurs.

As far as I know AP doesn’t do any heading resets on arming. It does reset the heading after it reaches about 2m of altitude. It’s possible that the difference in heading is caused by a ground station display - that’s a guess of course… a log helps reduce the guesswork…

Will try this. Unfortunately, this vehicle is rather large, and still in development, so the best I can do is arm it and give it throttle without motors powered, and look at the heading during that “flight”.

Just curious, is there anyway to just disable the compass entirely? I don’t need it for these initial hover tests, but even when I disable all; compass parameters, the yaw heading still changes at arming and the vehicle will physically try to yaw in a direction uncommanded by me. How are you supposed to disable the compasses if “Mag_Enable” being set to 0 doesn’t even do it?

It has been set to 0 for awhile, I tried setting it to 2, or “never” to try to stop the in-flight yaw realignment, but it still persists, even with this parameter turned off

Here is a Drive link to some log files from this morning, they were all too large to upload.


Ah, this is plane. Best that this is in the Plane forum. I’ll move this discussion.

At the risk of being accused of passing the buck, I’m going to leave this to the Plane guys to investigate I think. I’ve just tested it on Copter and the heading does not change so I suspect it’s something to do with the “fly forward” feature of the AHRS/EKF (i.e. use of the GPS to determine heading) which is mostly specific to Planes.

EDIT: I’ve reproduced this on Rover as well and asked our EKF expert @priseborough to see if he has any ideas.

Right, forgot to mention that it is actually modified quadplane firmware, so although it is plane, I am attempting to debug behavior in a multi-rotor, and thus posted my question here for lack of a better idea as to where to pose the question. I appreciate the help! Today I am trying stock firmware’s for both quad and plane to see if I can recreate the issue. You said that you saw the same behavior on Rover? The vehicle’s compass heading changing when armed?

Update: I couldn’t repeat the issue in the most recent versions of Plane or Copter. However, I went back to my custom firmware and disabled the AHRS_EKF_Type parameter, and that seemed to fix my compass reset issue. Did a few hover tests and the vehicle looks stable, no unwanted yaw inputs. However, the log files still show the occasional “EKF2 Yaw reset” message during flight. So the Kalman filter is still active, even though I supposedly disabled it? weird.