Skip to content

Generate customizable absolute position radial Gray code encoders in `svg` format.

Notifications You must be signed in to change notification settings

clvLabs/gray-code-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gray-code-generator

Generate customizable absolute position radial Gray code encoders in svg format.

Samples

8 bit encoder:

$ ./generate-encoder.py 8 test.svg

3/5/7/9 bit encoders:

Setup

Before using you must install svgwrite:

$ pip install svgwrite

Usage

$ ./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

Size units

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.

Calculation examples

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

Inner and outer diameters

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

Leaving gaps between bits

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:

Making an encoder from a single line

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.

Debug mode

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 :)

About

Generate customizable absolute position radial Gray code encoders in `svg` format.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages