|
RoboJDETM v2.0 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
com.ridgesoft.robotics.AnalogShaftEncoder
public class AnalogShaftEncoder
Implements an incremental shaft encoder using a photoreflive or break-beam sensor to track the position of a wheel.
This class is designed to interface to an infrared photoreflective sensor, such as a Fairchild QRB1134 sensor, to sense the position of a wheel. Using its own thread, this class polls the sensor signal, counting the transitions between high and low values which occur each time the edge of a wheel spoke passes in front of the sensor. Because this class will count both edges of each spoke, the change in the counter value for each full rotation of the wheel will be equal to twice the number of spokes in the wheel.
By implementing the DirectionListener interface, this class is able to listen for changes in direction of the motor driving the wheel, enabling it to keep track of which direction the wheel is rotating. By counting up when the wheel rotates forward and counting down when the wheel rotates backward, this class is able to track the absolute position of the wheel as moves forward and backward.
Knowing the position of the wheels and the geometry of the robot, a program can keep track of the robot's position. This class can be used in conjuntion with the OdometricLocalizer class for position tracking.
This class implements a simple filter (hysterisis) to ensure small changes of the sensor signal due to noise will not be counted. This is accomplished by using separate thresholds to detect high to low signal transitions and low to high signal transitions.
This class uses its own thread to periodically poll the sensor signal. The accuracy of the encoder depends on the thread priority and polling period being set correctly.
This thread should normally be given a high priority. Running this thread at too low a priority may cause the encoder to miss signal transitions and, therefore, miscount. The priority should be higher than all other threads that depend on this encoder. Otherwise, the dependent threads could prevent this encoder from being accurate, undermining their own accuracy.
The polling period should be chosen such that the sensor is polled at atleast twice the frequency at which the encoder is expected to count. The polling period can be easily calculated knowing the maximum rotational speed of the wheel and the number of encoder counts per wheel rotation. Polling too frequently consumes computing power, leaving less computational power for other tasks.
OdometricLocalizer
Field Summary |
---|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
AnalogShaftEncoder(AnalogInput input,
int lowThreshold,
int highThreshold,
int period,
int threadPriority)
Constructs an AnalogShaftEncoder object. |
Method Summary | |
---|---|
int |
getCounts()
Gets the current value of the encoder counter. |
int |
getRate()
Not supported. |
void |
run()
Encoder thread's run method which polls the sensor and maintains the encoder's counter. |
String |
toString()
Returns a String containing the decimal value of the encoder counter. |
void |
updateDirection(boolean isForward)
Listener method to enable the encoder to know whether it should increment or decrement each time it senses a transition of the sensor signal. |
Methods inherited from class java.lang.Thread |
---|
activeCount, currentThread, dumpStack, getName, getPriority, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, setDaemon, setName, setPriority, sleep, start, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait |
Constructor Detail |
---|
public AnalogShaftEncoder(AnalogInput input, int lowThreshold, int highThreshold, int period, int threadPriority)
input
- AnalogInput to which the sensor is attachedlowThreshold
- value below which the sensor signal be considered to be lowhighThreshold
- value above which the sensor signal is considered to be highperiod
- sensor polling period in millisecondsthreadPriority
- priority of this threadMethod Detail |
---|
public int getCounts()
getCounts
in interface ShaftEncoder
public int getRate()
getRate
in interface ShaftEncoder
public void run()
Do not call this method directly.
run
in interface Runnable
run
in class Thread
public String toString()
toString
in class Thread
public void updateDirection(boolean isForward)
updateDirection
in interface DirectionListener
isForward
- true if the counter should increment, false if it should
decrement
|
RoboJDETM v2.0 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |