157 lines
4.4 KiB
Python
157 lines
4.4 KiB
Python
"""
|
|
This schematics file contains all designs related to tool handles
|
|
"""
|
|
from dataclasses import dataclass
|
|
import cadquery as Cq
|
|
|
|
@dataclass(frozen=True)
|
|
class Handle:
|
|
"""
|
|
Characteristic of a tool handle
|
|
"""
|
|
|
|
# Outer radius for the handle
|
|
radius: float = 38 / 2
|
|
|
|
# Inner radius
|
|
radius_inner: float = 33 / 2
|
|
|
|
# Wall thickness for the connector
|
|
insertion_thickness: float = 4
|
|
|
|
# The connector goes in the insertion
|
|
connector_thickness: float = 4
|
|
|
|
# Length for the rim on the female connector
|
|
rim_length: float = 5
|
|
|
|
insertion_length: float = 60
|
|
|
|
connector_length: float = 60
|
|
|
|
def __post_init__(self):
|
|
assert self.radius > self.radius_inner
|
|
assert self.radius_inner > self.insertion_thickness + self.connector_thickness
|
|
assert self.insertion_length > self.rim_length
|
|
|
|
@property
|
|
def _r1(self):
|
|
"""
|
|
Radius of inside of insertion
|
|
"""
|
|
return self.radius_inner - self.insertion_thickness
|
|
@property
|
|
def _r2(self):
|
|
"""
|
|
Radius of inside of connector
|
|
"""
|
|
return self._r1 - self.connector_thickness
|
|
|
|
def segment(self, length: float):
|
|
result = (
|
|
Cq.Workplane()
|
|
.cylinder(radius=self.radius, height=length)
|
|
)
|
|
result.faces("<Z").tag("mate1")
|
|
result.faces(">Z").tag("mate2")
|
|
return result
|
|
|
|
def insertion(self):
|
|
"""
|
|
This type of joint is used to connect two handlebar pieces. Each handlebar
|
|
piece is a tube which cannot be machined, so the joint connects to the
|
|
handle by glue.
|
|
|
|
Tags:
|
|
* lip: Co-planar Mates to the rod
|
|
* mate: Mates to the connector
|
|
"""
|
|
result = (
|
|
Cq.Workplane('XY')
|
|
.cylinder(
|
|
radius=self.radius_inner,
|
|
height=self.insertion_length - self.rim_length,
|
|
centered=[True, True, False])
|
|
)
|
|
result.faces(">Z").tag("lip")
|
|
result = (
|
|
result.faces(">Z")
|
|
.workplane()
|
|
.circle(self.radius)
|
|
.extrude(self.rim_length)
|
|
.faces(">Z")
|
|
.hole(2 * self._r1)
|
|
)
|
|
result.faces(">Z").tag("mate")
|
|
return result
|
|
|
|
def connector(self, solid: bool = False):
|
|
"""
|
|
Tags:
|
|
* mate{1,2}: Mates to the connector
|
|
"""
|
|
result = (
|
|
Cq.Workplane('XY')
|
|
.cylinder(
|
|
radius=self.radius,
|
|
height=self.connector_length,
|
|
)
|
|
)
|
|
for (tag, selector) in [("mate1", "<Z"), ("mate2", ">Z")]:
|
|
result.faces(selector).tag(tag)
|
|
r1 = self.radius_inner
|
|
result = (
|
|
result
|
|
.faces(selector)
|
|
.workplane()
|
|
.circle(self._r1)
|
|
.extrude(self.insertion_length)
|
|
)
|
|
if not solid:
|
|
result = result.faces(">Z").hole(2 * self._r2)
|
|
return result
|
|
|
|
def one_side_connector(self):
|
|
result = (
|
|
Cq.Workplane('XY')
|
|
.cylinder(
|
|
radius=self.radius,
|
|
height=self.rim_length,
|
|
)
|
|
)
|
|
result.faces("<Z").tag("mate")
|
|
result.faces(">Z").tag("base")
|
|
result = (
|
|
result
|
|
.faces("<Z")
|
|
.workplane()
|
|
.circle(self._r1)
|
|
.extrude(self.insertion_length)
|
|
)
|
|
return result
|
|
|
|
def connector_insertion_assembly(self):
|
|
connector_color = Cq.Color(0.8,0.8,0.5,0.3)
|
|
insertion_color = Cq.Color(0.7,0.7,0.7,0.3)
|
|
result = (
|
|
Cq.Assembly()
|
|
.add(self.connector(), name="c", color=connector_color)
|
|
.add(self.insertion(), name="i1", color=insertion_color)
|
|
.add(self.insertion(), name="i2", color=insertion_color)
|
|
.constrain("c?mate1", "i1?mate", "Plane")
|
|
.constrain("c?mate2", "i2?mate", "Plane")
|
|
.solve()
|
|
)
|
|
return result
|
|
def connector_one_side_insertion_assembly(self):
|
|
connector_color = Cq.Color(0.8,0.8,0.5,0.3)
|
|
insertion_color = Cq.Color(0.7,0.7,0.7,0.3)
|
|
result = (
|
|
Cq.Assembly()
|
|
.add(self.insertion(), name="i", color=connector_color)
|
|
.add(self.one_side_connector(), name="c", color=insertion_color)
|
|
.constrain("i?mate", "c?mate", "Plane")
|
|
.solve()
|
|
)
|
|
return result
|