Generate customizable absolute position radial Gray code encoders in svg
format.
8 bit encoder:
$ ./generate-encoder.py 8 test.svg
3/5/7/9 bit encoders:
Before using you must install svgwrite:
$ pip install svgwrite
$ ./generate-encoder.py -h
usage: generate-encoder.py [-h] [-g GAP] [-id INNER_DIAMETER] [-od OUTER_DIAMETER] [-d] [-q] bits outfile
positional arguments:
bits number of bits
outfile name of the generated SVG
optional arguments:
-h, --help show this help message and exit
-id INNER_DIAMETER, --inner-diameter INNER_DIAMETER
diameter of the inner circle
-od OUTER_DIAMETER, --outer-diameter OUTER_DIAMETER
diameter of the outer circle
-g GAP, --gap GAP gap between bits
-d, --debug debug mode (adds extra figures to output)
-q, --quiet suppress console output
Please note there is no unit (cm
/mm
/inches
/etc) or dpi
associated to the generated svg
file. All values are expressed in points.
To match exact sizes in the real world either manually resize the shape in your editor of choice or calculate the equivalent points for the size(s) and dpi
you need.
For a 10cm outer-diameter
@ 300dpi
you have to specify -od 1181
:
( 10 / 2.54 ) * 300 = 1181
For a 2.5 inch outer-diameter
@ 300dpi
you have to specify -od 750
:
2.5 * 300 = 750
To create an encoder with specific dimensions/proportions, use the -od
and -id
parameters.
For an encoder with an outer-diameter
of 4 inches and an inner-diameter
of 3 inches @ 300dpi
:
$ ./generate-encoder.py 10 test.svg -od 1200 -id 900
If you specify a --gap
, the specified size will be substracted from the top (the outer edge) of each bit.
The inner-diameter
will be respected, but keep in mind that the outer gap
radius will be empty, as it will be the gap of the last bit.
With bigger gaps
you can have bits' arc pieces represented as thin lines:
Negative gaps can also be used to make sure the pieces do overlap:
In some cases (e.g. when 3D-extruding or laser cutting) it may be important to generate the shape as a single closed path.
The recommended procedure in these cases is:
- Use
--gap -0.5
to make sure your pieces overlap - Use any vector image editor (such as Inkscape) to open the
svg
file:- Ungroup the pieces.
- Apply a boolean union to the individual pieces so they become one.
Using the -d
option will add some extra shapes identifying the anchors and baselines used to construct the encoder. It was created to help while developing, but I found it nice and kept it :)