Hello,

I am using a gyro for the first time for making turns in autonomous. The code works perfectly when the target value is positive. I run into problems when the target value (Degrees) is negative.

int GyroLimit = 30;

int MSR; //Motor speed right side

int MSL; //Motor speed Left side

void GyroTurn(int Degrees){

```
while(1){
//less than target
if(abs(SensorValue[Gyro]) <= (Degrees / 2)){
//if far from target go fast
MSR = 75;
MSL = -75;
}else if(abs(SensorValue[Gyro]) > (Degrees / 2) && abs(SensorValue[Gyro]) < Degrees){
//once the robot gets closer slow down
MSR = 30;
MSL = -30;
}else if(abs(SensorValue[Gyro]) > (Degrees - GyroLimit) && abs(SensorValue[Gyro]) < (Degrees + GyroLimit)){
//stop if within target range
MSR = 0;
MSL = 0;
}
//greater than target
if(abs(SensorValue[Gyro]) > (Degrees * 1.5)){
//if far from target go fast
MSR = -75;
MSL = 75;
}else if(abs(SensorValue[Gyro]) < (Degrees * 1.5) && abs(SensorValue[Gyro]) > Degrees){
//once the robot gets closer slow down
MSR = -30;
MSL = 30;
}else if(abs(SensorValue[Gyro]) > (Degrees - GyroLimit) && abs(SensorValue[Gyro]) < (Degrees + GyroLimit)){
MSR = 0;
MSL = 0;
}
Checks();
motor[RightFront] = MSR;
motor[RightRear] = MSR;
motor[LeftRear]= MSL;
motor[LeftFront] = MSL;
}
```

}

I’m probably just over thinking it. Any help would be greatly appreciated.

Thanks in advance,

Kelton