-
Notifications
You must be signed in to change notification settings - Fork 2
/
mounted.py
135 lines (112 loc) · 4.13 KB
/
mounted.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import cadquery as cq
import cqparts
from cqparts.params import *
from cqparts.constraint import Fixed, Coincident
from cqparts.constraint import Mate
from cqparts.utils.geometry import CoordSystem
from cqparts.display import render_props, display
from cqparts.search import register
from cqparts_fasteners.male import MaleFastenerPart
from cqparts_fasteners.utils import VectorEvaluator
from cqparts_fasteners.fasteners.screw import Screw
from cqparts_fasteners.params import HeadType, DriveType, ThreadType
from .partref import PartRef
from .boss import Boss
from .stepper import Stepper
from .plank import Plank
class SmallScrew(Screw):
head = HeadType(
default=("countersunk", {"diameter": 5.0, "height": 2.4}),
doc="head type and parameters",
)
drive = DriveType(
default=("phillips", {"diameter": 3.0, "depth": 2, "width": 0.5}),
doc="screw drive type and parameters",
)
thread = ThreadType(
default=("ball_screw", {"diameter": 3.0, "pitch": 0.5, "ball_radius": 1}),
doc="thread type and parameters",
)
neck_length = PositiveFloat(0, doc="length of neck")
length = PositiveFloat(10, doc="screw's length")
tip_length = PositiveFloat(0, doc="length of taper on a pointed tip")
class Mounted(cqparts.Assembly):
base = PartRef(Boss())
target = PartRef()
screw = PartRef(SmallScrew)
@classmethod
def screw_name(cls, index):
return "screw_%03i" % index
def initialize_parameters(self):
pass
def make_components(self):
base = self.base
comps = {"base": base}
for i, j in enumerate(base.mount_verts()):
comps[self.screw_name(i)] = self.screw()
return comps
@property
def get_base(self):
return self.components["base"]
def make_constraints(self):
base = self.components["base"]
constr = [Fixed(base.mate_origin)]
constr.append(Coincident(self.target.mate_origin, base.mate_origin)),
for i, j in enumerate(base.mount_verts()):
# TODO covert to a Vector Evealuator
m = Mate(
self,
CoordSystem(
origin=(j.X, j.Y, j.Z + self.target.thickness),
xDir=(1, 0, 0),
normal=(0, 0, 1),
),
)
constr.append(
Coincident(self.components[self.screw_name(i)].mate_origin, m)
),
return constr
def target_cut_out(self, X, Y, Z, part, target):
coord = CoordSystem(origin=(X, Y, Z), xDir=(1, 0, 0), normal=(0, 0, 1))
# cut the screw from the mount
try:
this = self.components["base"].local_obj
this.cut((coord) + part.make_cutter())
except:
pass
# cut the screw from the target
target.local_obj.cut(
(self.world_coords + coord - target.world_coords) + part.make_cutter()
)
def mate_base(self):
return self.base.mate_origin
def make_alterations(self):
base = self.components["base"]
# for i, j in enumerate(base.mount_verts()):
# self.components[self.screw_name(i)].cutout(part=self.base)
if self.target is not None:
self.base.cutout(self.target)
for i, j in enumerate(base.mount_verts()):
p = self.components[self.screw_name(i)]
self.target_cut_out(
j.X, j.Y, j.Z + self.target.thickness, p, self.target
)
# put the board across
def mate_transverse(self):
return Mate(
self, CoordSystem(origin=(0, 0, 0), xDir=(0, 1, 0), normal=(0, 0, 1))
)
# positioned mount for target testing
class _DemoMount(cqparts.Assembly):
def make_components(self):
p = Plank(height=2.5)
return {"m": Mounted(base=Boss(), target=p), "p": p}
def make_constraints(self):
return [Fixed(self.components["m"].mate_origin)]
if __name__ == "__main__":
from cqparts.display import display
# p = MountedBoard(board=Pizero)
# p = MountedBoard(board=BeagleBoneBlack)
# p = Mounted()
p = _DemoMount()
display(p)