Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Encoder Help (http://www.chiefdelphi.com/forums/showthread.php?t=113968)

mgossman311 19-02-2013 16:00

Encoder Help
 
This year our team has decided to use the encoders. However I being one of two programmers for the team have never used the Java language and really need some help with programming the encoders.

shank948 19-02-2013 17:06

Re: Encoder Help
 
I might be able to help. What exactly do you plan to use the encoder for? PID? Distance tracking?
As a starting point you might look at 2013 Java FRC API, specifically the Encoder class.

mgossman311 19-02-2013 17:19

Re: Encoder Help
 
We're are using it to track a distance between the starting point of autonomous and as a reference when we go to shoot the frisbees. If you could help, that would be great.

BradAMiller 19-02-2013 21:13

Re: Encoder Help
 
You need to create the encoder objects using the constructor to provide port numbers:

Code:

Encoder enc;
    .
    .
    .
enc = new Encoder(3,4); // where 3 and 4 are the digital inputs for the 2 channels
enc.start();  // start the encoder counting
    .
    .
    .
int count = enc.get() // get the number of counts

The count will be the number of counts that the encoder object saw. If you know how many counts per revolution (CPR), and the wheel size, and (possibly) the gear ratio, you can compute how far you've gone in "count" counts.

There is a convenience method in the Encoder class that will actually return the distance traveled by the wheel (getDistance()). To use it you first have to first compute the distance traveled per pulse. When you have that number, call enc.setDistancePerPulse(distPerPulse) to "calibrate" the encoder object.

Does this help or are you still unsure?

Brad


All times are GMT -5. The time now is 10:07.

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