Quote:
Originally Posted by tseres
kevin.org/frc download the encoder file and read everything in there
|
Bingo! If you follow this link, you will find everything you need to know. Kevin Watson is a resource for code that is AMAZINGLY well documented. That is the place to start. Personally I believe he has contributed more to learning coding for sensors than just about anyone else in FIRST.
Quote:
Originally Posted by programmr
i know neither.. could you please help?
|
Quadrature encoders have two outputs. Both are 50% duty cycle square waves and are usually referred to as Phase A and Phase B. Phase B usually lags behind A by 90 deg.
Typically Phase A is used as a trigger, or more specifically, tied to an interrupt on the RC. When the "trigger", or interrupt, takes place, an IRS (Interrupt Service Routine) looks at Phase B. If B is high, the ISR increments the content of a counter, if B is low, the counter is decremented. Incrementing or decrementing can be swapped easily by modifying the code. Usually incrementing means you are moving forward, decrementing means reverse, but again, you can determine in code what you want it to represent.
Now, the value in the "counter" represents a unit of measure. The measurement it represents is determined by what it is physically driven by. Lets just use the output of a transmission as an example. Let's also assume we are using a 100 count per revolution encoder. The output shaft has a 15 tooth sprocket on it and it is driving a 6 in. dia. wheel with a 22 tooth sprocket on it. Here is the math.
Pi*D=18.85 in. per wheel revolution
22/15=1.466 revolutions of the encoder per wheel revolution.
100*1.466=146.6 counts per wheel revolution.
18.85/146.6 = .129 inches of travel per count from the encoder.