Comments - Magnetometer alignment - DIY Drones2017-12-13T18:40:51Zhttp://diydrones.com/profiles/comment/feed?attachedTo=705844%3ABlogPost%3A680600&xn_auth=noBill, could you repost your o…tag:diydrones.com,2015-04-25:705844:Comment:19776982015-04-25T00:30:44.407ZPhillip Schmidthttp://diydrones.com/profile/PhillipSchmidt
<p>Bill, could you repost your original document on a location that is not google code?</p>
<p></p>
<p>Thanks,</p>
<p></p>
<p>Phillip</p>
<p>Bill, could you repost your original document on a location that is not google code?</p>
<p></p>
<p>Thanks,</p>
<p></p>
<p>Phillip</p> Hi Alec,
You are correct, I a…tag:diydrones.com,2012-03-26:705844:Comment:8169912012-03-26T00:18:13.534ZWilliam Premerlanihttp://diydrones.com/profile/WilliamPremerlani
<p>Hi Alec,</p>
<p>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.</p>
<p>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…</p>
<p>Hi Alec,</p>
<p>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.</p>
<p>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.</p>
<p>Best regards,</p>
<p>Bill</p> Sorry - one rotation for each…tag:diydrones.com,2012-03-20:705844:Comment:8127432012-03-20T21:37:07.467ZAlec Myershttp://diydrones.com/profile/AlecMyers
<p>Sorry - one rotation for each angle theta and 2pi-theta and two possible rotations for every angle in between.</p>
<p>Sorry - one rotation for each angle theta and 2pi-theta and two possible rotations for every angle in between.</p> Bill,
I think your equation…tag:diydrones.com,2012-03-20:705844:Comment:8125562012-03-20T21:34:01.636ZAlec Myershttp://diydrones.com/profile/AlecMyers
<p>Bill,</p>
<p></p>
<p>I think your equation 11 is an insufficient constraint on A to define it.</p>
<p></p>
<p>For vectors a, b of equal length that subtend theta there is a rotation from a to b for every angle {theta, 2pi-theta}. You're assuming the shortest rotation (theta) is correct, am I right?</p>
<p>Bill,</p>
<p></p>
<p>I think your equation 11 is an insufficient constraint on A to define it.</p>
<p></p>
<p>For vectors a, b of equal length that subtend theta there is a rotation from a to b for every angle {theta, 2pi-theta}. You're assuming the shortest rotation (theta) is correct, am I right?</p> Hi Paolo,
It sounds like you…tag:diydrones.com,2011-11-28:705844:Comment:7188912011-11-28T01:11:27.322ZWilliam Premerlanihttp://diydrones.com/profile/WilliamPremerlani
<p>Hi Paolo,</p>
<p>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 <a href="http://en.wikipedia.org/wiki/Rotation_matrix" target="_blank">wiki entry on the subject</a> is pretty good. Read it a couple of times, paying special attention to the rigorous conversions among matrix, quaternion, and axis-angle representations.</p>
<p>You can in general move freely between matrix, quaternion, and…</p>
<p>Hi Paolo,</p>
<p>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 <a href="http://en.wikipedia.org/wiki/Rotation_matrix" target="_blank">wiki entry on the subject</a> is pretty good. Read it a couple of times, paying special attention to the rigorous conversions among matrix, quaternion, and axis-angle representations.</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p> </p>
<p>Anyway, I will do my best to answer some of your questions.</p>
<p> </p>
<p>1. The vex operator computes the following axis-angle parameters from the rotation matrix:</p>
<p> </p>
<p>n1*sin(alpha) = ( x32 - x23 ) / 2</p>
<p>n2*sin(alpha) = ( x13 - x31 ) / 2</p>
<p>n3*sin(alpha) = ( x21 - x12 ) / 2</p>
<p> </p>
<p>where n1, n2, and n3 are the direction cosines of the rotation axis, and alpha is the rotation angle.</p>
<p> </p>
<p>For small angles, the equations become:</p>
<p> </p>
<p>n1*alpha = ( x32 - x23 ) / 2</p>
<p>n2*alpha = ( x13 - x31 ) / 2</p>
<p>n3*alpha = ( x21 - x12 ) / 2</p>
<p> </p>
<p>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.</p>
<p> </p>
<p>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 <a target="_blank" href="https://docs.google.com/document/d/1z3DCEd9IXgIdPmByF62cUWZcfBCBf0J4Z2g0Nmw6xXg/edit?hl=en_US">link to the implementation</a>.</p>
<p> </p>
<p>Best regards,</p>
<p>Bill</p>
<p> </p> Dear Premerlani,
I'm very int…tag:diydrones.com,2011-11-25:705844:Comment:7166622011-11-25T09:05:37.669ZPaolo Mosnahttp://diydrones.com/profile/PaoloMosna
<p>Dear Premerlani,</p>
<p>I'm very interested in your article, which I read very carefully.</p>
<p>But I still have few points not very clear.</p>
<p>(1) First point is what you call vex operation. Giving a rotation matrix R vex operator is as follow:</p>
<p> vex(R) = 1/2 ( R - Rt ) = [ n1 n2 n3 ]</p>
<p>where Rt is the transpose of R. So giving xij the matrix element in row i and column j we would have:</p>
<p> n1 = 1/2 ( x12 - x21 );</p>
<p> n2 = 1/2 ( x13 - x31 );</p>
<p> n3 = 1/2 (…</p>
<p>Dear Premerlani,</p>
<p>I'm very interested in your article, which I read very carefully.</p>
<p>But I still have few points not very clear.</p>
<p>(1) First point is what you call vex operation. Giving a rotation matrix R vex operator is as follow:</p>
<p> vex(R) = 1/2 ( R - Rt ) = [ n1 n2 n3 ]</p>
<p>where Rt is the transpose of R. So giving xij the matrix element in row i and column j we would have:</p>
<p> n1 = 1/2 ( x12 - x21 );</p>
<p> n2 = 1/2 ( x13 - x31 );</p>
<p> n3 = 1/2 ( x23 - x32 );</p>
<p> </p>
<p>Is this correct?</p>
<p> </p>
<p>(2) Within the steps to implement the algorithm (from point 1 to pint 9), in point 5 you compute E as inverse vex operation. But vex operation just obtain x12 - x21, x13 - x31 and x23 - x32 and all zeros on the diagonal. Is this ok to compute E? could you better explain vex operation and its inverse?</p>
<p> </p>
<p>(3) finally, in step 9 you tell to compensate align with following equation:</p>
<p> </p>
<p> align = align - gain * adjust</p>
<p> </p>
<p>But align is a quaternion representation which is a 4 dimensions array, meanwhile adjust is 3 dimensional array, how each single element of align have to be compensated using adjust array?</p>
<p> </p>
<p>Pleas could you clarify aforementioned points?</p>
<p>Thanks for any suggestion.</p>
<p>Paolo.</p> @Mike, which is why the UDB /…tag:diydrones.com,2011-10-21:705844:Comment:6847252011-10-21T17:43:58.922ZPete Hollandshttp://diydrones.com/profile/PeterHollands
<p>@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…</p>
<p>@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).</p>
<p> </p> In the case of planes, right…tag:diydrones.com,2011-10-21:705844:Comment:6847822011-10-21T17:00:57.107ZMichael Pursifullhttp://diydrones.com/profile/MikePursifull
<p>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.</p>
<p>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.</p> LOL. Actually, this is a majo…tag:diydrones.com,2011-10-21:705844:Comment:6847172011-10-21T16:57:32.698ZMichael Pursifullhttp://diydrones.com/profile/MikePursifull
<p>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…</p>
<p>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....</p>
<p> </p>
<p>But once the magnetometer is mounted separate, alignment becomes a more serious issue. </p> Pete,
Thanks for the response…tag:diydrones.com,2011-10-21:705844:Comment:6847142011-10-21T16:44:18.664ZBill Donovanhttp://diydrones.com/profile/BillDonovan
<p>Pete,</p>
<p>Thanks for the response. That's what I thought. Just wanted to make sure. Real time calibration of the mag can definitely be useful. People always find ways to mess up a mag calibration.</p>
<p>Customer: "Look I installed a new hatch closure mechanism."</p>
<p>Me: "Are those rare earth magnets right next to the magnetometer?"</p>
<p>Customer: "Yup...is that a problem?"</p>
<p>Me: Scratching head.</p>
<p>Pete,</p>
<p>Thanks for the response. That's what I thought. Just wanted to make sure. Real time calibration of the mag can definitely be useful. People always find ways to mess up a mag calibration.</p>
<p>Customer: "Look I installed a new hatch closure mechanism."</p>
<p>Me: "Are those rare earth magnets right next to the magnetometer?"</p>
<p>Customer: "Yup...is that a problem?"</p>
<p>Me: Scratching head.</p>