Figuring out compass orientation setting from hmc5883 orientation


I’m having trouble finding consistent and clear information on how to determine the custom orientation I should use for my M9N-5883 when it’s mounted in a non-forward, non-flat orientation. It’s a due to the tpu mount I have available for this frame.

I’m understand how the xyz markings work and that it aligning the direction of sensor to the magnetic north will generate the highest register readout for that sensor (x-y-z)

What’s not clear to me is how to translate that to orientation since that all depends on how the software handles the readouts.

If COMPASS_AUTO_ROT is enabled, which it is by default, it will be detected and fixed during calibration. This has worked well for me with a Plane, never needed it with Copter but it’s the same functionality.

I’ve tried auto-rot but I’m not sure it handles non-flat positioning.

At least I’m still getting ekv errors when I tried using it, and I only see it sometimes adjusts orientation to yaw180 to handle the mounting backwards but there’s no handling of some tilt.

So mounting the M9N compass flat, arrow on the PCB backward, would lead to an auto-orient of YAW180 (the x-y-z of the 5883 is definitely pointed in some other direction).

So I figured I’ll throw the 5883 x-y-z direction out the window, go by the arrow, and used a custom orientation of YAW180 + PITCH (-30) (so arrow is tilted above the horizontal, facing backwards).

I still get compass “EKF status” spikes up to around 0.6 but otherwise heading seems work much better than before and is good enough?

I’d still like to get some community feedback on whether I can improve this.