Let's Make Robots!

Quadrature Encoders


Vendor's Description: 


Isn't that just a pot?

You are forgiven for thinking you are looking at a photo of a potentiometer AKA variable resistor. That's what this looks like. However, if you were to rotate the shaft, you'd very quickly find out that there are no endstops. It just keeps going round and round.

A quadrature encoder is a non-absolute type of rotary encoder. That is to say it cannot tell you its current position, but it can be used to deduce how far it has been rotated from its start point (which is why it is also sometimes known as an incremental encoder).

This makes it the least expensive, most easy to use sensor to tell you how far your robot has travelled and at what speed. Anyone who is familiar with Lego RCX will be familiar with this type of sensor. Anyone who remembers the days when PC mice had balls will have used these sensors (perhaps unknowingly).

Mechanical ones...

In the mechnical variant of the rotary encoder, what you have is a set of contacts arranged in a circle and a pair of wipers which touch these in turn as they rotate. If you know how many "switches" there are in the full circle, that information alone is sufficient for you to derive the speed of you bot. HOWEVER, these little dandies have PAIRS of switches arranged such that one contacts fractionally before the other. This can be used to derive direction information.

There are three contacts. On mine, the centre pin is common and the two outer pins are the contactors. As the shaft rotates, the circuit between common and pin A repeatedley opens and closes. The sensor shown has 30 contactors in a full turn: that's 12 degrees per output pulse. Plenty for most purposes. In addition, though, if the shaft is turning anticlockwise, there is a pulse on pin B just before that on pin A. If the shaft is turning clockwise, there is a pulse on pin B just after that on pin A. (Of course, you'll already KNOW what direction your wheels are going, because you programmed your motor controller, so why bother with this added complication...?)

There you have it. The worlds cheapest rotation sensor. I don't know why more people don't use them. One thing a lot of you seem to want to do is go in a straight line. These can be used as the feedback in a closed loop (AKA PID) system. Of course they don't guarantee you're goin in a straight line because the friction between the ground and the wheels might be unequal and stuff, but they could be used to attain equal motor speeds.

If you're sourcing these sensors, try to get "zero detent" variations. That means they don't have "detention points" (the volume control on your car stereo is probably one of these: notice the way it mechanically clicks around as you turn it). Coming out of the detention adds an unneccessary load to your motor.

Be careful not to rotate these too fast. Or rather, make sure your code is adjusted to cope with a "typical" speed. If a sensor has 30 switches per revolution, and you're polling it 30 times per second and your shaft is rotating at 1 revolution per second, the switch will, obviously, alway appear to be in the same state. The state is, of course, changing between polls, but your MCU desn't know that!

Oh, and you need to debounce them as well.

Optical Ones...

See here.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Nice tutorial! Quadrature encoders are really nice sensors to add to a robot, since you can do position estimation, speed/acceleration regulation, straight line regulation and other nice stuff with them.