## Friday, December 17, 2004

[ This post is echoed on http://www.tedpavlic.com/post_quadrature_encoder_comments.php , except A USEFUL EXAMPLE IS GIVEN THERE ]

So, as usual, with the upcoming FIRST season, I've gotten questions about quadrature encoders. And as usual, like everyone who has either just learned about quadrature encoders or simply has known about them for a long time but never used them, the people who come to me with these questions are extremely excited about these things. Some of them seem to even approach me as if I've never heard of them or had to use them. I know plenty about quadrature encoders, and I know that sometimes the best idea is not to use them.

ContentsSome Background

So I wanted to leave a few words here about quadrature encoders. I especially want to stress that they are not always necessary, especially when used as feedback for drive actuators, and if you absolutely need them, don't take for granted that you can build your own pretty easily.

An example of a commercially built quadrature encoder is given here:

Grayhill Series 25L Mechanical Quadrature Encoder

Shaft Encoders

A shaft encoder is used to convert rotations of some output shaft into information buried on top of a signal that can be read and processed by a computer. That computer then has some idea of the position of the output shaft.

For example, imagine a spinning disk with slits cut in it at regular intervals. Let's say that the cuts in the disk have an equal arc length as the space between them. As the shaft spins, so does the disk. Now imagine a beam of light positioned perpendicular to the disk. The beam shines through the disk. On the other side of the disk is a sensor that generates a high signal (call it a 1) whenever light hits it. When no light hits it, it generates a low signal (call it a 0). So as the disk spins it either blocks the light or lets it pass. And thus, if the shaft is spinning at a constant speed, the light sensor generates a periodic square wave (...01010101...).

If you can assume that the shaft only spins in one direction, waiting for the next transition (from 0 to 1 or from 1 to 0), it's pretty easily to estimate how far the shaft has rotated. If your shaft is turning a drive wheel, you can thus determine how far you've driven. Of course, you still don't know anything about direction. You could be rotating backwards, forwards, or be changing direction constantly. You simply don't know.

So came things like the quadrature encoder. There's lots I can say about quadrature encoders. I'll leave that for a whitepaper I'll put together later. But let's continue the above example to try to illustrate the idea.

Imagine that your first disk is somewhere near the middle of the shaft. Imagine that the light source and light sensor simply straddle that disk. Now imagine you put a second disk away from the middle of the shaft. Again, put a second sensor stradling the disk. Make sure the second disk is aligned perfectly with the first disk. That is, when looking down the shaft, the disks line up. However, put the second sensor half a cut-out-arc length away from the other sensor. In other words, if the cutouts in the disk span 30 degrees of the circular disk, the sensors are placed 15 degrees apart.

So now rotate the shaft as before at a constant rotational speed. Call the first sensor A and the second sensor B. We then get this waveform out:

 A: 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 ... B: 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 ...

This can be depicted graphically as:

So the two waveforms are identical, but the B waveform is shifted a little to the left.

Now, notice that moving either left-to-right or right-to-left, only one bit (either A or B) changes at a time. Only one bit.

But notice something else. Notice that if you know what state you were previously in, you can decipher what direction you moved. If A did not change, but B changed to match A, then you KNOW that you might be moving from RIGHT-TO-LEFT. Likewise, if B did not change, but A changed to match B, you know you must be moving from LEFT-TO-RIGHT.

It's a beautiful way of deciphering both DIRECTION of rotation AND angular position.

Now, if your motor is coupled to an arm by some flexible member, like a spring, then the arm can move relative to the motor. It's not a rigid connection, thus knowing something about the motor's movement does not give you a whole lot of information about the actual arm movement. Thus, coupling the arm's rotational axis with a quadrature encoder allows us to find how the position of the arm moves with respect to the motor. We can use this feedback to move the motor so that it ends up also moving the arm where we want the arm to move.

Now, let's say we're talking about drill motor. Let's say we're talking about a drill motor that has been severely geared down so that many rotations of the motor cause few rotations of the output. Now let's say the output is a wheel. That wheel rotates freely and ends up moving a robot forward and backward.

There is nearly no way to back drive that motor from the wheel. It requires a great deal of force to rotate that wheel even when the motor is not being driven. If the motor is rigged for dynamic braking, and the leads are shorted together, it is even harder to rotate that wheel. Finally, if the motor is being driven in a particular direction, it will be nearly impossible to rotate that wheel manually in any direction but the direction corresponding to the motor's rotation.

And yet people feel like it's necessary to take the time to put a quadrature encoder on their drive shaft. IF the system rotates at all, it will only be due to rotation of the motor. If that robot is ever driven backwards, it will be due to slipping on the ground and not due to rotation of the wheel.

The Moral of the Story Is...
• So I contend that it is SILLY to use quadrature shaft encoders on drive shafts. If there's any direction, it will be in the direction of the DRIVEN rotation, which is also known a priori.

• And I also think it's silly to attempt to buy your own quadrature encoders and find some crazy way to couple them to a drive shaft when you can just build your own. If you're careful, you can build your own for a measily \$10 from RadioShack.

• And finally, if you're going to gear down your motor anyway, PUT THE ENCODER CLOSER TO THE MOTOR. It GREATLY INCREASES YOUR RESOLUTION.