Inkscape optical rotary encoder disk generator with STGC support

Inkscape optical rotary encoder disk generator with STGC support

I have added support for single-track gray encoders to my Inkscape optical rotary encoder disk generator extension.

In a nutshell single-track gray encoders are similar to binary-reflected gray encoders because they give absolute position with multiple sensors, and two adjacent positions can only differ by one least significant bit. The difference is that STG encoder has just one track with multiple sensors. This makes it possible to make radially smaller sensors because you have just one track.

The downside to STG encoders is that they can not distinguish as many positions as a BRG encoder with the same amount of sensors. If the amount of sensors n is a power of two, then a STG encoder can distinguish 2^n-2n positions, compared to BRG encoder which can distinguish 2^n positions (doesn’t matter if n is a power of two or not).

I have been studying the New Zealand patent NZ 264738 by Bruce Spedding (who answered a few of my questions about the patent, thanks!) to be able to add this feature to my extension. One small detail is that for the same number of cutouts and sensors my extension might not give the same spacing for the encoder segments as Spedding’s patents examples. This is because the equation for figuring out the spacing between the encoder segments includes an integer “s” which can be any positive integer and all the examples in Spedding’s patent do not seem to use the same value of “s“. My extension uses a hard coded value of s=1 since it does not really affect the functionality of the encoder in any way.

Spedding’s patent is pretty clear in describing STG encoders but the actual math involved is pretty scary when you look at some other papers such as “Single-Track Circuit Codes” by Alain P. Hiltgen and Kenneth G. Paterson so I cannot guarantee my extension works like it should (because I do not fully understand them). If someone makes an actual encoder using my extension and it works or doesn’t work (or spots a bug), let me know!

You can get the extension from GitHub (check my original post for installation instructions): Inkscape rotary encoder disk generator

Categories: All posts, Programming

4 Responses so far.

  1. Bert says:


    Great work!
    Do you think it would be possible to add linear encoder strips? I have been thinking about building a 3d printer using so called threadless ballscrews. One would need to use linear encoder strips for that to compensate for slip of the threadless ballscrew… Maybe there are more people that want to do something similar.

    • Hey Bert! Adding support for linear encoder strips would not be difficult, I just haven’t had any use for them. When making an encoder strip for a 3D printer the achievable resolution might be limited by the printer you use to print the encoder. 3D printers are usually accurate to 0.1mm or so and the usual rule of thumb with measuring is that you’d want one decimal more of information so you’d want an encoder with 0.01mm resolution. Which is over 2500 DPI.

  2. Jay Dowling says:

    It is not true that 2^n-2n code length sequences are generated for n bits.

    • Hey Jay! My only source is Wikipedia which says “Although it is not possible to distinguish 2n positions with n sensors on a single track, it is possible to distinguish close to that many. For example, when n is itself a power of 2, n sensors can distinguish 2^n−2n positions.” But does not seem to have a reference. Can you elaborate?

Leave a Reply