# When do I need to care about quadrature?

Could someone give me examples of where they are using information from quadrature encoders on a motor?

I am setting up a Rover 5 and am not sure why I would connect the quadrature pins (at the moment at least).  From my reading it seems that you use quadrature to determine: speed of rotation and direction of rotation (and possibly orientation of the shaft/distance travelled?)  Is there more to it that I'm missing?

Thanks

B

## Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Most important is the capability to let the robot go straight in one direction. Robots without encoders will tend to drift in one direction.  Instead of changing the PWM of the motors to speed up or slow down you can write functions:

• to let your robot drive with a constant speed like encoderticks per second, centimeters per second, mph, kmh...,
• or drive a curve with a known diameter,
• make a turn of xxx degrees.

To get the direction the wheels moved out of a quadrature encoder is useless, because you the programmer controls the direction with your program.

One advantage of using quadrature encoders instead of normal encoders is the capability to detect glitches in the encoder signal. Because the quadrature encoder gives you a 2bit gray code yo can use a simple 4 state machine to detect glitches.

An example for using QE can be found in my Arduino timer tutorial. I'm using this technique with my Ardubot  for the write LMR challenge. This example should work with the Rover 5, too.

> Most important is the capability to let the robot go straight in one direction. Robots without encoders will tend to drift in one direction.

Ah....  I guess I would have run into that problem in time.

I don't get how you can use them to drive at constant speed.  Do you monitor them and turn the motors off?  Scale the pwm on the drive pin?

Sorry for not responding sooner, didn't see this post.

Thanks!

What options you have available depends on your motor driver, but scaling the PWM would be an easy approach.

If Motor A runs at 90% the speed of Motor B when the PWM values are the same, scale the PWM values for Motor B down to 90% of what you're sending to Motor A, that sort of thing.

If you want something a bit smarter you can opt for a PID control loop to adjust the PWM based on your target speed vs. feedback from the encoder.

Do motors tend to vary consistently?  ie if they are out by 10% at pwm = 40 will they be out by 10% at pwm=220?

The short answer? Sometimes they'll be consistent, but it all depends on the motors in question.

If you don't have encoders then you'll have to trial the motors at different speeds to get it right, otherwise you can have the program take care of it automatically using the encoder feedback.