Shop OBEX P1 Docs P2 Docs Learn Events
[gyro] how to get the orientation — Parallax Forums

[gyro] how to get the orientation

solixsolix Posts: 7
edited 2011-04-25 05:10 in Accessories
Hello everyone,
I just bought a gyro and I finally made it work... But my problem is, it seems to give me the acceleration, not the position.
What I need actually is just a value that correspond to an angle. If it's horizontal I want a 0 if it's tilted 10 deg to the right I want x and if it's tilted 10 deg to the left I want -x.

I'v tried different things knowing that acceleration = speed' and that speed = position' :

dspeed = acceleration * dt;
speed = speed + dspeed ;
dx = speed * dt
x = x + dx

But this doesn't work...
Is it possible to get the angle ?

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2011-04-22 08:41
    A gyro gives you the rate of rotation. You would integrate this to get the angle. You need a reference to determine the absolute angle, and you will need to compensate for drift.

    An accelerometer gives you translational acceleration. You integrate this to get velocity, and integrate the velocity to get position. You can determine the vertical direction from the low-pass values from the accelerometer, unless you are constantly accelerating such as in a rocket.

    Do you have a gyro or an accelerometer? What device are you using?
  • solixsolix Posts: 7
    edited 2011-04-22 10:08
    I have a gyro : http://www.sparkfun.com/products/9165
    I have tried to integrate, but the problem is, even if I don't touch anythings, to value of the position keeps getting bigger and bigger...

    How can I "compensate for drift" ?

    Thanks for your help Hein ;)
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-04-22 10:53
    This gyro provides an analog voltage that you need to digitize. Assuming you are digitizing it correctly you will get a number that represents the rotational velocity. You can get the angle by integrating the velocity, but you need to subtract the DC bias from the velocity first. The computations would be something like the following

    sample := GetSample
    speed := sample - dc_offset
    dx := speed * dt
    x := x + dx

    You can measure the dc_offset when the gyro is not moving. You can compensate for drift by using a 2D accelerometer to determine the vertical/horizontal directions.
  • solixsolix Posts: 7
    edited 2011-04-24 11:05
    Thanks you very much Hein !
    I really appreciate your time ;) Your answer helped me a lot ! But my gyro is pretty cheap and I think the mesurement isn't great >< (the error is increasing in time)

    Thank you !
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-04-24 15:54
    I don't have any direct experience with the particular gyro that you are using, but the basic outline in the link below should still apply.

    http://forums.parallax.com/showthread.php?127868-Gyro-lisy300&highlight=gyro

    I don't hear this enough, so I will preach it again, and this especially applies to a sensor with a nature such as a gyro. The DATA that most people, round or truncate, might actually contain useful information, and if not dealt with properly can contribute to significant drift. In an ideal system, the LSB (Least Significant Bit should have a normal bias of 50%. External 'noise' will offset this bias, as well as even the circuit configuration. Each time you introduce a link in th system, such as converting from analog to digital), you introduce some additional amount of error to the system that can ultimately offset the bias. Over time this bias can be tracked and measured, and applied back into the system as a means of error correction. Perhaps the most maddening thing that a programmer can experience with a sensor such as a gyro, is the circular reference issues, and trying to wrap your head around that. The attached reference page explains in a way (I hope) that makes approaching this type of device less daunting.
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-04-25 05:10
    solix,

    Can you provide a description of your application? If you want to determine the angle over a long period of time you will need to compensate for the drift of the gyro by using an accelerometer or some other method to determine vertical. Depending on your application you could even use a suspended pendulum and some way to measure it's deflection. I don't know how many bits you're using on the the ADC for your gyro, buy you should use enough bits to get down into the noise level. Your DC offset should be accumulated to a greater precision than your ADC to reduce the drift due to the DC bias.

    Dave
Sign In or Register to comment.