Gyro Not Working

For our autonomous, we are using the gyro sensor. However, every time we run our autonomous, the gyro causes the robot to turn in different ways. What could be causing this?
Here is our gyro code:

void gyroTurn(int speed, int degs) {
	SensorValue(gyro) = 0;
	int ticks = degs * 10;
	while (abs(SensorValue[gyro]) < ticks * .6) {
	while (abs(SensorValue[gyro]) < ticks * .8) {
		autoTurn(speed * .8);
	while (abs(SensorValue[gyro]) < ticks) {
		autoTurn(speed * .6);
	autoTurnTime(-speed/2, 100);


Where autoTurn simply turns certain motors. The different while loops are to counter momentum.

The gyro may need some time to calibrate. Normally this would happen as soon as the sensor is configured, but you can force re-calibration as seen in

Try first inspecting your gyro behavior w/o turns. Set up data logging, keep the robot still and record the gyro value for a minute - you’ll see whether it is stable or drifts heavily.

You may also need to make sure the gyro is well isolated from vibrations (hint: 275-1029), using a short cable and avoiding interference from motor wires parallel to the gyro cable.

Are you treating your float and integer variables in a way that would prevent the results from getting rounded down? If a variable is an int, then something like ticks * .6 could get rounded down or even rounded to zero. If I’m not mistaken, ROBOTC is somewhat forgiving when it comes to mixing variable types, but you will still experience rounding errors.

Can you specify exactly what range of behavior you are having, maybe with a couple videos.

@tabor473 Unfortunately we can’t provide any video footage. However, the problems are very slight with a variance of 15-10 degrees.

Not a definitive analysis, but see this thread.