Shop OBEX P1 Docs P2 Docs Learn Events
Using a memsic2125 for tilt compensation of compass — Parallax Forums

Using a memsic2125 for tilt compensation of compass

rwgast_logicdesignrwgast_logicdesign Posts: 1,464
edited 2013-03-03 17:00 in Accessories
I was hoping someone here could give me the run down on how one could do compass tilt compensation using a memsic 2125. Basically from what I understand if the accelerometer is perpendicular with the ground and is then tilted you can get the amount of rotational degrees by combining the X and Y outputs of the memsic2125.

Here is what im having trouble figuring out. Fist of all once you have your degree of tilt, angle of rotation, whatever you want to call it how do you apply this to your compass data?

Next thing and this probably sounds stupid but, lets say the acclerometer is mounted on a robot. The left wheel is higher than the right, or vice versa, you would be able to measure the amount of tilt. But what if the nose or front end of the robot is at a higher point than its tail, is this still on the same x,y plain? Or even more complicated what if the bots nose and left wheel are high causing the tail and left wheel to be low, would a 2 axis accelerometer fit this scenario? Basically im trying to figure out when a 3 axis accelerometer may be needed besides an application where you would want to meassure g forces along the Z axis?

Edit:
One last thing, the compass im using is a standard HMC5883L 3 axis, when I think of a compass I think of a flat device that that operates in a 2 demensional plain. I know these are acually magnometers that measure magnetic feilds, but I dont quite understand what the third access is for..

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-03-03 13:06
    Depending on how close you are to a magnetic pole, the magnetic field lines can have a strong vertical component. Here in Idaho, the z component is very significant.

    One can use a three axis magnetometer to measure the orientation of a robot. You really don't need an accelerometer to correct for tilt if your magnetometer has three axes.

    You would first need to determine what the magnetic field's vector is in your part of the world. You could then use this information to figure out your robot's orientation by comparing current magnetic vector to this initial vector. This would involve a lot of math with rotation matrices or quaternions.

    How much of a tilt do you think you'll need to worry about? I think a tilt of up to 15 degrees wouldn't throw the compass off by much. You ought to test and see how your sensor behaves without any tilt compensation to see if it's even needed. If you decide it is needed then you'll probably want to find an example program that uses the third axis in its heading calculation.

    I modified the example code on Parallax's KickStarts page. My version outputs a heading and a couple of "tilt" angles. I haven't really figured out how to use the tilt angles for anything practical yet.

    Here's the output from my version of the code.
    X = -71 , Y = -200, Z =-594
    
    Course = -109.545  tiltX = -96.81, tiltY = -108.608
    

    More digits are displayed than are really significant. If your calculation starts with three digit numbers, the output's accuracy is generally only good for three digits (a very simplified description of significant digits).

    The "Course" value (heading) has a range from -179.999 to 180 degrees. Zero should be magnetic north and 180 magnetic south.

    You ought to try the code and see how much tilt affects your heading reading.

    My SparkFun board doesn't include pull-up resistors on the I2C lines. If you're board doesn't have pull-ups, you'll want to make sure and include them. The pin assignments in the attached object use the Prop's I2C bus so if you use the same pins you shouldn't need to add pull-up resistors. Almost all Propeller boards have pull-up resistors on P28 and P29. The exception to this is the Propeller Demo board which only has a pull-up on the data line.

    The OBEX version of F32 has a bug in the Atan2 method. Use the F32.spin object included in the attached archive. The attached version of F32 includes my temporary fix to the Atan2 bug.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-03-03 17:00
    Thanks Duane,

    I acually read a tutorial for the hmc5883L becuase to see what I was getting myself in to. I didnt know if it needed to be calibrated or anything, im guessing no, from all the docs I read? It was geared twords Arduino though, as almost every tutorial is. They suggested using a website to find the magnetic declanation in your part of the world and adding that to your readings.

    The next tutorial they wrote was about using a 3 axis adxSomething accelerometer to do tilt compensation up to 40 degrees, but it was all wrapped up in a library with no usefull info, so i wasnt sure if a 2axis memsic would work. Funny it never mentioned the Z axis or using it for tilt. In reality I probably dont need to worry about anything over 20 degrees. So ill hook the thing up and play with it when i get there see what the real deal is with error from tilt.

    I have a 3 axis accelerometer I want to use in a controller at some point, then I have the memsic which ive been trying to figure out a use for, other than detecting stops/crashes.
Sign In or Register to comment.