-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstepper.py
242 lines (201 loc) · 6.82 KB
/
stepper.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
""" cqparts motors
2018 Simon Kirkby [email protected]
stepper motor generic
"""
# TODO
# even 4 fasteners so it auto mounts to whatever it is parented to.
import cadquery as cq
import cqparts
from cqparts.params import PositiveFloat
from cqparts.constraint import Fixed, Coincident
from cqparts.constraint import Mate
from cqparts.display import render_props
from cqparts.utils.geometry import CoordSystem
from cqparts.search import register
from . import shaft
from . import motor
class _EndCap(cqparts.Part):
# Parameters
width = PositiveFloat(42.3, doc="Motor Size")
length = PositiveFloat(10, doc="End length")
cham = PositiveFloat(3, doc="chamfer")
# _render = render_props(color=(50, 50, 50),alpha=0.4)
def make(self):
base = (
cq.Workplane("XY")
.box(self.width, self.width, self.length)
.edges("|Z")
.chamfer(self.cham)
)
return base
@property
def mate_top(self):
" connect to the end of the top cap"
return Mate(
self,
CoordSystem(
origin=(0, 0, -self.length / 2), xDir=(0, 1, 0), normal=(0, 0, -1)
),
)
@property
def mate_bottom(self):
" bottom of the top cap"
return Mate(
self,
CoordSystem(
origin=(0, 0, -self.length / 2), xDir=(0, 1, 0), normal=(0, 0, 1)
),
)
class _Stator(cqparts.Part):
# Parameters
width = PositiveFloat(40.0, doc="Motor Size")
length = PositiveFloat(20, doc="stator length")
cham = PositiveFloat(3, doc="chamfer")
_render = render_props(color=(50, 50, 50))
def make(self):
base = (
cq.Workplane("XY")
.box(self.width, self.width, self.length, centered=(True, True, True))
.edges("|Z")
.chamfer(self.cham)
)
return base
@property
def mate_top(self):
" top of the stator"
return Mate(
self,
CoordSystem(
origin=(0, 0, self.length / 2), xDir=(0, 1, 0), normal=(0, 0, 1)
),
)
@property
def mate_bottom(self):
" bottom of the stator"
return Mate(
self,
CoordSystem(
origin=(0, 0, -self.length / 2), xDir=(1, 0, 0), normal=(0, 0, -1)
),
)
class _StepperMount(_EndCap):
spacing = PositiveFloat(31, doc="hole spacing")
hole_size = PositiveFloat(3, doc="hole size")
boss = PositiveFloat(22, doc="boss size")
boss_length = PositiveFloat(2, doc="boss_length")
def make(self):
obj = super(_StepperMount, self).make()
obj.faces(">Z").workplane().rect(
self.spacing, self.spacing, forConstruction=True
).vertices().hole(self.hole_size)
obj.faces(">Z").workplane().circle(self.boss / 2).extrude(self.boss_length)
return obj
@property
def mate_top(self):
" top of the mount"
return Mate(
self,
CoordSystem(
origin=(0, 0, self.length / 2), xDir=(0, 1, 0), normal=(0, 0, 1)
),
)
@property
def mate_bottom(self):
" bottom of the mount"
return Mate(
self,
CoordSystem(
origin=(0, 0, -self.length / 2), xDir=(0, 1, 0), normal=(0, 0, 1)
),
)
class _Back(_EndCap):
spacing = PositiveFloat(31, doc="hole spacing")
hole_size = PositiveFloat(3, doc="hole size")
def make(self):
obj = super(_Back, self).make()
obj.faces(">Z").workplane().rect(
self.spacing, self.spacing, forConstruction=True
).vertices().hole(self.hole_size)
return obj
@register(export="motor")
class Stepper(motor.Motor):
" Stepper Motor , simple rendering "
shaft_type = shaft.Shaft
width = PositiveFloat(42.3, doc="width and depth of the stepper")
length = PositiveFloat(50, doc="length of the stepper")
hole_spacing = PositiveFloat(31.0, doc="distance between centers")
hole_size = PositiveFloat(3, doc="hole diameter , select screw with this")
boss_size = PositiveFloat(22, doc="diameter of the raise circle")
boss_length = PositiveFloat(2, doc="length away from the top surface")
shaft_diam = PositiveFloat(5, doc="diameter of the the shaft ")
shaft_length = PositiveFloat(24, doc="length from top surface")
def get_shaft(self):
return self.components["shaft"]
def mount_verts(self):
" return mount points"
wp = cq.Workplane("XY")
h = wp.rect(
self.hole_spacing, self.hole_spacing, forConstruction=True
).vertices()
return h.objects
def make_components(self):
sec = self.length / 6
return {
"topcap": _StepperMount(
width=self.width,
length=sec,
spacing=self.hole_spacing,
hole_size=self.hole_size,
boss=self.boss_size,
),
"stator": _Stator(width=self.width - 3, length=sec * 4),
"botcap": _Back(
width=self.width,
length=sec,
spacing=self.hole_spacing,
hole_size=self.hole_size,
),
"shaft": self.shaft_type(length=self.shaft_length, diam=self.shaft_diam),
}
def make_constraints(self):
return [
Fixed(self.components["topcap"].mate_top),
Coincident(
self.components["stator"].mate_top,
self.components["topcap"].mate_bottom,
),
Coincident(
self.components["botcap"].mate_bottom,
self.components["stator"].mate_bottom,
),
Coincident(
self.components["shaft"].mate_origin, self.components["topcap"].mate_top
),
]
def apply_cutout(self):
" shaft cutout "
stepper_shaft = self.components["shaft"]
top = self.components["topcap"]
local_obj = top.local_obj
local_obj = local_obj.cut(stepper_shaft.get_cutout(clearance=0.5))
def make_alterations(self):
self.apply_cutout()
def boss_cutout(self, clearance=0):
bc = cq.Workplane("XY").circle(self.boss_size / 2).extrude(self.shaft_length)
return bc
def cutout(self, part):
self.cut_boss(part)
def cut_boss(self, part, clearance=0):
co = self.boss_cutout(clearance=clearance)
lo = part.local_obj.cut((self.world_coords - part.world_coords) + co)
def mate_tip(self):
return Mate(
self,
CoordSystem(
origin=(0, 0, self.shaft_length), xDir=(1, 0, 0), normal=(0, 0, 1)
),
)
if __name__ == "__main__":
from cqparts.display import display
st = Stepper()
display(st)