Rotary Encoder Disks with Matplotlib

Did you ever needed a quick way to make your own rotary encoder disks?

Here a quick way to make the graphics. Afterwards only a printer and scissors are necessary.

First import the packages numpy and matplotlib

import matplotlib.pylab as plt
import numpy as np

And now define the outer and inner diameter as well as the number of lines:

di = 300.e-3# inner diameter
da = 340.e-3 # outer diameter
lpr = 720. # lines per 360°

And here comes the rest:

fig, ax = plt.subplots(1,1, subplot_kw=dict(polar=True))
theta = np.linspace(0.,2*np.pi,lpr+1)
radii=np.empty(lpr+1); radii.fill((da-di)/2)
dis=np.empty(lpr+1); dis.fill(di/2)
ax.bar(theta, radii, width=np.radians(360/(2*lpr)), bottom=dis,
           color='black', edgecolor = 'none', linewidth  = 0.)
ax.plot(0,0,'.',color='black')
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
fig.patch.set_visible(False)
ax.axis('off')

It is a polar plot with bars, separeted from inner diameter to outer diameter. Important is to suppress any lines which disturb your signals (suppress tick and labels).

And here is an example output:

Rotary Encoder Disk
Rotary Encoder Disk

Only thing what’s left is to print and build.

Advertisements

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s