External compass orientation problem

I’m rebuilding Phantom 2 with Pixhawk and PX4, and trying to reuse as many DJI original parts as possible. I’ve solved a bunch of issues, but stumble upon the unexpected one.

I can not set the right orientation for the external compass.

Using handy CLI command sensors status, I was able to find the base orientation of the external compass, in which both internal and external magnetometers reading seem to match. I’ve checked with the datasheet on HMC5883, and as far as I can tell, that orientation is correct.

Now, I want to mount the sensor back where it was and set a correct rotation in PX4 parameters. But can’t find a correct option for it.

To get compass into position, I need to turn it around two axes. One of the possible definitions: first, it should be turned 90 degrees clockwise around the yaw axis, then, 90 degrees counterclockwise around the pitch axis. I hope that explanation makes sense.

In despair, I’ve tried all two-axis 90 degree-divisible options, including:
10 Roll 180°, Yaw 90°
14 Roll 180°, Yaw 270°
18 Roll 90°, Yaw 90°
22 Roll 270°, Yaw 90° <-- this seems to be correct, but doesn’t work :frowning:
There are only four of them, which is very strange.

I’m stuck, any help appreciated.

Hi @errno!

Here my reasoning.

There are just two thing you have to take into account, first of all sensor orientation:
immagine
Then to the drone orientation:
https://docs.px4.io/v1.9.0/en/config/flight_controller_orientation.html

From the sensor datasheet, the z axes is pointing upwards from the sensor to your eyes, so you have to flip it 180° (roll), and then rotate it 180° (yaw), in the case the front of the drone is pointing on the top of the screen and you see it from above.

Hope it helps! :vulcan_salute:

Sorry for a long silence, was busy with other stuff.

@simosilva, thank you for the input. Hint on Z-axis direction was useful.

But unfortunately, looking into datasheet wasn’t sufficient. Further googling and exploring source code (to be 100% sure) led me to the correct base orientation. Here is the place in the driver where axes are remapped https://github.com/PX4/Firmware/blob/47e668eb86531130bcc22b29f82d62eaa57704a6/src/drivers/magnetometer/hmc5883/hmc5883.cpp#L885.

After some more poking through the code I found that desired magnetometer orientation is not supported. To my surprise, not all of the 24 possible 90-degree-divisible orientations are implemented. In general, list of orientations is messy and incomplete.

I disabled external compass for now, but I’m going to try adding missing orientation, and creating pull request after some testing.

1 Like