I’m not sure if this is a common problem, but our gyro seems to be constantly drifting. I read the “Gyro Sensor Drift” thread but in their case they only encountered drifting of about 50 units, but our sensor is just constantly drifting in one direction. I left it on for about 2 minutes sitting still and it drifted all the way to upwards of 3000. I have not even added much code either. I have the gyro plugged into analog port 7 and just have this:
and in the debugger window the sensor readings just constantly change. Another peculiar thing is that when the sensor is unplugged, the debugger window still has the values drifting upward, but at a slower pace. Any thoughts?
The drift is slower than the robot can possibly turn. Therefore, you can run a task in the background to keep track of turns that are really slow. This could be considered the error, and subtracted from the gyro reading…
What we did to help with this was clear the sensor every time we ran the robot. It can add to the time it takes for your robot to start up, but it has greatly helped with ours, and kept it from being too crazy:
//Completely clear out any previous sensor readings by setting the port to "sensorNone"
SensorType[in8] = sensorNone;
//Reconfigure Analog Port 8 as a Gyro sensor and allow time for ROBOTC to calibrate it
SensorType[in8] = sensorGyro;
1 deg per second is not normal. Drift occurs due to noise on the A-D input, how long are the wires to the gyro? Do the wires pass any noise generating components? ie. motors. You could try calculating your own bias in this way.
// Cause the gyro to reinitialize (a theory anyway)
SensorType[GyroInput] = sensorNone;
// Wait 1/2 sec
// improved bias setting
cumBias = cumBias + SensorValue[GyroInput];
realBias = cumBias / 2000;
// Gyro should be motionless here
SensorType[GyroInput] = sensorGyro;
// Now put the bias back to the correct value we found in the initialization
SensorBias[GyroInput] = realBias;
and then compare with the bias RobotC is calculating, in my case there is not much difference.
Why are you using a SensorScale of 400? default is 130 and should work correctly.
That is what I normally had before I added the clearing code. Now many times it will stay at 0, or between 1 and -1. Just before I added the sensor clearing code to our program, the Gyro was scrolling through values very quickly. It got to 3600 in a couple seconds or so. That was when I knew I needed to clear the sensor every time. I haven’t had any problems at all with it since.