Will EKF2 calculate my compass misalignment?

Will EKF2 calculate my compass misalignment (in relation to the vehicle frame)? If so, what’s the best way to allow it to do so (leave the drone sitting on the ground perfectly still for 30 mins?), and how can I ensure it remembers the calculated value(s) for subsequent operations?

Thanks,

Gerry

As of the latest RC, it will automatically set its orientation, but only to one of the already defined positions. (If I understand it correctly)
So, if your compass is rotated by 90 degrees and upside down, it should be able to set the correct orientation for it. You do a compass calibration for it to figure it out.
If it’s of by 30 degrees or something not already defined, then I don’t think it will work.

My impression is that EKF2 works out the difference between the specified orientation and the actual orientation. So, say you install your compass yaw +90 degrees. You also specify that you’ve installed the compass yaw +90 degrees. EKF2 then works out the actual difference between compass frame and vehicle frame (which will always exist, but typically be less than a couple of degrees).

Anyone know for sure?

Yes, the EKF does learn to correct for misalignment, however I do not think that this correction is saved between flights or reboots, so it has to re-learn it every flight. This behavior can be changed with the EK2_MAG_CAL parameter. I believe the EKF uses GPS track and other in-flight measurements to learn this, so I think the best way to do this is to fly in a large circle in a position-controlled mode like Loiter.

There is also COMPASS_LEARN, which auto-learns the compass magnetic offsets. These do persist through reboots, but I do not think they can account for misalignment.

there is a setting of ‘2’ for COMPASS_LEARN that has a comment stating that it somehow would ‘learn’ offsets from EKF but i have never seen actual compass values to change having ‘2’ set there - and did not try to trace the code to see what in fact happens in there. if anybody knows the correct answer of what this setting of ‘2’ was supposed to do - it would be helpful.

1 Like