Shop OBEX P1 Docs P2 Docs Learn Events
Gyroscope L3G4200D — Parallax Forums

Gyroscope L3G4200D

kaydarakaydara Posts: 17
edited 2012-05-07 18:35 in Accessories
Greetings I'm new to the forum. I'mworking on autopilot, and I can not resolve a quaternion matrix does anyone know how to complete these parameters? ..also need to know,if the parameters with which tomultiply the cosine matrix are the integration o fan accelerometer? ..thank you very much.
matriz.jpg
acelerometer.jpg
1022 x 434 - 40K
1022 x 522 - 85K

Comments

  • SRLMSRLM Posts: 5,045
    edited 2012-05-05 22:19
    Well, to begin, a quaternion is not a matrix per se. It's a vector with four elements. Are you talking about a rotation matrix?

    In any case, your post needs a bit of work. You need to be much more clear on exactly what your question is, preferably with references and enough text to support your question.
  • kaydarakaydara Posts: 17
    edited 2012-05-05 22:51
    Sorry,what happens is that I am from Chile and not much use this language.I thank you for the answer, the more specific reference to this in manual number one gyroscopeL3g4200d, on page 37:

    http://www.parallax.com/portals/0/downloads/docs/prod/sens/27911-GyroscopeAppNote1.pdf
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-05 23:30
    I used to use rotation matrices a lot with computer animation. I understand a quaternion has advantages over a normal rotation matrix but I don't understand how to go from one to the other. I think we need to dig our our math books to learn how to do this unless someone else on the forum understands quaternions better than we do. Maybe SRLM?

    I'd also like to know where to look to understand the equations on page 37, kaydara just linked to. Does anyone know of a good place to learn about quaternions?

    I searched a while ago on the forums for information about quaternions without any luck.

    Kaydara, what controller or processor are you using with the L3G4200D?
  • kaydarakaydara Posts: 17
    edited 2012-05-05 23:35
    thanks for the reply, I'm using propeller, a pilot automatic
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-05 23:39
    kaydara wrote: »
    I'm using propeller, a pilot automatic

    I think the Propeller should be able to handle the math needed for this task. But as I mentioned above, I haven't found any Propeller software for computing quaternions. I think this would be a very useful feature to add to the Propeller's library of math functions.
  • kaydarakaydara Posts: 17
    edited 2012-05-05 23:53
    Duane Degn wrote: »
    I think the Propeller should be able to handle the math needed for this task. But as I mentioned above, I haven't found any Propeller software for computing quaternions. I think this would be a very useful feature to add to the Propeller's library of math functions.


    I agree
  • SRLMSRLM Posts: 5,045
    edited 2012-05-06 02:11
    Quaternions are rather simple, and the Propeller can handle them without any problem. All a quaternion needs is four floats. For angle updates it just takes some multiplies (12) and adds (8). In contrast, a rotation matrix or Euler angles require trigonometric functions for the update (==slower).

    I'm currently working on some code that uses quaternions on the Propeller, although I don't need to do much quaternion specific. The IMU I have produces quaternion output, and the algorithm that I am using uses quaternions natively. Basically all I need to write myself is the multiply and inverse. It's all in assembly.

    Note that linux (or at least Ubuntu 11.10) has libcqrlib2 "library for quaternion arithmetic and rotation math".

    For understanding quaternions, I found these resources helpful:
    http://www.gamedev.net/page/resources/_/technical/math-and-physics/quaternion-powers-r1095
    http://www.tobynorris.com/work/prog/csharp/quatview/help/orientations_and_quaternions.htm
    www.geometrictools.com/Documentation/Quaternions.pdf
    gamma.cs.unc.edu/courses/planning-f07/PAPERS/quaternions.pdf
    www.cs.ucr.edu/~vbz/resources/quatut.pdf
  • SRLMSRLM Posts: 5,045
    edited 2012-05-06 02:24
    kaydara wrote: »
    Greetings I'm new to the forum. I'mworking on autopilot, and I can not resolve a quaternion matrix does anyone know how to complete these parameters? ..also need to know,if the parameters with which tomultiply the cosine matrix are the integration o fan accelerometer? ..thank you very much
    matriz.jpg
    acelerometer.jpg

    In answer to your original question, x_b, y_b, and z_b is a vector in three dimensional space. The _b subscript denotes that it is in reference to the body, although note that the ' mark nullifies that. Equation 10 is simply rotating the axes through the three angles. (ps: note all the trig functions. yuk!)

    In equation 14, a,b,c,d are from the quaternion that represents the starting angle (before the rotation). The equation comes from the derivative of a quaternion, and is how you rotate a quat based on angular rate (not amount). The dot over the q denotes the derivative of the quaternion. Note that in quaternion calculus, the derivative results in another quaternion.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-06 08:14
    Thank you SRLM for all the information on quaternions.

    I'm pretty sure I used them in at least one of my math classes, but I've never used them since.

    I used to use rotation matrices with computer animation but so far with the Prop, I've only need to rotate one axis at a time (as in a hexapod) and there are usually faster ways to compute angles than using a rotation matrix.

    While Equation 10 has a lot of trig functions, the same function is used many times. It wouldn't take as long to calculate as it first appears. (I'm sure you already know this, I just don't want others to be completely scared of a rotation matrix.)

    I don't suppose you've posted any of your quaternion code? If not, is it something you'd be willing to do? "No" is a very acceptable answer; I just thought I'd ask.

    Thanks again for all the links to quaternion sites and for your explanations.
  • SRLMSRLM Posts: 5,045
    edited 2012-05-06 10:40
    Here's a rough calculation for the speed of equation 10 vs equation 14, done with the float32 library.
    op --- time (uS@80Mhz)
    cos - 98
    sin - 93
    add - 5
    mul - 11
    
    I count the following:
    op --- number of ops
    cos - 3
    sin - 3
    add - 4
    mul - 13
    
    
    3*98 + 3*93 + 4*5 + 13*11 = 736 uS
    
    That's just to make the matrix. To multiply the matrix and the vector, you need:
    op -- number of ops
    add - 6
    mul - 9
    
    6*5 + 9*11 = 129 uS
    
    736 + 129 = 865 uS total to update the rotation matrix.
    

    That's quite a hefty penalty, especially when compared to a quaternion rotation update:
    (a quaternion multiply is used to rotate)
    op --- number of ops
    add - 12
    mul - 16
    
    12*5 + 16*11 = 236uS total to update the orientation
    

    Anyway, I'm still working on the code, and not ready to release it yet. Like the OP I too am working on an autopilot :) It's taken me months to get all the math down.

    Matrix refresher: http://www.facstaff.bucknell.edu/mastascu/elessonshtml/Circuit/MatVecMultiply.htm

    Here is a little spreadsheet I wrote to calculate the parameters of a control loop for an autopilot: fp speed calculator
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-06 11:16
    I think it's pretty cool the Prop can do all that in 865us.

    I was pleasantly surprised to find the Prop could handle IK calculations for all 18 servos of my hexapod within a servo's 20ms refresh period.

    Besides the speed advantage, I understand quaternions aren't susceptible to the same axis cancellation problems that can happen with rotation matrices.

    I'm not right ready to work on my autopilot (I wonder if all forum members are secretly working on one), but when I do, I'll need to get these quaternions figured out for myself.
  • kaydarakaydara Posts: 17
    edited 2012-05-06 16:00
    SRLM wrote: »
    In answer to your original question, x_b, y_b, and z_b is a vector in three dimensional space. The _b subscript denotes that it is in reference to the body, although note that the ' mark nullifies that. Equation 10 is simply rotating the axes through the three angles. (ps: note all the trig functions. yuk!)

    In equation 14, a,b,c,d are from the quaternion that represents the starting angle (before the rotation). The equation comes from the derivative of a quaternion, and is how you rotate a quat based on angular rate (not amount). The dot over the q denotes the derivative of the quaternion. Note that in quaternion calculus, the derivative results in another quaternion.


    thanks for your answer.then in equation 14. The parameters a-b-c-d, representing the initial angle, do I get data integrating gyroscope or accelerometer?, although logic by integrating the gyroscope data would have to give me certain angles, I'm not sure.
  • SRLMSRLM Posts: 5,045
    edited 2012-05-07 15:05
    kaydara wrote: »
    thanks for your answer.then in equation 14. The parameters a-b-c-d, representing the initial angle, do I get data integrating gyroscope or accelerometer?, although logic by integrating the gyroscope data would have to give me certain angles, I'm not sure.

    The initial reference is whatever you want it to be. At power up, the system does not know what it's initial orientation is. Usually it doesn't really matter too much if all you want to do is stay level. If you do need your world referenced orientation, you can use your magnemometers to determine yaw (via north), and your accelerometers to determine pitch and roll (via gravity vector). This assumes that you are powering on while stationary.

    As a side note, a-b-c-d does not represent the "initial angle" per se, but rather the initial orientation. In any case, I admire you for learning all this in a non-native language.

    Integrating the gyros will give you an angle, but it's not reliable over long periods of time. That's why you need some sort of filter to add in the long term stability of other sensors. Typically this is done with either a Kalman Filter (hard) or Direction Cosine Matrix (easier).
  • kaydarakaydara Posts: 17
    edited 2012-05-07 18:35
    SRLM wrote: »
    The initial reference is whatever you want it to be. At power up, the system does not know what it's initial orientation is. Usually it doesn't really matter too much if all you want to do is stay level. If you do need your world referenced orientation, you can use your magnemometers to determine yaw (via north), and your accelerometers to determine pitch and roll (via gravity vector). This assumes that you are powering on while stationary.

    As a side note, a-b-c-d does not represent the "initial angle" per se, but rather the initial orientation. In any case, I admire you for learning all this in a non-native language.

    Integrating the gyros will give you an angle, but it's not reliable over long periods of time. That's why you need some sort of filter to add in the long term stability of other sensors. Typically this is done with either a Kalman Filter (hard) or Direction Cosine Matrix (easier).

    thanks SRLM, the truth is there is a forum parallax Spanish, but I have not answered these questions as necessary.
Sign In or Register to comment.