Thread: Encoder Help
View Single Post
  #4   Spotlight this post!  
Unread 19-02-2013, 21:13
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 588
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
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
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote