View Single Post
  #8   Spotlight this post!  
Unread 18-03-2015, 15:53
SuperBK's Avatar
SuperBK SuperBK is offline
Registered User
AKA: BrianK
FRC #1225 (Amperage Robotics)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Henersonville, NC
Posts: 358
SuperBK is just really niceSuperBK is just really niceSuperBK is just really niceSuperBK is just really nice
Re: Large amounts of gyro drift

Here is some calibration code I found here on Chielf Delphi. It basically involves adjusting the sensitivity with the gyro sitting still so that it doesn't change. It seems to help, although I don't know how accurate it was after changing the sensitivity.

Code:
	void CalibrateGyro()
	{
		// gyro should be out of cal mode by now,
		// try to find and set best sensitivity

		float fAngle;

		for(int uLoop = 0; uLoop < 10; uLoop++)
		{
			float fAngleSensitivity = Gyro::kDefaultVoltsPerDegreePerSecond;
			bool bLastAdjustmentWasIncrease;

			// reset the accumulator, stop a while and see if we drifted

			gyro.Reset();
			// taskDelay(sysClkRateGet() / 4);
			Wait(.001);

			fAngle = gyro.GetAngle();

			if(fAngle > 0.0)
			{
				fAngleSensitivity -= 0.0001;
				bLastAdjustmentWasIncrease = false;
			}
			else
			{
				fAngleSensitivity += 0.0001;
				bLastAdjustmentWasIncrease = true;
			}

			gyro.SetSensitivity(fAngleSensitivity);

			if((fAngleSensitivity > 0.0) && (bLastAdjustmentWasIncrease == false))
			{
				// we were adjusting up then went down a step - good enough
				break;
			}
			else if ((fAngleSensitivity < 0.0) && (bLastAdjustmentWasIncrease == true))
			{
				// we were adjusting down then went up a step - good enough
				break;
			}

			if((fAngleSensitivity >= (Gyro::kDefaultVoltsPerDegreePerSecond + 0.0008)) ||
					(fAngleSensitivity <= (Gyro::kDefaultVoltsPerDegreePerSecond - 0.0008)))
			{
				// the next number would be outside any reasonable value according to the datasheet
				break;
			}
		}

		gyro.Reset();
	}
__________________
Brian K
Team 1225 Robotics Mentor