(SLOT, ROTARY, LINEAR)
The Robot Encoder - What is it?
A typical encoder uses optical sensor(s), a moving mechanical component, and a special reflector to provide a series of electrical pulses to your microcontroller. These pulses can be used as part of a PID feedback control system to determine translation distance, rotational velocity, and/or angle of a moving robot or robot part.
For instance, if you have a wheel rotating, and you want to measure the time it takes to rotate exactly 40 degrees, or know when you have traveled X distance, you would use an encoder. The sensor would be fixed on your robot, and the mechanical part (the encoder wheel) would rotate with the wheel. The output of an encoder would be a square wave, so if you hook up this signal to a digital counter or microcontroller you can then count the pulses. Knowing the distance/angle between each pulse, and the time from start to finish, you can easily determine position or angle or velocity or whatever. Encoders are necessary for making robot arms, and very useful for acceleration control of heavier robots. They are also commonly used for maze navigation.
Calculating Robot Motion with an Encoder
To do this calculation you need more information, such as wheel diameter and encoder resolution (number of clicks per 360 degrees, or counts per revolution). I highly recommend reading the first half of my Robot Dynamics tutorial before continuing on to understand how wheel diameter relates to robot speed.
Starting off, you should know two things - wheel circumference and counts per revolution. Dividing the two, you can easily figure out the distance your robot travels between each encoder click:
wheel circumference / counts per revolution = distance traveled per encoder count
Now velocity is just distance divided by time . . . So using the answer in the above equation, divide that by the time passed determined from your microcontroller timer:
distance traveled per encoder count / time = velocity
After you know distance and velocity, you must then run a PID feedback control algorithm so that your robot can match a desired (pre-determined) distance and velocity.
Typical Problems With Encoders
Other Tips and Uses
First, keep ambient light out of your sensor, such as sunlight. If light shines in to your sensor, it could potentially read false clicks.
Be careful when putting a control system on motors, as an improper one can damage the motor and circuitry by sudden voltage changes. I once fried a motor because of this . . .
High resolution encoders for velocity control can take a lot of computational system time, so it is better to use a digital counter IC to count encoder clicks than to have your microcontroller count clicks. Your controller can read the counter value serially when it pleases instead.
On your encoder wheel, you can try coloring your black lines in different shades of grey so that your encoder can identify which angle it is at even after a reset. Your robot would match the shade with the angle. Just be careful that the sensor does not read a 'grey shade' when exactly between a black and white line.
When making an encoder wheel, I found that Titanium White paint reflects/blocks infrared very well. Many types of printer ink does not!
This is how I typically wire up my encoder sensor. Basically a PCB with the circuit and slot encoder attached, and wiring to go straight to my microcontroller:
And a closeup of the connection:
How to Make an Encoder Wheel
1) Download the basic excel pie chart encoder or make your own.
These are a few encoder wheel designs I printed out to try:
If you expect a motor rotation to often go to a certain angle, you can also put interesting patterns on your encoder wheel to make processing simpler. You can use an IR LED array IC to read all the patterns simultaneously.
Has this site helped you with your robot? Give us credit -
link back, and help others in the forums!
Society of Robots copyright 2005-2013