We improved out gyro performance doing two things:
1. We re-run the calibration code from the gyro constructor at the beginning of autonomous:
Code:
m_analog->InitAccumulator();
Wait(kCalibrationSampleTime);
INT64 value;
UINT32 count;
m_analog->GetAccumulatorOutput(&value, &count);
UINT32 center = (UINT32)((float)value / (float)count + .5);
m_offset = ((float)value / (float)count) - (float)center;
m_analog->SetAccumulatorCenter(center);
m_analog->SetAccumulatorDeadband(0); ///< TODO: compute / parameterize this
m_analog->ResetAccumulator();
2. We allow the driver to re-run this during play if the drift has gotten too bad. Even a 500ms calibration seems to give good results.
I think the culprit is lack of temperature compensation. The gyro specifically has a temperature output to allow compensation and that has not been implemented.
By delaying the calibration until the start of autonomous, we are allowing the gyro temperature to stabilize in the operating environment.
Note: we are actually programming in LabVIEW but the calibration code is basically the same and it's easier to post the C++ version.
Brad