How can i write a turning function using the gyro in conjunction with jpearmans gyro code for absolute gyro value.
Here is jpearmans code:
using namespace vex;
brain Brain;
gyro Gyro1( Brain.ThreeWirePort.A );
int absGyroValue = 0;
void
gyroChanged() {
static int lastValue;
// get gyro value as 1/10 deg
int value = Gyro1.value( analogUnits::range12bit );
// calculate change in gyro value
int delta = value - lastValue;
lastValue = value;
// delta should be small, did we overflow gyro value
if( delta > 1800 )
delta -= 3600;
if( delta < -1800 )
delta += 3600;
// add change to absolute value
absGyroValue += delta;
}
void
gyroReset() {
absGyroValue = 0;
}
void
screenPressed() {
gyroReset();
}
int main() {
Gyro1.changed( gyroChanged );
Brain.Screen.printAt( 10, 180, "Touch screen to reset" );
Brain.Screen.pressed( screenPressed );
while(1) {
Brain.Screen.printAt( 10, 50, "Gyro raw %6d ", Gyro1.value( analogUnits::range12bit ) );
Brain.Screen.printAt( 10, 70, "Gyro abs %6d ", absGyroValue );
// Allow other tasks to run
this_thread::sleep_for(10);
}
}