What is an Encoder?
What is an encoder?
An encoder can be defined as a sensor in which a light sensor is used in conjunction with a slotted disc in order to determine how far a rotational mechanism has turned. The slots in the disc either allow light to pass or block it, allowing the light sensor to send data to the microcontroller, which can add these pulses and determine mow many 'slots' the encoder has passed.
The VEX encoder
The internals of the VEX standard shaft encoder include the slotted disc and the light sensor. The disc has 90 slots, meaning that the encoder will make one 'tick' every 4 degrees.
The regular VEX encoder has a problem - due to its nature, it is impossible to tell which direction the slotted wheel is turning as it can only record a light reading of a 'slot' or a 'non-slot'. If the wheel was to turn the other way, the sensor will keep adding to the rotational value, giving the programmer very confusing values to work with.
The quadrature encoder
Luckily, VEX has recently released an upgrade to the standard encoder, called the Quadrature Shaft Encoder or Quad encoder for short. The quad encoder works essentially the same as the standard encoder, with one important difference - the quad encoder has two light sensors, offset in such a way that the encoder not only can determine the direction it is turning, but also can improve its accuracy four times, meaning it will count up one degree per tick.
How it works
Since the standard encoder has 90 slots in a disc, we can determine, then, that the disc has a 2° slot for every 2° of non-slot. If the wheel spins at a constant rate, the output values will look like this:
|Degrees||Light Value||Cumulative ticks|
If we use a Quadrature Encoder, where we have another light sensor offset by one degree, our values will look something like this:
|Degrees||Value 1||Value 2||Cumulative ticks|
This way, the microcontroller can distinguish between each individual degree, as well as being able to interpret the pattern to find the direction of rotation. This is much more useful to the programmer and it becomes easier to write powerful programs using the encoder.
The robot can determine the direction of turn by interpreting the signal as a pattern. Consider the pattern of a regular encoder:
Now, if the wheel is rotating backwards:
The pattern is the same, because it is read the same backwards as forwards.
When using the quadrature encoder, however, the pattern has much more information as the robot is now getting two bits of data.
See how the patterns are different? The robot can distinguish this and thus tell how whether the encoder is turning backwards or forwards.