Compound Gear Train Python
Compound Gear Train Python
def nstage(r,n,eps):
f = r**(1/n)
if f > 10:
return None, None
for N1 in range(14,20):
N2 = N1*f
if isacceptable(N2,round(N2),eps):
return N1,round(N2)
return None,None
def isacceptable(xreal,xcalc,eps=0.2/100):
err = abs((xreal-xcalc)/xreal)
if err >= eps:
return False
return True
def draw_train(N1,N2,n,Pd,pa=20):
for k in range(n):
dx1,dy1 = gears_make_gear(pa, N1, Pd)
dx2,dy2 = gears_make_gear(pa, N2, Pd)
C = 0.5*(N1/Pd) + 0.5*(N2/Pd)
plt.fill(np.array(dx1)+C*(k-1), dy1)
plt.fill(np.array(dx2)+C*k, np.array(dy2))
plt.axis('square')
http://localhost:8888/notebooks/Google%20Drive/Scribd%20Gen/Compound-Gear-Train.ipynb# 1/7
5/3/2019 Compound-Gear-Train
Figure 1
In [ ]:
In [ ]:
In [ ]:
http://localhost:8888/notebooks/Google%20Drive/Scribd%20Gen/Compound-Gear-Train.ipynb# 2/7
5/3/2019 Compound-Gear-Train
# =================================================================================
# =================================================================================
# Spur-gear generation script
# (c) James Gregson, 2012
# Free for all use, including commercial, but do not redistribute.
# Use at your own risk.
#
# Notes:
# - seems to work well for pressure angles up to about 30 degrees
# =================================================================================
# =================================================================================
http://localhost:8888/notebooks/Google%20Drive/Scribd%20Gen/Compound-Gear-Train.ipynb# 3/7
5/3/2019 Compound-Gear-Train
ty = r*( s - i*dtheta*c )
d = math.sqrt(tx*tx+ty*ty)
if d > r_max:
a = (r_max-rlast)/(d-rlast)
tx = x[-1]*(1.0-a) + tx*a
ty = y[-1]*(1.0-a) + ty*a
ttheta = theta[-1]*(1.0-a) + math.atan2( ty, tx )*a
x.append( tx )
y.append( ty )
theta.append( ttheta )
break
else:
x.append( tx )
y.append( ty )
theta.append( math.atan2( ty, tx) )
return x, y, theta
# returns the angle where an involute curve crosses a circle with a given radius
# or -1 on failure
def gears_locate_involute_cross_angle_for_radius( r, ix, iy, itheta ):
for i in range( 0, len(ix)-1 ):
r2 = ix[i+1]*ix[i+1] + iy[i+1]*iy[i+1]
if r2 > r*r:
r1 = math.sqrt( ix[i]*ix[i] + iy[i]*iy[i] )
r2 = math.sqrt( r2 )
a = (r-r1)/(r2-r1)
return itheta[i]*(1.0-a) + itheta[i+1]*a
return -1.0
# rotates the involute curve around the gear center in order to have the involute
# cross the x-axis at the pitch diameter
def gears_align_involute( Dp, ix, iy, itheta ):
theta = -gears_locate_involute_cross_angle_for_radius( Dp/2.0, ix, iy, itheta )
c = math.cos(theta)
s = math.sin(theta)
for i in range( 0, len(ix) ):
tx = c*ix[i] - s*iy[i]
ty = s*ix[i] + c*iy[i]
ix[i] = tx
iy[i] = ty
return ix, iy
# reflects the input curve about the x-axis to generate the opposing face of
# a tooth
def gears_mirror_involute( ix, iy ):
tx = []
ty = []
for i in range( 0, len(iy) ):
tx.append( ix[len(iy)-1-i] )
ty.append( -iy[len(iy)-1-i] )
return tx, ty
minx = min( px )
maxx = max( px )
miny = min( py )
maxy = max( py )
cenx = (minx + maxx)/2.0
ceny = (miny + maxy)/2.0
sx = ( maxx - cenx )*1.1
sy = ( maxy - ceny )*1.1
out.write('" />\n' )
out.write('</svg>\n')
out.close()
# write output as dxf profile in x-y plane, for use with OpenSCAD
def gears_dxf_out( px, py, filename, scale=1.0 ):
out = open( filename, 'w' )
out.write(' 0\n')
out.write('SECTION\n')
out.write(' 2\n')
out.write('HEADER\n')
out.write('999\n')
out.write('%s by gears.py\n' % filename )
out.write('999\n')
out.write('contact [email protected] for gears.py details\n')
out.write(' 0\n')
out.write('ENDSEC\n')
http://localhost:8888/notebooks/Google%20Drive/Scribd%20Gen/Compound-Gear-Train.ipynb# 5/7
5/3/2019 Compound-Gear-Train
out.write(' 0\n')
out.write('SECTION\n')
out.write(' 2\n')
out.write('TABLES\n')
out.write(' 0\n')
out.write('ENDSEC\n')
out.write(' 0\n')
out.write('SECTION\n')
out.write(' 2\n')
out.write('BLOCKS\n')
out.write(' 0\n')
out.write('ENDSEC\n')
out.write(' 0\n')
out.write('SECTION\n')
out.write(' 2\n')
out.write('ENTITIES\n')
out.write(' 0\n')
out.write('ENDSEC\n')
out.write(' 0\n')
out.write('EOF\n')
out.close()
# pa = 20
# N1 = 12
# N2 = N1*6
# PD = 32
# C = 0.5*(N1/PD) + 0.5*(N2/PD)
# print(C)
In [ ]:
In [ ]:
In [ ]:
http://localhost:8888/notebooks/Google%20Drive/Scribd%20Gen/Compound-Gear-Train.ipynb# 6/7
5/3/2019 Compound-Gear-Train
In [ ]:
http://localhost:8888/notebooks/Google%20Drive/Scribd%20Gen/Compound-Gear-Train.ipynb# 7/7