Skip to content

Commit

Permalink
Merge pull request #7 from meadiode/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
meadiode authored Jan 8, 2022
2 parents ab0d995 + 3110141 commit b3f0014
Show file tree
Hide file tree
Showing 10 changed files with 1,076 additions and 149 deletions.
2 changes: 1 addition & 1 deletion cq_gears/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'''


__version__='0.6'
__version__='0.62'

import cadquery as cq
from .spur_gear import SpurGear, HerringboneGear
Expand Down
88 changes: 57 additions & 31 deletions cq_gears/bevel_gear.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

class BevelGear(GearBase):

surface_splines = 12

def __init__(self, module, teeth_number, cone_angle, face_width,
pressure_angle=20.0, helix_angle=0.0, clearance=0.0,
backlash=0.0, **build_params):
Expand Down Expand Up @@ -70,6 +72,8 @@ def __init__(self, module, teeth_number, cone_angle, face_width,
self.surface_splines = 2
self.twist_angle = 0.0

assert np.isnan(self.twist_angle) == False, 'Twist angle is NaN'

self.build_params = build_params

# The distance between the cone apex and the bottom of the gear
Expand Down Expand Up @@ -164,9 +168,12 @@ def _build_tooth_faces(self):
ta1 = -(pc_f - self.gs_r) / self.face_width * self.twist_angle
ta2 = (self.gs_r - tc_f) / self.face_width * self.twist_angle

surf_splines = int(np.ceil(abs(self.twist_angle) / (np.pi * 2.0)))
surf_splines = max(1, surf_splines) * self.surface_splines

# Transformation parameters: (radius, twist angle)
spline_tf = np.linspace((pc_f, ta1), (tc_f - 0.01, ta2),
self.surface_splines)
surf_splines)

tcp_size = tc_rb * 1000.0
top_cut_plane = cq.Face.makePlane(length=tcp_size, width=tcp_size,
Expand Down Expand Up @@ -299,7 +306,7 @@ def _make_bore(self, body, bore_d):
return body.val()


def _build(self, bore_d=None, trim_bottom=True, trim_top=True):
def _build(self, bore_d=None, trim_bottom=True, trim_top=True, **kv_args):
faces = self._build_gear_faces()

shell = make_shell(faces)
Expand All @@ -326,6 +333,9 @@ def _build(self, bore_d=None, trim_bottom=True, trim_top=True):
class BevelGearPair(GearBase):

gear_cls = BevelGear

asm_gear_color = 'goldenrod'
asm_pinion_color = 'lightsteelblue'

def __init__(self, module, gear_teeth, pinion_teeth, face_width,
axis_angle=90.0, pressure_angle=20.0, helix_angle=0.0,
Expand All @@ -352,44 +362,60 @@ def __init__(self, module, gear_teeth, pinion_teeth, face_width,
self.build_params = build_params


def _build(self, gear=True, pinion=True, transform_pinion=True,
gear_build_args={}, pinion_build_args={}, **kv_args):
def assemble(self, build_gear=True, build_pinion=True,
transform_pinion=True, gear_build_args={},
pinion_build_args={}, **kv_args):

gearset = cq.Workplane('XY')
gearset = cq.Assembly(name='bevel_pair')

if build_gear:
if 'gear_build_args' in self.build_params:
in_args = self.build_params['gear_build_args']
else:
in_args = {}

args = {**self.build_params,
**in_args,
**kv_args,
**gear_build_args}

if gear:
args = {**kv_args, **gear_build_args}
gear = self.gear.build(**args)
gearset.add(gear, name='gear', loc=cq.Location(),
color=cq.Color(self.asm_gear_color))

if build_pinion:
if 'pinion_build_args' in self.build_params:
in_args = self.build_params['pinion_build_args']
else:
in_args = {}

gearset.add(gear)
args = {**self.build_params,
**in_args,
**kv_args,
**pinion_build_args}

if pinion:
args = {**kv_args, **pinion_build_args}
pinion = self.pinion.build(**args)

if transform_pinion:
dist = -self.pinion.cone_h + self.gear.cone_h
angle = np.pi / 2.0 - self.axis_angle
loc = cq.Location()

if self.pinion.z % 2 == 0:
pinion = pinion.rotate(
(0.0, 0.0, 0.0),
(0.0, 0.0, 1.0),
np.degrees(np.pi / self.pinion.z))

pinion = (pinion
.rotate((0.0, -1.0, self.gear.cone_h),
(0.0, 1.0, self.gear.cone_h),
if transform_pinion:
loc *= cq.Location(cq.Vector(0.0, 0.0, self.gear.cone_h),
cq.Vector(0.0, 1.0, 0.0),
np.degrees(self.axis_angle))
.translate((dist * np.cos(angle),
0.0,
dist * np.sin(angle))))

loc *= cq.Location(cq.Vector((0.0, 0.0, -self.pinion.cone_h)))

if self.pinion.z % 2 == 0:
loc *= cq.Location(cq.Vector(0.0, 0.0, 0.0),
cq.Vector(0.0, 0.0, 1.0),
np.degrees(np.pi / self.pinion.z))

gearset.add(pinion, name='pinion', loc=loc,
color=cq.Color(self.asm_pinion_color))

gearset.add(pinion)
return gearset

gearset = gearset.vals()

if len(gearset) == 1:
return gearset[0]

return cq.Compound.makeCompound(gearset)
def _build(self, *args, **kv_args):
asm = self.assemble(*args, **kv_args)
return asm.toCompound()
131 changes: 75 additions & 56 deletions cq_gears/crossed_helical_gear.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class CrossedGearPair(GearBase):

gear1_cls = CrossedHelicalGear
gear2_cls = CrossedHelicalGear
asm_gear1_color = 'goldenrod'
asm_gear2_color = 'lightsteelblue'

def __init__(self, module, gear1_teeth_number, gear2_teeth_number,
gear1_width, gear2_width, pressure_angle=20.0,
Expand All @@ -148,52 +150,59 @@ def __init__(self, module, gear1_teeth_number, gear2_teeth_number,
helix_angle=g2_helix,
clearance=clearance,
backlash=backlash)
self.shaft_angle = shaft_angle
self.shaft_angle = np.radians(shaft_angle)
self.build_params = build_params


def assemble(self, build_gear1=True, build_gear2=True, transform_gear2=True,
gear1_build_args={}, gear2_build_args={}, **kv_args):


def _build(self, gear1=True, gear2=True, transform_gear2=True,
gear1_build_args={}, gear2_build_args={}, **kv_args):

gearset = cq.Workplane('XY')

if gear1:
gearset = cq.Assembly(name='crossed_pair')

if build_gear1:
args = {**self.build_params, **kv_args, **gear1_build_args}
gear1 = self.gear1.build(**args)

gearset = gearset.add(gear1)

if gear2:
gearset.add(gear1, name='gear1', loc=cq.Location(),
color=cq.Color(self.asm_gear1_color))

if build_gear2:
args = {**self.build_params, **kv_args, **gear2_build_args}
gear2 = self.gear2.build(**args)

if transform_gear2:

ratio = self.gear1.z / self.gear2.z
align_angle = 0.0 if self.gear2.z % 2 else 180.0 / self.gear2.z
align_angle = 0.0 if self.gear2.z % 2 else 180.0 / self.gear2.z
align_angle += np.degrees(self.gear2.twist_angle + \
self.gear1.twist_angle * ratio) / 2.0

gear2 = (gear2
.rotate((0.0, 0.0, 0.0), (0.0, 0.0, 1.0), align_angle)
.translate((0.0, 0.0, (self.gear1.width - \
self.gear2.width) / 2.0))
.rotate((0.0, 0.0, self.gear1.width / 2.0),
(1.0, 0.0, self.gear1.width / 2.0),
self.shaft_angle)
.translate((self.gear1.r0 + self.gear2.r0, 0.0, 0.0)))

gearset = gearset.add(gear2)

gearset = gearset.vals()

if len(gearset) == 1:
return gearset[0]

return cq.Compound.makeCompound(gearset)
loc = cq.Location(cq.Vector(self.gear1.r0 + self.gear2.r0,
0.0,
self.gear1.width / 2.0))
loc *= cq.Location(cq.Vector(0.0, 0.0, 0.0),
cq.Vector(1.0, 0.0, 0.0),
np.degrees(self.shaft_angle))
loc *= cq.Location(cq.Vector(0.0, 0.0, -self.gear2.width / 2.0))
loc *= cq.Location(cq.Vector(0.0, 0.0, 0.0),
cq.Vector(0.0, 0.0, 1.0),
align_angle)

else:
loc = cq.Loaction()

gearset.add(gear2, name='gear2', loc=loc,
color=cq.Color(self.asm_gear2_color))

return gearset


def _build(self, *args, **kv_args):
asm = self.assemble(*args, **kv_args)
return asm.toCompound()


class HyperbolicGear(SpurGear):

surface_splines = 2

def __init__(self, module, teeth_number, width, twist_angle,
Expand All @@ -220,6 +229,8 @@ def __init__(self, module, teeth_number, width, twist_angle,
class HyperbolicGearPair(GearBase):

gear_cls = HyperbolicGear
asm_gear1_color = 'goldenrod'
asm_gear2_color = 'lightsteelblue'

def __init__(self, module, gear1_teeth_number, width, shaft_angle,
gear2_teeth_number=None, pressure_angle=20.0,
Expand All @@ -238,8 +249,8 @@ def __init__(self, module, gear1_teeth_number, width, shaft_angle,
gear2_twist_angle = np.arcsin(hh / g2_r0) * 2.0

if np.isnan(gear1_twist_angle) or np.isnan(gear2_twist_angle):
raise ValueError('Impossible to calculate a twist angle for the '
'given shaft angle/teeth number/gear width')
raise ValueError('Impossible to calculate the twist angle for the '
'given shaft angle / teeth number / gear width')

self.shaft_angle = np.radians(shaft_angle)

Expand All @@ -256,17 +267,18 @@ def __init__(self, module, gear1_teeth_number, width, shaft_angle,
backlash=backlash)
self.build_params = build_params

def _build(self, build_gear1=True, build_gear2=True, transform_gear2=True,
gear1_build_args={}, gear2_build_args={}, **kv_args):
gearset = cq.Workplane('XY')

def assemble(self, build_gear1=True, build_gear2=True, transform_gear2=True,
gear1_build_args={}, gear2_build_args={}, **kv_args):

gearset = cq.Assembly(name='hyperbolic_pair')

if build_gear1:
args = {**self.build_params, **kv_args, **gear1_build_args}
gear1 = self.gear1.build(**args)
gearset = gearset.add(gear1)

gearset.add(gear1, name='gear1', loc=cq.Location(),
color=cq.Color(self.asm_gear1_color))

if build_gear2:
args = {**self.build_params, **kv_args, **gear2_build_args}
gear2 = self.gear2.build(**args)
Expand All @@ -277,20 +289,27 @@ def _build(self, build_gear1=True, build_gear2=True, transform_gear2=True,
align_angle = 0.0 if self.gear2.z % 2 else 180.0 / self.gear2.z
align_angle += np.degrees(self.gear2.twist_angle + \
self.gear1.twist_angle * ratio) / 2.0

loc = cq.Location(cq.Vector(self.gear1.throat_r + \
self.gear2.throat_r,
0.0,
self.gear1.width / 2.0))
loc *= cq.Location(cq.Vector(0.0, 0.0, 0.0),
cq.Vector(1.0, 0.0, 0.0),
np.degrees(self.shaft_angle))
loc *= cq.Location(cq.Vector(0.0, 0.0, -self.gear2.width / 2.0))
loc *= cq.Location(cq.Vector(0.0, 0.0, 0.0),
cq.Vector(0.0, 0.0, 1.0),
align_angle)
else:
loc = cq.Location()

gearset.add(gear2, name='gear2', loc=loc,
color=cq.Color(self.asm_gear2_color))

return gearset


gear2 = (gear2
.rotate((0.0, 0.0, 0.0), (0.0, 0.0, 1.0), align_angle)
.rotate((0.0, 0.0, self.gear1.width / 2.0),
(1.0, 0.0, self.gear1.width / 2.0),
np.degrees(self.shaft_angle))
.translate((self.gear1.throat_r + self.gear2.throat_r,
0.0, 0.0)))

gearset = gearset.add(gear2)

gearset = gearset.vals()

if len(gearset) == 1:
return gearset[0]

return cq.Compound.makeCompound(gearset)
def _build(self, *args, **kv_args):
asm = self.assemble(*args, **kv_args)
return asm.toCompound()
Loading

0 comments on commit b3f0014

Please sign in to comment.