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;
wait1Msec(1000);
//Reconfigure Analog Port 8 as a Gyro sensor and allow time for ROBOTC to calibrate it
SensorType[in8] = sensorGyro;
wait1Msec(2000);
Yes, I have cleared the sensor every time we run it. Honestly, the sensor is drifting far too fast to counteract it with any programming. It drifts like 100 per 10 seconds. Is this normal?
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.
int realBias;
long cumBias;
int i;
// Cause the gyro to reinitialize (a theory anyway)
SensorType[GyroInput] = sensorNone;
// Wait 1/2 sec
wait10Msec(50);
// improved bias setting
cumBias=0;
for(i=0;i<2000;i++)
{
cumBias = cumBias + SensorValue[GyroInput];
wait1Msec(1);
}
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.
Anyone know what deadband is used on the accumulator?
For a 12-bit ADC, I would put in something like 3-4 counts, maybe a few more if I was having issues.
If there is no deadband, I would not consider 1deg/sec drift unreasonable.
Remember that heading can also be calculated from a pair of drive encoders, and you can combine the driftless encoder heading with the higher resolution gyro heading to get a much better heading.
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.
Yes, however we do “clear” it every time we do a new drive “routine”. (Simply set it back to 0, and count from there, not completely re-calibrating the sensor.)