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:
The 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
Comments
Bill, could you repost your original document on a location that is not google code?
Thanks,
Phillip
Hi Alec,
You are correct, I am assuming the shortest rotation. I am using the same idea that is used in the PI feedback controller for the gyro drift computation in the DCM algorithm: the misalignment rotation vector for a pair of vectors is perpendicular to the plane that they lie in.
The matrix A itself is unique. The method that I describe computes A iteratively via a sequence of small rotations of the identity matrix. The process converges and stops with the correct value of A when the magnetic field in the earth frame converges to a constant value.
Best regards,
Bill
Hi Paolo,
It sounds like you are interested in vector and matrix representations of rotations. I suggest your next step is to read up on rotation matrices. The wiki entry on the subject is pretty good. Read it a couple of times, paying special attention to the rigorous conversions among matrix, quaternion, and axis-angle representations.
You can in general move freely between matrix, quaternion, and axis-angle representations. The vex operation converts from matrix to angle-axis, assuming the angle is less than 90 degrees. Quaternions and axis-angle representations can easily be converted to matrices, using the equations in the wiki article. In my implementation of the magnetometer alignment, I sometimes use matrices (such as when realigning the mag vector), and sometimes vectors.
The conversions from matrix to quaternion and axis-angle representations look complicated, but you can simplify them if you make assumptions about signs. In our case, we can use the simpler equations because the algorithm will converge until the residual misalignment is zero. We really do not need to compute the exact misalignment at each step, we just have to keep moving closer to the correct answer, and to be able to stop when we get there. The key is to always apply the latest estimate of the alignment matrix to the mag measurements before computing the residual misalignment.
Although quaternions have 4 components, only 3 of them are independent. The main difference between quaternions and axis-angle is that quaternions are based on the sine and cosine of half the rotation angle, while axis angle representation is based on sine and cosine of the rotation angle.
Anyway, I will do my best to answer some of your questions.
1. The vex operator computes the following axis-angle parameters from the rotation matrix:
n1*sin(alpha) = ( x32 - x23 ) / 2
n2*sin(alpha) = ( x13 - x31 ) / 2
n3*sin(alpha) = ( x21 - x12 ) / 2
where n1, n2, and n3 are the direction cosines of the rotation axis, and alpha is the rotation angle.
For small angles, the equations become:
n1*alpha = ( x32 - x23 ) / 2
n2*alpha = ( x13 - x31 ) / 2
n3*alpha = ( x21 - x12 ) / 2
2. Refer to the wiki article on how to convert angle-axis or quaternions back onto a rotation matrix. There is more to it than just putting elements into the right places.
3. Regarding the updating the quaternion, I found a way that worked reasonably well was to do an incremental quaternion rotation, ignoring the cross product. Here is a link to the implementation.
Best regards,
Bill
@Mike, which is why the UDB / MatrixPilot will work out the alignment of the magnetometer automatically ! (Thanks Bill P). You don't really have to worry anymore. Just give the magnetometer alignment your best shot, and then MatrixPilot will do the rest. The magnetometer should be mounted right way up and in the same level position as the main level flight of the plane. However you can orientate it into 4 positions, and give the magnetometer options file a hint as to what you want. The UDB will always align the mag, but the more you mis-align, the longer it takes to figure out what you've done (as you turn the plane around).
In the case of planes, right now I am considering fixing the magnetometer underneath the APM, where it has only some foam between it and the earth most of the time, and where it is four inches or more removed from the stock magnets (if I keep them) and also farther away from the ESC and motor, the xbee and video transmitter, and farther away from the servos. But how to ensure it is aligned, that is always a challenge.
LOL. Actually, this is a major reason why I am so very interested in the magnetometer calibration routines. I do not like to mount the magnetometer on the APM, in part because I use the i2c bus, and also because I wanted the freedom to move it farther away from an ESC (in the case of one of my smaller quads) and center it closer to the XY sensors, and I also foresaw that I might want to move it farther from the magnets on my planes (if I leave them in place... jury is still out there....
But once the magnetometer is mounted separate, alignment becomes a more serious issue.
Bill D.
Please forgive me if I answer beford Bill P. (who may yet still answer. I know that he is deep into more exciting R&D).
The magnetometer returns a 3D Vector which is rotated into the Earth Reference. The MatrixPilot firwmware only uses this 3D vector for correcting the yaw information in the Direction Cosine Matrix,;not Roll or Pitch.
Best wishes, Pete
Ionut,
In case you don't get around to reading my report, and are wondering how to account for magnetometer delay.
First, you have to determine what the delay is. That is easy enough to do with a camera: spin the IMU and magnetometer. Use the mag readings to implement yaw lock. Flash an LED when the heading passes a certain location. Plot the angular position of the flash versus rotation rate. From that you can figure out the magnetometer group delay.
Once you know the magnetometer group delay, its easy to account for it. It just like pretriggering a scope. You take a snapshot of the direction cosine matrix prior to receiving the magnetometer data. You wind up orientation information that matches in time with magnetometer information.
Then, to prove that it all works, you repeat the spin test. If you have everything working right, then the angular location of the LED blink does not move as speed varies.
In some ways it is like using a timing light to adjust the ignition timing of your motorcycle.
Best regards,
Bill
Hi ionut,
You are absolutely right, there is a delay between magneto reading and gyro reading. I have already taken care of that to a "gnat's eyelash". You might want to read my report. I figured out ways to get very high performance out of inexpensive gyros and magnetometers. I pulled out all the stops to be able to maintain high accuracy of orientation estimation during sustained (indefinite), high rate rotations (500 degree/second) around any axis. Two techniques in my bag of tricks was to automatically calibrate the gyro gains, and to account for magnetometer reporting latency.
As part of the testing, I spun the IMU and magnetometer at 78 RPM, and blinked an LED to create a visual pattern that I used to determine the group delay of the magnetometer. One of the pictures from the research is shown at the top of this reply.
Best regards,
Bill
Mr.Premerlani unfortunately I don't think I'm up to the task because I lack solid algebra and physics skills.(not my field not even remote).I used some of these techniques in medical field.
Regarding magnetometers I think that magnetometer can offer limited information just by reading earth magnetic field.You will need multiple magnetic fields to extract position and orientation using a magnetometer.
Also I think there is a delay between magneto reading and gyro reading :(.
-
1
-
2
-
3
of 3 Next