I shouldn't even be writing this, but i felt like i needed to. The second topic in this forum asks the exact same thing (found here:
http://www.chiefdelphi.com/forums/sh...ad.php?t=23268) and i gave them the following response:
Quote:
|
Originally Posted by myself in another forum
one piece of advice, before bringing up something that is not completely obscure, search the forums and also just go the the appropriate forum and make sure to change the start date from one week to one year or something along those lines. here's one forum on gyroscopes and C and the like:
http://www.chiefdelphi.com/forums/sh...ad.php?t=23071
|
I cannot say it enough, search, search, search!
As i just realized though, that doesn't give autonomous code. All a gyro can really do is tell you which way you're pointing, nothing more. So there really is no way to give sample code except for the following which just integrates the gyro output to give you one number which shows how far you've turned.
Code:
int theta=0; //in global variables
// from here on in autonomous section or what have you
signed char gyro = (GYRO-127)*G_ADJUST; //GYRO being the macro for wherever your gyro is attached
//and G_ADJUST is a constant to adjust to degrees
if (theta+gyro>=360) //rolling from 359 to 0 and around again
theta+=gyro-360;
else if (theta+gryo<0) //rolling from 0 to 359 and around again
theta+=gyro+360;
else
theta+=gyro;