Thread: encoders
View Single Post
  #3   Spotlight this post!  
Unread 05-02-2007, 10:26
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 590
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: encoders

Quote:
Originally Posted by benjamin1748 View Post
I was working on a program using the encoders to get my robot to drive straight. I ran into a problem. When I tried to get my wheels to drive at the same speed they would slow down, speed up, and would repeat this until they stopped. If looked as if the wheels were playing catch up. Does anyone know a solution or have any helpful advice on how I should go about this problem?
If the problem isn't related to PID stuff - another easy way to use encoders to drive straight is using this algorithm:

Code:
error = GetEncoder(LEFT_ENCODER) - GetEncoder(RIGHT_ENCODER);
Drive(speed, error);
The Drive function (either from the easyC samples or built in to WPILib) takes a speed and direction. When you are driving straight, the wheel counts will be the same on the two wheels. If the count is different, you need to speed up either the right or left wheel. The amount of the correction is proportional to the amount of error.

A few implementation details:
1. You should make sure that the sign of error matches your robot.
2. You should probably limit error so the robot doesn't make wild turns.
3. You might want to stick this into a function, like DriveStraight where the encoder counts are reset at the beginning of the straight driving segment.
4. The drive function simply sends speed+direction to one wheel and speed-direction to the other wheel, so make sure that they don't exceed +/-127 since that's all the range that speed controls have.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute