-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.scad
398 lines (343 loc) · 11 KB
/
util.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
// utility functions
function xor(a,b) = (a && !b) || (!a && b);
// makes a number of clones of a supbtreem/ rotated and spaced evenly around the origin
module rotational_clone(clones=2) {
for(i=[0:clones-1] ) {
rotate([0,0,i * (360/clones)]) children();
}
}
/* one take on 'loft' - takes pairs of bounding boxes and then the model as the final child.
* joins the parts of the model within the bounding pairs, ideally connecting convex surfaces,
* while preserving the concavity of the model */
module bounded_hull() {
end=$children-1;
union() {
children(end);
for(i=[0:2:end-1-(end%2)]) {
difference() {
hull() {
intersection() {
children(end);
children(i);
}
intersection() {
children(end);
children(i+1);
}
}
hull() intersection() {
children(end);
children(i);
}
hull() intersection() {
children(end);
children(i+1);
}
}
}
}
}
/* similar to bounded hull, but instead of taking pairs of bounds, connects all the bounds in sequence,
* wrapping at the end, to make a hamiltonian circuit. */
module bounded_hull_circuit() {
function nextwrap(i) = i+1 == $children-1 ? 0 : i+1;
end=$children-1;
union() {
children(end);
for(i=[0:end-1]) {
difference() {
hull() {
intersection() {
children(end);
children(i);
}
intersection() {
children(end);
children(nextwrap(i));
}
}
hull() intersection() {
children(end);
children(i);
}
hull() intersection() {
children(end);
children(nextwrap(i));
}
}
}
}
}
/* similar to bounded hull, but takes an array of vectors, each of which specifies 2 or more
* bounding boxes to be connected. can be upsed with pairs similarly to bounded_hull, but without
* having to potentially duplicate bounding boxes, or in a more free-form manner to build a
* non-convex hull out of convex subsets of bounds.
*/
module bounded_hull_stipulated(sets=[]) {
end=$children-1;
union() {
children(end);
for(set=sets){
difference() {
hull() intersection() {
children(end);
children(set);
}
for(i=set) {
hull() intersection() {
children(end);
children(i);
}
}
}
}
/*for(i=pair) {
difference() {
hull() {
intersection() {
children(end);
children(i[0]);
}
intersection() {
children(end);
children(i[1]);
}
}
hull() intersection() {
children(end);
children(i[0]);
}
hull() intersection() {
children(end);
children(i[1]);
}
}
}*/
}
}
// adds a mount for a cup magnet at a given position
module magnetize(position=[0,0,0], cut_height=9, post_height=12) {
union() {
difference() {
/* idk why you would call this on a set of objects since there is only one position, but just
* in case union the children because otherwise the difference will subtract the subsequent
* children from the first one
*/
union(){
children();
}
/* a loose fitting hole for the magnet, bringing it is closer to the work surface (force is
* proportional to the square of distance), maybe also provides some support when moving laterally
*/
translate(position) cylinder(cut_height,d=33,$fn=64);
}
// change diameter if you need to accomodate a different screw size
translate(position) cylinder(post_height,d=3.5,$fn=64);
}
}
// adds a mount for a cup magnet at a given position
module magnetize_screwed(position=[0,0,0], cut_height=9) {
epsilon=.1;
difference() {
/* idk why you would call this on a set of objects since there is only one position, but just
* in case union the children because otherwise the difference will subtract the subsequent
* children from the first one
*/
union(){
children();
}
/* a loose fitting hole for the magnet, bringing it is closer to the work surface (force is
* proportional to the square of distance), maybe also provides some support when moving laterally
*/
translate(position+[0,0,2]) cylinder(cut_height,d=33,$fn=60);
translate(position) cylinder(h=cut_height, d=3.8, $fn=60);
translate(position+[0,0,-epsilon]) cylinder(h=2+epsilon, d1=7.1, d2=3.8, $fn=60);
}
}
*magnetize_screwed() translate([0,0,2]) cube([75,75,4], true);
module bar_magnetize_below(position=[0,0,0], rotation=[0,0,0], spacer=0, walls=2, ceiling=2, washer=0, grow=[0,0,0]) {
bar = [14, 60.5, 5.5+1];
epsilon=.1;
outer = bar+[2*walls,2*walls,ceiling+spacer];
difference() {
union(){
children();
translate(position) rotate(rotation)
translate([-outer.x/2+min(grow.x,0),-outer.y/2+min(grow.y,0),0])
cube(outer+[abs(grow.x),abs(grow.y),abs(grow.z)]);
}
translate(position) rotate(rotation) {
translate([0,0,(bar.z/2 + spacer - epsilon)]) cube(bar+[0,0,epsilon*2], true);
rotational_clone() translate([0,45/2,0]) cylinder($fn=60,h=2*(outer.z+epsilon), d=3.6, center=true);
}
if (washer>0) {
translate(position) rotate(rotation) {
rotational_clone() translate([0,45/2,outer.z]) cylinder($fn=60,h=100, d=washer);
}
}
}
}
*bar_magnetize_below() translate([0,0,2]) cube([50,75,4], true);
module bar_magnetize(position=[0,0,0], spacer=2) {
bar = [14, 60.5, 5.5];
epsilon=.1;
difference() {
children();
translate(position) rotate(rotation) {
translate([0,0,(bar.z/2 + spacer + epsilon)]) cube(bar+[0,0,epsilon*2], true);
rotational_clone() translate([0,45/2,-epsilon]) cylinder($fn=60,h=spacer+2*epsilon, d=3.4);
rotational_clone() translate([0,45/2,-epsilon]) cylinder($fn=60,h=2+2*epsilon, d1=5.6, d2=3.4);
}
}
}
*bar_magnetize() translate([0,0,2]) cube([50,75,4], true);
module mount_teensy20pp(position=[0,0,0], rotation=[0,0,0], spacer=2, walls=2, diode=false) {
slop =.1;
bar = [18.2+slop, 51.2+slop, 8+spacer];
epsilon=.1;
outer = bar+[2*walls,2*walls,0];
if ($preview) {
translate(position) rotate(rotation) let(z1=18.5,z2=23-18.5) translate([0,0,spacer]) {
color("black", .2) translate([0,0,z1/2]) cube(bar + [0,0,z1 - bar.z], true);
color("blue", .2) translate([0,0,z1+z2/2]) cube(bar + [0,0,z2 - bar.z], true);
}
}
pitch=2.54;
difference() {
union(){
children();
translate(position) rotate(rotation)
translate([0,0,(outer.z/2)]) cube(outer, true);
}
translate(position) rotate(rotation) {
// cavity for teensy
translate([0,0,(bar.z/2 + spacer + epsilon)]) cube(bar+[0, 0, epsilon*2], true);
// for pin headers
rotational_clone() translate([bar.x/2-1, 0, spacer]) cube([2, bar.y, 2],true);
// bonus interior pins
translate([0, -pitch/2-3*pitch, spacer]) cube([2, 4*pitch+2, 2], true);
translate([pitch, -pitch/2-3*pitch, spacer]) cube([2, 4*pitch+2, 2], true);
// reversed for when reflected for opposite hand
translate([-pitch, -pitch/2-3*pitch, spacer]) cube([2, 4*pitch+2, 2], true);
// reset pins
translate([0,-pitch/2 - 9*pitch, spacer]) cube([bar.x, 2 , 2], true);
// usb
translate([0, bar.y/2, bar.z/2+spacer+7/2]) cube([11, 40, bar.z+7],true);
// for VBUS detect shottky
if (diode) translate([0,(pitch/2)+(4*pitch)+(pitch*3/2),spacer]) cube([8,pitch*3,4],true);
}
}
}
*mount_teensy20pp() translate([0,0,2]) cube([50,75,4], true);
module mount_trrs(position=[0,0,0], rotation=[0,0,0], spacer=2, walls=2) {
slop = .1;
bar = [6.5+slop, 12.5+slop, 8 + spacer];
epsilon=.1;
outer = bar + [2*walls,2*walls,0];
difference() {
union(){
children();
translate(position) rotate(rotation)
translate([0,0,(outer.z/2)]) cube(outer, true);
}
translate(position) rotate(rotation) {
// cavity for jack
translate([0,0,(bar.z/2 + spacer + epsilon)]) cube(bar+[0, 0, epsilon*2], true);
// connector
translate([0, bar.y/2, bar.z/2+spacer+epsilon/2]) cube([5.5, (epsilon+max(2,walls))*2, bar.z+epsilon],true);
// plug
translate([0, bar.y/2+walls, spacer+2.5]) rotate([-90,0,0]) cylinder($fn=60, d=6.25, h=50);
}
}
translate(position) rotate(rotation)
translate([bar.x/2, 0, 5.4]) rotate([90,0,0]) cylinder($fn=60, d=.3, h=8, center=true);
}
*mount_trrs() translate([0,0,2]) cube([30,30,4], true);
module mount_permaproto_flat(position=[0,0,0], rotation=[0,0,0], spacer=4+2.5, margin=2,washer_dia=6.4, screw_h=2.7) {
bar = [2,53,33];
if ($preview) {
translate(position+[bar.z,0,spacer]+[margin,margin,0]) rotate([0,-90,0]){
color("white", .4) cube(bar);
pitch=2.54;
translate([2,53/2,33/2]) rotate([0,90,0]) translate([0,0,17.5/2]) color("black", .2) cube([12*pitch,15*pitch,17.5], true);
}
}
children();
translate(position+[margin,margin,0]) let(w=bar.z,l=bar.y) {
difference() {
union() {
translate([-margin,-margin,0]) cube([w+margin*2, l+margin*2, 4]);
translate([0,l-8,0]) cube([8,8,spacer]);
translate([w-8,l-8,0]) cube([8,8,spacer]);
translate([0,0,0]) cube([8,8,spacer]);
translate([w-8,0,0]) cube([8,8,spacer]);
}
translate([4,l-4,0]) {
cylinder(d=3.4,h=30,center=true,$fn=60);
cylinder(d=washer_dia,h=screw_h*2,center=true,$fn=60);
}
translate([w-4,l-4,0]){
cylinder(d=3.4,h=30,center=true,$fn=60);
cylinder(d=washer_dia,h=screw_h*2,center=true,$fn=60);
}
translate([4,4,0]){
cylinder(d=3.4,h=30,center=true,$fn=60);
cylinder(d=washer_dia,h=screw_h*2,center=true,$fn=60);
}
translate([w-4,4,0]){
cylinder(d=3.4,h=30,center=true,$fn=60);
cylinder(d=washer_dia,h=screw_h*2,center=true,$fn=60);
}
}
}
}
mount_permaproto_flat();
module mount_permaproto(position=[0,0,0], rotation=[0,0,0], spacer=4.5, walls=2,rail1=15.5, rail2=20) {
bar = [2,53,33];
if ($preview) {
translate(position+[0,0,spacer]) {
color("white", .4) cube(bar);
pitch=2.54;
translate([2,53/2,33/2]) rotate([0,90,0]) translate([0,0,17.5/2]) color("black", .2) cube([12*pitch,15*pitch,17.5], true);
}
}
children();
let(w=6,l=53-2*4,h=4) {
translate(position+[2,4,0]){
// fill in between rails to help prevent peeling
cube([min(rail1,rail2), l, h]);
//support the ends of the rails
//cube([w,l,h]);
difference() {
union () {
translate([0,-w/2,0]) {
cube([w, w, spacer + bar.z]);
cube([rail2, w, h]);
}
}
translate([0,0,spacer+4]) rotate([0,90,0]) cylinder(d=3.4,h=20,center=true,$fn=60);
translate([0,0,spacer+33-4]) rotate([0,90,0]) cylinder(d=3.4,h=20,center=true,$fn=60);
}
translate([0,l,0]){
difference() {
union () {
translate([0,-w/2,0]) {
cube([w, w, spacer + bar.z]);
cube([rail1, w, h]);
}
}
translate([0,0,spacer+4]) rotate([0,90,0]) cylinder(d=3.4,h=20,center=true,$fn=60);
translate([0,0,spacer+33-4]) rotate([0,90,0]) cylinder(d=3.4,h=20,center=true,$fn=60);
}
}
}
}
}
*mount_permaproto();
module mount_foot(position=[0,0,0], rotation=[0,0,0], protrusion=.8) {
epsilon = .1;
difference() {
children();
translate(position-[0,0,protrusion+epsilon]) rotate(rotation) cylinder(d=8.3, h=2+epsilon);
}
}