View Single Post
  #1   Spotlight this post!  
Unread 16-01-2016, 14:35
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Question Using Encoder to Drive a Certain Distance

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);
		}

	}

Last edited by curtis0gj : 16-01-2016 at 15:33.
Reply With Quote