View Single Post
  #16   Spotlight this post!  
Unread 14-02-2011, 13:57
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

No, you must call SetDistancePerPulse for all four encoders after they are instantiated (as part of the encoder initialization). The parameter to SetDistancePerPulse must be calculated or experimented. Basically, one revolution of the encoder will give you x pulses (I forgot what the KOP encoder is, probably 1440 pulses per revolution), then you have to multiply with the gear ratio if the encoders are mounted on the motor side instead of the wheel side.
Code:
Do this in your encoder intiialization:
distancePerPulse = (wheel_diameter*PI/pulses_per_revolution)*gear_ratio;
leftfrontEncoder->SetDistancePerPulse(distancePerPulse);
leftrearEncoder->SetDistancePerPulse(distancePerPulse);
rightfrontEncoder->SetDistancePerPulse(distancePerPulse);
rightrearEncoder->SetDistancePerPulse(distnacePerPulse);
 
Then do this in your autonomous loop:
double distanceTraveled = (leftfrontEncoder->GetDistance() +
                                     rightFrontEncoder->GetDistance() +
                                     leftRearEncoder->GetDistance() +
                                     rightRearEncoder->GetDistance())/4.0;
if (distanceTraveled < 60.0)
{
    MecaumDrive_Polar(forwardPower, 0.0, 0.0);
}
else
{
   MecaumDrive_Polar(0.0, 0.0, 0.0);
}
__________________
Reply With Quote