Servos often use potentiometers to measure the position. That works fine if you have a good quality potentiometer. A different alternative is to use an optical or mechanical decoder. You can find examples of 3D printed rotary encoders here:   

http://www.thingiverse.com/thing:1957311

It's made in two variants.

Natural encoded ( i.e. simply using binary form where a hole represents 1 and no hole = 0). 

Gray code. Gray code has the advanage that only one bit changes for each step of the rotation.

https://en.wikipedia.org/wiki/Gray_code

If anyone want to test this type of encoder, I made two methods that can be used to convert from Gray code to decimal, and also from decimal to Gray.

It's based on this algorithm: 

http://aggregate.org/MAGIC/#Gray%20Code%20Conversion

You can find an example Python script here: 

https://github.com/MyRobotLab/pyrobotlab/blob/master/home/Mats/Gray.py

 

hairygael

7 years 3 months ago

I have kept some disk encoders savaged from paper printers some time ago and I knew it would have a purpose some day. They must be very cheap because it's only a transparente disk with a grey outlining. You can see the black encoder mounted on the brown pcb.

Though, I have no idea how to connect the four white wires to my H-bridge driver and Arduino.

A link to disk encoders made with PET.

http://www.laserlab.com/encoders.php

my god the resolution of that is impressive...

its a single channel digital encoder .. there should be "at least" 3 wires

1 power, 1 ground & 1 signal ...

very nice fine .. very fine resolution too, since from the picture it looks like a solid grey color ..

GroG

7 years 3 months ago

In reply to by Mats

I can't see, usually you have 2 printed channels for direction ..

but you could have 1 channel and 2 ir transistors which are out of phase

regardless, for 2 direction you should expect 2 signal lines plus ground and power