Quadrature Encoder Inside and R/C Servoby Giuseppe Marullo -- firstname.lastname@example.org R/C servos are an invaluable resource for small robots, but they lack feedback. I will describe here how I put a quadrature encoder inside a standard R/C servo. A little step toward motion control. This could be an ideal solution on small robots like the Mark III, you save a lot of space and complexity. Another advantage is that you can use it on almost every robot that already has servos. Quadrature encoders have many advantages over regular encoders:
- 4X the resolution (if you know how to deal with it)
- Allow digital filtering to improve reliability and can detect failures
- Let you track the wheel position independently of inertia, slope or motor controller(you can sense direction from the encoder). A dedicated chip does the hard work for you, tracking reliably the wheel's position
On a standard servo, the first gear gives you roughly 52 counts per revolution (CPR). While this seems a low resolution, using a 4X decoder it really means 208 CPR. This sounds more adequate. The first gear is accessible from above, just drill two holes at 90 degrees each other, push two reflective IR sensors inside and voila, you have your encoder on a servo.
The only reflective sensor I was able to get in Italy is CNY70. It has no fancy features present on sensors like the Hamamatsu P5587. I need to use a comparator and a Schmitt trigger to clean up the signal. At first I tried to keep only the IR sensors inside the servo, but soon I discovered that noise was a problem.
The second board included the entire comparator circuit. At this point, there was no space left for the original board. The next release will let you to leave the original board inside.
The servo: 2 standard Parallax Servos already modified for continuous rotation. The key here is that everything under the "gear plane" is clear. Probably a modified servo that has the pot left in place won't work.
You need to reach the space under the first gear (approximately the center area), being able to put some stuff under.
The sensors: 4 CNY70 sensors (2 on each sensors)
The electronic stuff:
- 3 4x4 cm of protoboard single side
- 4 10kΩ multi-turn pot (lowest profile possible)
- 2 150Ω 1/8W resistor
- 1 10kΩ 1/8W resistor
- 2 LM358 comparator
- 1 LS74HCT14
- 4 yellow LEDs
- 4 220Ω 1/4W resistor
- a micro drill (like Dremel and such)
- some bits in the 1mm range
- black permanent marker, ink or whatever you feel confident to use to black the gear
- soldering equipment, 7/15W max
- small file
- a webcam (not joking)
Begin disassembling the servo on a table. Put away all the parts you won't need. You are going to produce dirt, and gears are greased. They will instantly retain every single particle you have around.
Put away the gears, and take away electronics. You will need two wires connected to the motor, so if the board is soldered directly to the motor, please remove it carefully.
Codewheel MarkingTake the first gear, turn it upside down and paint black exactly one half.
Almost half of the gear overlaps with the motor; you should have the opposite side free.
Use a cutter to mark the place where holes should be placed. The sensors are square, so it makes sense to cut the holes square as well. You should avoid cutting structural plastic, especially the one that supports the shaft.
Be careful when choosing the place to put the sensors. The center of the sensor should be around 90 degrees from other with respect to the center of the codewheel. This is because the signal should be shifted 90 degrees.
90 degrees between the center of the sensors
- Transition between black and white
- Middle of white
The effect will be that when on sensor is exactly switching between black and white (or vice-versa), the other sensor will be in the middle of black or white slice.
Once you have the holes done, you have to remove as much plastic as possible inside to accommodate the circuit. Don't cut anything near the motor, or in the corners.
This is the block description of the circuit:
Try to use this as a starting point for your board, but you need to find out how to build our own. Remember that the circuit will fit tightly, so you will not have to glue it. Try several times to put it inside. Modify it bit by bit, and when it enters with a little effort but does not move you have the right size.
Solder the following circuit, except the reflective IR sensors:
I used the following method to successfully put the electronics inside:
- cut the holes where the sensors should be on the servo
- put the sensors on the circuit without soldering them
- put the whole circuit inside the servo, trying to adapt it just to let it fit while pushing out the sensors on their holes (they must not coming out of the plastic but be as close as possible to the edge)
- when the position of the sensors are ok and the circuit is right inside the servo then solder the sensors
- once you have soldered the sensors you could carefully push the whole thing away and back, just use a little attention
Cutting the holes is not a 5 minute thing. For me it was the most challenging task. You need to align them correctly and try several times to put sensors in. They must remain locked without glue, so you can get the circuit out of the servo.
Another thing to check is that the gear must run free. Double-check it using all the gears.
This simply has to accommodate the Schmitt inverter IC and 4 LEDs. Only one half (one encoder) is shown:
You need to set the comparators' levels. Turn the pot completely counter-clockwise. You should have LOW on the 74HCT14 output.
Turn the first gear until both sensors "see" black. Gently turn clockwise until the LEDs turn off. Try to turn the first gear and let one sensor see white. Does the LED light up? If the answer is yes, it is okay. Move on the other sensor and repeat. Try to move the wheel; do the LEDs turns on and off like a quadrature encoder's signal?
If you don't see signals while moving the wheel, you could check the IR diodes using a webcam:
Under strong light the sensors may saturate easily: Try to perform the procedure using low lights or using the servo cover.
When you are done, remember to solder two wires to the motor before closing the case. You should use a H-bridge from now on, but just for testing you could connect the electronic board that was inside the servo to the motor using the original circuit.
If you own a scope, you should get a signal similar to this:
Yes, it is not easy, but I think that it is worth the effort. The next step will be a board that will process quadrature encoders$B!G(B signals in hardware and possibly P5587 sensors.
CNY70 - http://www.vishay.com/docs/83751/83751.pdf
Application of Optical Reflex Sensors TCRT1000, TCRT5000, CNY70 - http://new.vishay.co