I have a DriveForDistance method that uses encoders. I'm assuming you're using command based. Think of what you want to do:
1. Clear the current count of the encoders
Code:
I recommend you create a method in your driveTrain called clearEncoders():
public void clearEncoder() {
_leftEncoder.reset();
_rightEncoder.reset();
}
While you're in your drive train subsystem, go ahead and create getter methods for your encoders.
public double getRightDistance() {
return _rightEncoder.getDistance();
}
In your initialize, you want to clear the encoders.
In your execute, you want to tell the motors to go the appropriate direction that the robot should be moving.
In your isFinished:
Code:
// code from Joe 2729
double left = Robot._driveTrain.getLeftDistance();
double right = Robot._driveTrain.getRightDistance();
double distance = Math.abs(left) > Math.abs(right) ? left : right;
if(_forw) {
return distance >= _distance;
} else {
return distance <= _distance;
}
That's how the general layout of your program should be if you want to drive for a distance.