-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.scad
436 lines (349 loc) · 9.48 KB
/
engine.scad
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
// Number, and angle, of cylinders
CONFIGURATION = 2; // [1:1 Cylinder, 2:2 Cylinders (V), 20:2 Cylinders (Flat), 3:3 Cylinders, 4:4 Cylinders]
// Distance between the stepper motor screws
MOTOR_SIZE = 31; // [20:0.1:50]
// Diameter inside the magnet mounting holes
MAGNET_DIAMETER = 8.05; // [4:0.01:10]
// Magnet thickness
MAGNET_HEIGHT = 3; // [1:0.01:5]
// Tolerance between moving parts
TOLERANCE = 0.3; // [0.1:0.05:0.5]
// Parts layout
VIEW = "Printing"; // [Printing, Combined, Exploded]
/* [Propeller] */
ENABLE_PROPELLER = 0; // [0:No, 1:Yes]
PROPELLER_BLADES = 2; // [1:1:8]
PROPELLER_DIRECTION = 1; // [1:Clockwise, -1:Counter Clockwise]
/* [Mounting Tabs] */
// How to fasten the visualizer engine to the stepper motor
MOUNTING_TYPE = "Magnet"; // ["Magnet", "Press-fit tab"]
// Diameter inside the motor screw holes
MOUNTING_TAB_SIZE = 6.15; // [4.5:0.01:7.5]
$fa = $preview ? 15 : 0.1;
$fs = $preview ? 1.25 : 0.6; // Curve resolution
PIN = 2 + 0; // Pin radius
WALL = 2 + 0; // Wall thickness
SQRT2 = sqrt(2); // Square root of 2
TOLHALF = TOLERANCE / 2; // Half of the part tolerance
CRANK = MOTOR_SIZE / 6; // Crankshaft length
ROD = MOTOR_SIZE / 1.9; // Connecting rod length
PISTON = MOTOR_SIZE / 3.1; // Piston size
BLOCK = 2+MAGNET_HEIGHT; // Engine block thickness
SLEEVE = CRANK+ROD+PISTON/2+WALL+0.5; // Cylinder length from center
CYLINDERS = CONFIGURATION == 20 ? 2 : CONFIGURATION; // Number of cylinders
CYLINDER_ANGLE = CONFIGURATION == 20 ? 180 : 90; // Angle between cylinders
MOUNT_TAB_R = MOUNTING_TAB_SIZE / 2; // Motor mount tab radius
PIN_HEIGHT = CYLINDERS == 1 ? 4 : CYLINDERS+2;
if (VIEW == "Printing") {
draw_for_printing();
}
else if (VIEW == "Combined") {
rotate([90, 0, 0])
draw_combined();
}
else if (VIEW == "Exploded") {
length = 3;
rotate([90, 0, 0])
translate([0, 0, -length*3])
draw_combined(length);
}
/*************************
* Part layout modules *
*************************/
module draw_for_printing() {
translate([0,0,(MOUNTING_TYPE == "Magnet" ? 0 : 4)])
rotate((MOUNTING_TYPE == "Magnet" ? 0 : 180), [0,1,0])
block();
translate([0, CRANK/2, 0])
crank();
translate([0, MOTOR_SIZE+PISTON, 0])
spacer();
y = CYLINDERS == 4 ? MOTOR_SIZE : CRANK*3;
x = PISTON * 2;
offset = (CYLINDERS-1) * PISTON;
for (i = [0:CYLINDERS-1]) {
translate([-offset + x*i, -y-PISTON, 0]) {
piston();
translate([0, -PISTON-ROD, 0])
rod();
}
}
if (ENABLE_PROPELLER) {
translate([MOTOR_SIZE*2.5, 0, 0])
propeller();
}
}
// https://en.wikipedia.org/wiki/Piston_motion_equations#Crankshaft_geometry
function piston_height(angle) =
CRANK * cos(angle) + sqrt(ROD*ROD - CRANK*CRANK * sin(angle)*sin(angle));
module draw_combined(explode = 0) {
a = $t * 360 + 90; // angle of the crankshaft
z = 4 + explode*6 + TOLHALF; // base z height of connecting rods
nudge = 45;
offset = (CYLINDERS-1) * (CYLINDER_ANGLE/2) - nudge;
color("LightGrey")
translate([0, 0, 4-BLOCK-explode])
rotate([0, 0, offset])
block();
color("SlateGrey")
translate([0, 0, 4-BLOCK+explode])
rotate([0, 0, a])
spacer();
color("SlateGrey")
translate([0, 0, 2+explode*2])
rotate([0, 0, a])
crank();
for (i = [0:CYLINDERS-1]) {
A = -i*CYLINDER_ANGLE + nudge; // angle of this piston sleeve iteration
O = i % 2; // is this an odd iteration?
color("SlateGrey")
rotate([0, 0, -A])
translate([0, piston_height(abs(180-A-a)), 2+explode*4])
piston();
color("LightGrey")
translate([sin(a)*CRANK, -cos(a)*CRANK, i*(1+TOLHALF/2) + z])
rotate([0, 0, asin(sin(a+A)*CRANK/ROD)-A]) {
if (O || (CYLINDERS==3 && i==2)) {
rotate([0, 180, 0])
translate([0, 0, -1])
rod();
}
else {
rod();
}
}
}
if (ENABLE_PROPELLER) {
translate([0, 0, 7+PIN_HEIGHT+TOLHALF+explode*7])
rotate([180, 0, a-90])
propeller();
}
}
/**************************************************
* Modules for building each part of the engine *
**************************************************/
module pin() {
// Pin body
cylinder(r = PIN, h = PIN_HEIGHT);
// Upper cone
translate([0, 0, PIN_HEIGHT+0.5])
cylinder(r1 = PIN + 0.5, r2 = PIN, h = 0.5);
// Lower cone
translate([0, 0, PIN_HEIGHT])
cylinder(r1 = PIN, r2 = PIN + 0.5, h = 0.5);
}
module crank() {
translate([0, -CRANK, 0])
union() {
pin();
// Middle filler
translate([-4, 0, 0])
cube([8, CRANK, 2]);
// Lower circle
cylinder(r = 4, h = 2);
// Upper circle
translate([0, CRANK, 0])
cylinder(r = 4, h = 2);
if (ENABLE_PROPELLER) {
p = PIN * 2 / SQRT2; // pin size
translate([0, 0, PIN_HEIGHT+3])
cube([p, p, 4], true);
}
}
}
module spacer() {
cylinder(r = 4, h = BLOCK-2); // crankshaft spacer
}
// Connecting rod ring with a split for flexing over the pin head
module ring(height) {
difference() {
cylinder(r = PIN+TOLHALF+1, h = height);
translate([0, 0, -1])
cylinder(r = PIN+TOLHALF, h = height+2);
translate([-TOLERANCE/2, 0, -1])
cube([TOLERANCE, PIN+TOLERANCE+1, height+2]);
}
}
module rod() {
union() {
difference() {
union() {
// Half height ring
rotate([0, 0, 180])
ring(CYLINDERS == 1 ? 2 : 1);
// Middle bar
translate([-1, PIN+TOLERANCE+1, 0])
cube([2, ROD-PIN*2-TOLERANCE*1.5-1, 2]);
// Lower bar filler
translate([-1, PIN+TOLHALF, 0])
cube([2, 2, CYLINDERS == 1 ? 2 : 1]);
}
}
// Full height ring
translate([0, ROD, 0])
ring(2);
}
}
module piston_body() {
w = PISTON + 2;
a = (w-TOLERANCE*2) / SQRT2;
s = PISTON - TOLERANCE*2;
translate([0, 0, 1])
difference() {
rotate([0, 45, 0])
cube([a, PISTON, a], true); // main piston body
translate([0, 0, PISTON/2+1])
cube([s, PISTON+1, PISTON], true); // flatten top
translate([0, 0, -PISTON/2-1])
cube([s, PISTON+1, PISTON], true); // flatten bottom
}
}
module piston() {
union() {
pin();
difference() {
piston_body();
// curved cutout
translate([0, -CRANK*2+1, -1])
cylinder(r = CRANK+1, h = 4);
}
}
}
module mount_magnet() {
ir = MAGNET_DIAMETER / 2;
or = ir + 2;
w = or * 2;
difference() {
cylinder(r = or, h = MAGNET_HEIGHT); // outside diameter
translate([0, 0, -1])
cylinder(r = ir, h = MAGNET_HEIGHT+2); // inside diameter
translate([0, -or, MAGNET_HEIGHT-1])
rotate(30, [1,0,0])
translate([-w/2, 0, 0])
cube([w, w, MAGNET_HEIGHT]); // Diagonal ramp
}
if (ir+2 <= PISTON/2) {
for (i = [0:2])
rotate(90*i, [0,0,1])
translate([ir+1, -1, 0])
cube([PISTON/2-ir, 2, 2]);
}
}
module mount_tab() {
d = MOUNT_TAB_R/2;
w = PISTON + 2*WALL;
translate([0, 0, -1])
difference() {
cylinder(r = MOUNT_TAB_R, h = 1); // outside diameter
translate([0, 0, -1])
cylinder(r = MOUNT_TAB_R-0.6, h = 3); // inside diameter
}
// upper crossmember
translate([-w/2, MOUNT_TAB_R-2, 0])
cube([w, 2, 1]);
// lower crossmember
translate([-w/2, -MOUNT_TAB_R, 0])
cube([w, 2, 1]);
// right support
translate([MOUNT_TAB_R-1, -MOUNT_TAB_R/2, 0])
cube([1, MOUNT_TAB_R, 0.5]);
// left support
translate([-MOUNT_TAB_R, -MOUNT_TAB_R/2, 0])
cube([1, MOUNT_TAB_R, 0.5]);
}
module mounts() {
s = MOTOR_SIZE / 2 * SQRT2;
offset = (CYLINDERS-1) * CYLINDER_ANGLE/2;
for (i = [0:CYLINDERS-1])
rotate([0, 0, offset-i*CYLINDER_ANGLE])
translate([0, s, 0]) {
if (MOUNTING_TYPE == "Magnet") {
mount_magnet();
}
else if (MOUNTING_TYPE == "Press-fit tab") {
mount_tab();
}
}
}
module sleeve_outline() {
w = PISTON + 2*WALL;
W = w + 2;
a = W / SQRT2;
if (WALL < 2)
translate([0, SLEEVE/2, BLOCK-1])
intersection() {
rotate([0, 45, 0])
cube([a, SLEEVE, a], true); // piston track bulge
cube([W, SLEEVE, 2], true); // flatten top
}
translate([-w/2, 0, 0])
cube([w, SLEEVE, BLOCK]);
}
module sleeve_cutout() {
a = (PISTON+2) / SQRT2;
translate([-PISTON/2, -WALL, -1])
cube([PISTON, SLEEVE, BLOCK+2]);
translate([0, SLEEVE/2 - WALL, BLOCK-1])
rotate([0, 45, 0])
cube([a, SLEEVE, a], true); // piston track grooves
}
module sleeve() {
difference() {
sleeve_outline();
sleeve_cutout();
}
}
module block() {
offset = (CYLINDERS-1) * CYLINDER_ANGLE/2;
union() {
difference() {
union() {
for (i = [0:CYLINDERS-1])
rotate([0, 0, offset-i*CYLINDER_ANGLE])
sleeve_outline();
// block housing outer wall
cylinder(r = CRANK+5+WALL, h = BLOCK);
}
for (i = [0:CYLINDERS-1])
rotate([0, 0, offset-i*CYLINDER_ANGLE])
sleeve_cutout();
// block housing inner wall
translate([0, 0, -1])
cylinder(r = CRANK+5, h = BLOCK+2);
}
mounts();
}
}
module propeller_blade() {
l = MOTOR_SIZE + 4; // length of propeller blade
translate([l/2+l/10, 0, 0]) {
linear_extrude(2) {
hull() {
scale([1, 0.25, 1])
circle(d = l); // main body
translate([-l/2-l/10, 0, 0])
square(PROPELLER_BLADES>5 ? 1/PROPELLER_BLADES : 3, true);
translate([l/2-l/40, -l/15*PROPELLER_DIRECTION, 0])
circle(d = l/20); // wingtip
}
}
}
}
module propeller() {
p = (PIN * 2 + TOLHALF) / SQRT2; // pin size
a = 360 / PROPELLER_BLADES;
s = PIN*2+TOLERANCE*2; // pin slot extension size
difference() {
union() {
cylinder(d = 8, h = 2); // center hub
for (i = [0:PROPELLER_BLADES-1]) {
rotate(a*i, [0,0,1])
propeller_blade();
}
translate([CRANK-s/2, -s/2, 0])
cube([s, s, 4]); // pin slot extension
}
translate([CRANK, 0, 2])
cube([p+0.1, p+0.1, 6], true); // pin slot
}
}