T3

Magnetometer alignment

3689428725?profile=originalTeam,

The above picture shows an interesting side effect of magnetometer misalignment: complete reversal of the measured horizontal component of the earth's magnetic field.

The effect was discovered by Peter Hollands during his analysis of the data from one of Ric Kuebler's flights. Ric was using the UAV DevBoard (UDB) with MatrixPilot autopilot software. The airplane icons in the picture indicate the estimated orientation of the plane. The blue arrows indicate the estimated direction of the horizontal component of the measured magnetic field, in the earth frame of reference.

The magnetometer is mounted separately from the UDB. It turns out that there was a small roll misalignment of the magnetometer in Ric's setup. Ric aligned his magnetometer more carefully, and the flipping disappeared on subsequent flights. But there was a nagging issue.

Because of the large vertical component of the earth's magnetic field in many parts of the world, magnetometer-based yaw information is particularly vulnerable to misalignment. In my neighborhood, the vertical magnetic field is three times as large as the horizontal field. As a result, a little bit of mechanical misalignment of the magnetometer, and certain attitudes of the aircraft can cause complete flipping of the measured magnetic field.

It is not all that easy to align a separately mounted magnetometer. Even a 5 degree misalignment is too much. I wondered if there might be a way to solve the problem with software....

While I was analyzing the data from Ric's flight, on a hunch, I plotted the measured horizontal magnetic field against the heading:

3689428770?profile=originalThe plot told me two things. First, it told me that there was a misalignment issue. But it also told me how much the misalignment was. If that could be determined from the flight data from a post-flight analysis, it should be possible to figure it out in flight as well. So I set out to find a way to determine magnetometer misalignment in flight, and automatically compensate for it. The theory, implementation, and testing are reported here.

The method works much better than I originally thought it might. It will automatically and exactly compensate for any amount of roll, pitch, and yaw misalignment between a magnetometer and its partner IMU, including 180 degrees.

Best regards,

Bill Premerlani

 



E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • In theory you only need 3 points, but in practice, due to measurement noise, it would be preferable to have an overdetermined system that you can then solve by least squares or by a recursive algorithm such as a Kalman filter or the fixed-gain observer that he is proposing.

  • I'm not sure I fully understand the problem here, but if you have a missalignement between 2 coordinates system like magnetic space and Gyro space, you will need only 3 points in both spaces to determine the transformation between the 2 spaces.Horn's closed form algorithm here

  • Moderator

    Here here, implementing the wind model should be a no brainer for every project out there that can.

    Its a shame that there is not one platform that you could try all the different methods out on.

  • Bill, your elegant use of mathematics to solve such problems as this and wind compensation are impressive to say the least and a major contribution to the development of autopilot systems - not just UDB! Thank you for your immense contribution to the hobby.

     

    Mike

  • Developer

    This is great stuff Bill!

    I'm pretty sure we will integrate this into the Arducopter and ArduPilot code.  Rate determining factor is mostly putting in the time to understand the method Bill's come up with!

    It doesn't need to be someone in the core dev team though, with the magic of git anybody can implement in their own branch and then (apparently) we can merge it in easy to trunk while keeping the credit for who did the original code changes intact...that's my understanding anyway. :-)

  • Moderator

    Sorry, I was thinking of multipilot, if anything, it makes MatrixPilot more remarkable. I've added one to my shopping cart, I need to take a much closer look at everything you have been up to. Thank you.

  • Moderator

    Bill,

     

    Thank you. I'm not feeling sufficiently big brained to grok this at the moment; I will study it and hope that someone here beats me to the punch if munging this into ArduCopter, with your permission. I do not know, also, if we will need to await the next gen hardware for this. If I recall correctly, MatrixPilot is 32bit?

  • T3

    Hi Mike,

    Here is a link to the portion of the MatrixPilot code that does the magnetic field calculations. There are several calculations that are being done, including yaw drift correction, offset removal, and alignment.

    magnetometer.c

    Best regards,

    Bill

  • T3

    Hi Mike,

    I previouslyreported how to achieve inflight calibration of gyros.

    Regarding the source code, I decided to leave it out of the report mostly because I thought a verbal explanation would be easier to follow. If there is sufficient interest, I will also publish the code. Does anyone else want to see the code?

    Best regards,

    Bill

  • Moderator

    I also wonder about the potential application of this sort of calculation in the calibration of gyros or other sensors... for example, if one includes a second set of gyros which are not aligned with those on the IMU? I do not pretend to understand the math, but my limited understanding is suggestive that we can use one set of sensors to calibrate another... I will leave the practical applications possible with three or five separate IMUs to the imagination of the reader. 

This reply was deleted.