Skip to content

Instantly share code, notes, and snippets.

@jschoch
Created June 16, 2022 03:45
Show Gist options
  • Save jschoch/5f66f0dd7ef6d2ee7e2e82eba47fc91d to your computer and use it in GitHub Desktop.
Save jschoch/5f66f0dd7ef6d2ee7e2e82eba47fc91d to your computer and use it in GitHub Desktop.
cycloid ball reducer sketch for fusion360
import adsk.core, adsk.fusion, adsk.cam, traceback, math
import sys, os
packagepath = os.path.join(os.path.dirname(sys.argv[0]), 'Lib/site-packages/')
if packagepath not in sys.path:
sys.path.append(packagepath)
#import numpy as np
#np = math
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
install_numpy = sys.path[0] +'\Python\python.exe -m pip install numpy'
try:
import numpy as np
except:
ui.messageBox('failed to install numpy\n{}'.format(traceback.format_exc()))
#ui.messageBox('Hello script')
design = app.activeProduct
# Get the root component of the active design.
rootComp = design.rootComponent
# Create a new sketch on the xy plane.
sketches = rootComp.sketches
xyPlane = rootComp.xYConstructionPlane
sketch = sketches.add(xyPlane)
# Create an object collection for the points.
points = adsk.core.ObjectCollection.create()
Dia = 10 #Diameter of the pin circle
#R = Dia/2 # Radius of the toro
#E = 0.3 # Eccentricity of input shaft
Rr = 0.3 # Radius of the rollers
#N = 19 # Number of rollers
n = 10 # num rollers
e = .2 # eccentricity
d = Rr * 2 # roller diameter
i = 0
shaft_radius = .8
splinePoints = (n -1) * 20
t = np.linspace(0, 2*np.pi, splinePoints)
RD=Dia/2 # ring radius
rd=d/2 # roller radius same as Rr
rc = (n-1)*(RD/n)
rm = (RD/n) #
# draw a shaft circle
circles = sketch.sketchCurves.sketchCircles
circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), shaft_radius)
circleA = circles.addByCenterRadius(adsk.core.Point3D.create((rc+rm) - rd,0,0),1)
inner_pinA = circles.addByCenterRadius( adsk.core.Point3D.create((-rd - (2 * e)), 0,0),0.2)
# moving eccentric inner
# ehypocycloidA
xa = (rc+rm)*np.cos(t)-e*np.cos((rc+rm)/rm*t)
ya = (rc+rm)*np.sin(t)-e*np.sin((rc+rm)/rm*t)
dxa = (rc+rm)*(-np.sin(t)+(e/rm)*np.sin((rc+rm)/rm*t))
dya = (rc+rm)*(np.cos(t)-(e/rm)*np.cos((rc+rm)/rm*t))
xCoord = xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya)
yCoord = ya + rd/np.sqrt(dxa**2 + dya**2)*dxa
for i in range(splinePoints):
points.add(adsk.core.Point3D.create(xCoord[i],yCoord[i],0))
sketch.sketchCurves.sketchFittedSplines.add(points)
# moving eccentric outer
# ehypocycloidE
points = adsk.core.ObjectCollection.create()
rc = (n-1)*(RD/n)
rm = (RD/n)
xa = (rc+rm)*np.cos(t)-e*np.cos((rc+rm)/rm*t)
ya = (rc+rm)*np.sin(t)-e*np.sin((rc+rm)/rm*t)
dxa = (rc+rm)*(-np.sin(t)+(e/rm)*np.sin((rc+rm)/rm*t))
dya = (rc+rm)*(np.cos(t)-(e/rm)*np.cos((rc+rm)/rm*t))
xCoord = xa - rd/np.sqrt(dxa**2 + dya**2)*(-dya)
yCoord = ya - rd/np.sqrt(dxa**2 + dya**2)*dxa
for i in range(splinePoints):
points.add(adsk.core.Point3D.create(xCoord[i],yCoord[i],0))
sketch.sketchCurves.sketchFittedSplines.add(points)
# Add moving eccentric disk od
# ehypocycloidD
sketch = sketches.add(xyPlane)
circles = sketch.sketchCurves.sketchCircles
# should be eccentric
circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), shaft_radius)
circleD = circles.addByCenterRadius(adsk.core.Point3D.create((rc+rm) - rd, 0,0),0.1)
points = adsk.core.ObjectCollection.create()
rc = (n+1)*(RD/n)
rm = (RD/n)
xa = (rc-rm)*np.cos(t)+e*np.cos((rc-rm)/rm*t)
ya = (rc-rm)*np.sin(t)-e*np.sin((rc-rm)/rm*t)
dxa = (rc-rm)*(-np.sin(t)-(e/rm)*np.sin((rc-rm)/rm*t))
dya = (rc-rm)*(np.cos(t)-(e/rm)*np.cos((rc-rm)/rm*t))
xCoord = xa - rd/np.sqrt(dxa**2 + dya**2)*(-dya)
yCoord = ya - rd/np.sqrt(dxa**2 + dya**2)*dxa
for i in range(splinePoints):
points.add(adsk.core.Point3D.create(xCoord[i],yCoord[i],0))
sketch.sketchCurves.sketchFittedSplines.add(points)
# Add moving eccentric disk id
# ehypocycloidF
points = adsk.core.ObjectCollection.create()
i = 0
rc = (n+1)*(RD/n)
rm = (RD/n)
xa = (rc-rm)*np.cos(t)+e*np.cos((rc-rm)/rm*t)
ya = (rc-rm)*np.sin(t)-e*np.sin((rc-rm)/rm*t)
dxa = (rc-rm)*(-np.sin(t)-(e/rm)*np.sin((rc-rm)/rm*t))
dya = (rc-rm)*(np.cos(t)-(e/rm)*np.cos((rc-rm)/rm*t))
xCoord = xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya)
yCoord = ya + rd/np.sqrt(dxa**2 + dya**2)*dxa
for i in range(splinePoints):
points.add(adsk.core.Point3D.create(xCoord[i],yCoord[i],0))
sketch.sketchCurves.sketchFittedSplines.add(points)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment