Go to Post Dave Lavery just responded to one of my posts. I think that I might die. - Karibou [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:43.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi