Hi I am looking for some resources and places to get start to use one encoder to drive a certain distance during autonomous. I found this link
http://wpilib.screenstepslive.com/s/...or-other-shaft. It has been slightly helpful with understanding how the encoder works and got me started. Here's what I have so far. Our team will be getting a second encoder soon, I hope I can still get this working with just the one encoder for now. Thanks!
Code:
public class Robot extends IterativeRobot {
RobotDrive tankDrive = new RobotDrive(0, 1);
Encoder encoder = new Encoder(0, 1, true, EncodingType.k4X);
double desiredDistance = 1;
public void robotInit() {
}
public void autonomousInit() {
/**
* What I want is for the robot to drive one foot. I am certain that I
* am going to have to do some calculations. We are using 8" pneumatic
* wheels.
*/
encoder.reset();
encoder.setDistancePerPulse(5);
encoder.getDistance();
}
public void autonomousPeriodic() {
double encodersReading = encoder.get();
tankDrive.arcadeDrive(0.25, 0);
if (encodersReading > desiredDistance) {
tankDrive.arcadeDrive(0, 0);
}
}