View Single Post
  #4   Spotlight this post!  
Unread 06-03-2014, 19:20
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,169
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Looking at the KOP Gyro

Enjoy - hope it helps!

Code:
    // gyro should be out of cal mode by now,
    // try to find and set best sensitivity
        
    for(uLoop = 0; uLoop < 10; uLoop++)
    {
        float fAngleSensitivity = Gyro::kDefaultVoltsPerDegreePerSecond;
        bool bLastAdjustmentWasIncrease;
        
        // reset the accumulator, stop a while and see if we drifted
        
        pGyro->Reset();
        taskDelay(sysClkRateGet() / 4);
        fAngle = pGyro->GetAngle();    
        
        if(fAngle > 0.0)
        {
            fAngleSensitivity -= 0.0001;
            bLastAdjustmentWasIncrease = false;
        }
        else
        {
            fAngleSensitivity += 0.0001;
            bLastAdjustmentWasIncrease = true;
        }

        pGyro->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;
        }    
    }
    
    pGyro->Reset();
    bCalibrated = true;
__________________
Fast, cheap or working - pick any two!
Reply With Quote