# Gyro Angle calculations isn't precise?

I'm using this LISY300AL Gyro: DataSheet

But i cant get a precise data..

Here is my calculation:

    sensitivity = 0.716454545;
gyroRotation=gyroRotation+gyroRate*dtime1/1000;
gyroAngle = abs((gyroRotation - 360 * ceil(gyroRotation / 360))); // Round up between 0-360
dtime = millis() - stime; // millis() is the milliseconds since my controller started
stime = millis();


I dont get a precise angle, i move my object 90 degrees but the gyro drifts too much so it showes something else...

Maybe i'm doing something wrong ? or i should just add an Accelerometer to make it more precise ?

I didn't look at your datasheet, but cheap gyros (not 10s of 1000s of \$) inherently get a signal proportional to the rate of turning. To get angle, this must be integrated. Any error in the rate signal therefore accumulates over time. Cheap MEMS gyros have drift and accuracy such that angle is pretty meaningless after a few seconds.

Real mechanical gyroscopes work on a totally different principle which keeps the axis pointing in the same direction. These therefore provide true angle outputs, not angle rate of change, so are more useful for inertial navigation.

Accellerometers can give you absolute angle magnitude with respect to gravity if you know the object is not otherwise accellerating. However, that is only angle with respect to down. They won't help you determine angle of turning sideways, for example.

• Great explanation. Just wanted to comment that the LSM303 chip contains both an accelerometer and magnetometer and could be useful to get both pitch and heading. Pololu has a good module for Arduino. – geometrikal Nov 8 '11 at 7:09

In order to avoid this drift in my gyro, I added if statements to filter out the drift. Something like this:

if(abs(degrees(gyroRate[XAXIS]))>0.5)
rollAngle += degrees(gyroRate[XAXIS])*timeDiff/1000.00;
if(abs(degrees(gyroRate[YAXIS]))>0.5)
pitchAngle += degrees(gyroRate[YAXIS])*timeDiff/1000.00;
if(abs(degrees(gyroRate[ZAXIS]))>0.5)
yawAngle += degrees(gyroRate[ZAXIS])*timeDiff/1000.00;


So, when the gyro's rate is less than +/- 0.5 (usual drift of gyros) it will not update the the angle.