View Single Post
  #19   Spotlight this post!  
Unread 14-02-2011, 14:56
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Encoders in Auto Mode

That's basically what the code is doing: drive until the encoder->GetDistance() say it has traveled 60 inches.
You could put the code in a function like this:
Code:
void DriveDistance(float targetDistance)
{
    float distanceTraveled = (leftfrontEncoder->GetDistance() +
                                     rightFrontEncoder->GetDistance() +
                                     leftRearEncoder->GetDistance() +
                                     rightRearEncoder->GetDistance())/4.0;
 
    while (distanceTraveled < targetDistance)
    {
        MecanumDrive_Polar(forwardPower, 0.0, 0.0);
    }
    MecanumDrivePolar(0.0, 0.0, 0.0);
}
But this function is blocking. You cannot do anything else why the while loop is waiting. Not to mention this will starve your watchdog although by calling the MecanumDrive_Polar function, you probably will feed the per motor watchdog for this year's WPI library. So it's better to do what I suggested in the previous post of checking the target distance in your autonomous loop.
__________________
Reply With Quote