I have recently tried to do a 90 degree right turn using the yaw rate gyroscope. It didn’t work, and after writing the values to the lcd display, I found that instead of reading 900 tenths of a degree, it is reading 1800. The values on the gyro go from 1 - 3600 in 180 degrees, not 360. How would I go about fixing this problem?
When coding for our gyros we found that they had some inaccuracy (around 20 degrees of offset for five rotations) so we multiplied the difference in the current and previous gyro values, and added this new value to the previous total direction. If your gyro is reading double the actual angle, then multiply by 0.5:
#define GYROOFFSET 0.5
Float truedirection = 0;
Float lastgyro = 0;
Float difference = 0;
Difference = SensorValue(gyro) - lastgyro;
Difference = difference * GYROOFFSET;
//if you want true direction to read the angle in degrees then uncommercial next line
//difference = difference / 10;
truedirection = truedirection + difference ;
Lastgyro = sensorValue(gyro);
I just wrote this quickly so it may not work exactly, but it should be ok to fix your problem, then you just use truedirection wherever you would read the gyro value.
To find our offset value we spun the robot round 5 times (1800 degreses) and divided the gyro value by 18000.;
For you it would be 3600/1800 (3600 tenths of a degree for every 180 degrees of rotation) meaning OFFSET would be 0.5.
For us this gave us about 1.012, but it’s different for each gyro (we use two) also it may be different based on which direction you turn it… we use two offset values, and just check if difference is + or - to see which offset value to use.
Hope this is helpful!