This is going to be a long post. I’m trying to target this post at relative newbies, so if any of this is old news feel free to skip to the good parts.
(Since this got long, I’ll break it into two posts: the first will be explanation (the "why), and the second will be the “how” part.)
The vast majority of gyro “drift” is usually due to a poor voltage bias calculation.
What is this “bias” that you speak of? The sensor outputs a voltage relative to the angular rate (these devices are angular rate (speed) sensors, not heading sensors). The voltage when still (angular rate = 0) is typically around 2.5V for a 5V sensor, but in reality that can vary for many reasons. Therefore, the software always needs to calculate the voltage bias before using the angular rate to compute a heading. The bias is used by subtracting it from each sample before computing the heading. Thus, after the “bias subtraction”, the sensor output is transformed from 0 - 5V to approximately -2.5 - +2.5V.
How is the bias typically calculated? The bias is calculated by averaging a number of samples when the software thinks the gyro is still. The WPI gyro software performs this calculation as soon as the software begins to run. Any movement of the robot just after power-on until the bias calculation is finished will cause your bias to be bad, and you will get a large gyro drift. “When is the WPI code finished calculating it’s bias so we know it’s safe to move the robot?” you ask. Good question. I don’t really know, which is one of the reasons we don’t use it. Another reason we don’t use it is because we find it nearly impossible to keep the robot perfectly still immediately after power on.
Can the bias of the gyro drift? The short answer is yes. If you calculate a good bias, and then the bias changes, your heading will drift over time. That’s not good.
What causes the bias to drift I don’t want to repeat a good post: see Jared Russell’s post above. One important I’ll repeat: the bias is likely to drift as the gyro warms up. Therefore, in an ideal world you would like gyro to be at its steady-state before calculating the bias. The WPI code does this immediately after power-on so the likelihood of bias drift is much higher than if you could wait.
Ok, then in your opinion when should the bias be calculated There are 3 main criteria for me: 1) The robot MUST be PERFECTLY STILL; 2) The gyro should be at steady state; and 3) The bias calculation should be performed as close as possible to the time your are going to start using it (in other words, a bias calculation from 5 minutes ago is much less likely to be accurate than a bias calculated 1 second ago).
So when do YOU calculate the bias? Simple answer: the instant before the match begins. This ensures it satisfies all three criteria: 1) the robot will be perfectly still since all humans have to be off the field or someone is getting DQ’d; 2) The gyro should be at steady state since it has been a few minutes since power-on; and 3) the instant before the match starts is as close as you can get to when you start using the bias.
What are the disadvantages of your method? The WPI gyro code can’t be used, and you have to write all of your own software.