chiark / gitweb /
scaffold-clamp-linear-bracket: wip
[reprap-play.git] / scaffold-clamp-common.scad
1 // -*- C -*-
2
3 include <utils.scad>
4
5 tube_dia = 48.3;
6
7 th = 7;
8
9 pin_gap = 1.5; // around
10
11 smooth_r = 15;
12
13 bolt_dia = 5;
14 bolt_flat = 10 + 1;
15
16 nbolts = 2;
17
18 open_gap = 10;
19
20 hinge_unit = 10;
21 hinge_z_gap = 1;
22
23 hinge_units = 4;
24
25 bolt_gap = 1.0; // total, on both sides
26
27 // ---------- vhook ----------
28
29 vhook_th = 14;
30
31 // ---------- cleat ----------
32
33 cleat_frames = 10;
34 cleat_curve_r = 200;
35 cleat_horn_l = 40;
36 cleat_horn_d_min = [10, 12];
37 cleat_horn_d_max = [12, 14];
38 cleat_height = 25;
39 cleat_stem_l = 20;
40
41 cleat_overlap = (1-cos(60));
42
43 // ---------- hhook ----------
44
45 hhook_inside = 40;
46 hhook_th = 4;
47 hhook_l = 40;
48
49 // ---------- linear bracket ----------
50
51 linear_bracket_h = 50;
52 linear_bracket_l = 1000;
53
54 // ========== defaults ==========
55
56 pin_head_th = th/2;
57 pin_dia = th;
58 pin_hole_dia = pin_dia/2;
59 pin_tail = pin_hole_dia + pin_head_th + hinge_z_gap*3;
60
61 // ========== calculated ==========
62
63 TAU = PI*2;
64
65 hole_dia = th + pin_gap;
66
67 bolt_hole_r = (bolt_dia + bolt_gap)/2;
68
69 main_r = tube_dia/2 + th;
70
71 hinge_gap = pin_gap;
72
73 hinge_o_r = 0.5 * hole_dia + th;
74
75 hinge_x = -0.5 * tube_dia - hinge_o_r;
76 bolt_x = 0.5 * tube_dia + th + bolt_flat * 0.5;
77 max_x = bolt_x + max(bolt_hole_r + th, 0.5 * bolt_flat/2);
78
79 flats_y = open_gap/2 + th;
80
81 stride_z = hinge_unit*2 + hinge_z_gap*2;
82 total_z = hinge_units * stride_z - hinge_z_gap;
83
84 min_z = -total_z/2;
85 max_z = +total_z/2;
86
87 pin_flatten = pin_dia/2 * (1 - cos(45));
88
89 bolt_stride = total_z / nbolts;
90
91 // calculated - vhook
92
93 vhook_inside = 15;
94
95 vhook_theta = atan2( smooth_r, main_r );
96
97 vhook_y0 = -max(main_r, (tube_dia/2 + vhook_th));
98 vhook_ctr = vhook_y0 - vhook_inside/2;
99 vhook_outer_dia = vhook_inside + vhook_th*2;
100
101 // calculated - cleat
102
103 cleat_horn_tl = cleat_horn_l + cleat_stem_l/2;
104
105 vcleat_dz = max(0,
106                 cleat_horn_tl
107                 + cleat_horn_d_min[0]/2
108                 - cleat_horn_d_min[0]/2 * cleat_overlap
109                 - total_z/2
110                 );
111
112 // calculated - hhook
113
114 hhook_outer_dia = hhook_inside + hhook_th*2;
115
116 hhook_ctr = -max(main_r + hhook_inside/2,
117                  tube_dia/2 + hhook_outer_dia/2);
118
119 $fa = 3;
120 $fs = 0.1;
121
122 module SmoothPlan(){
123   offset(r=-smooth_r) offset(delta=smooth_r) children(0);
124 }
125
126 module TubePlan(){ circle(r = tube_dia/2); }
127 module MainCirclePlan(){ circle(r = main_r); }
128
129 module PlanWeldMainCircle(){
130   intersection(){
131     difference(){
132       SmoothPlan(){
133         union(){
134           MainCirclePlan();
135           children(0);
136         }
137       }
138       TubePlan();
139     }
140     rotate(-135) square(100);
141   }
142 }
143
144 module MainPlan(flatten=false) {
145   difference(){
146     SmoothPlan()
147       union(){
148       translate([hinge_x, 0]) circle(r= hinge_o_r);
149       MainCirclePlan();
150       rectfromto([0,           -flats_y],
151                  [max_x,       +flats_y]);
152     }
153     TubePlan();
154     rectfromto([0,       -open_gap/2],
155                [max_x+1, +open_gap/2]);
156     translate([hinge_x, 0]) {
157       intersection(){
158         circle(r= hole_dia/2);
159         if (flatten)
160           translate([ pin_flatten, 0 ])
161           square(center=true, [hole_dia, hole_dia + 1]);
162       }
163     }
164   }
165 }
166
167 module Portion(d=0) {
168   translate([hinge_x, 0]) circle(r= hinge_o_r + d);
169   rectfromto([hinge_x*2, 0],
170              [max_x+10, -(tube_dia/2+th+10)]);
171 }
172
173 module MainPlanA(flatten){
174   intersection(){
175     MainPlan(flatten);
176     Portion(0);
177   }
178 }
179
180 module MainPlanB(flatten){
181   difference(){
182     MainPlan(flatten);
183     Portion(hinge_gap);
184   }
185 }
186
187 module HalfClampXPositive(flatten=false){
188   translate([0,0, min_z]) {
189     linextr(0, total_z) mirror([0,1]) MainPlanB();
190     for (i=[0 : hinge_units-1]) {
191       translate([0,0, stride_z*i])
192         linextr(0, hinge_unit) MainPlanA(flatten);
193     }
194   }
195 }
196
197 module HalfClampXNegative(){
198   for (j=[0:nbolts-1]) {
199     translate([ bolt_x, 0, min_z + (j + 0.5) * bolt_stride ]) {
200       translate([0, -tube_dia/2, 0])
201         rotate([-90,0,0])
202         cylinder(r= bolt_hole_r, h= tube_dia);
203       translate([0, -flats_y, 0])
204         rotate([90,0,0])
205         cylinder(r= bolt_flat/2, h= tube_dia/2);
206     }
207   }
208 }
209
210 module HalfClampX(flatten=false){
211   difference(){
212     HalfClampXPositive(flatten);
213     HalfClampXNegative();
214   }
215 }
216
217 // ---------- vhook ----------
218
219 module VHookProfile() {
220   translate([0, -vhook_inside/2 - vhook_th/2])
221     circle(r = vhook_th/2);
222 }
223
224 module VHookHookMain(outer=false){ ////toplevel
225   rotate([0,90,0])
226     rotate_extrude(convexity=10)
227     rotate([0,0,90])
228     hull(){
229       VHookProfile();
230       if (outer) {
231         translate([0,-vhook_outer_dia]) square(center=true, vhook_th);
232       }
233     }
234 }
235
236 module VHookA(){ ////toplevel
237   DummyA();
238
239   translate([0, vhook_ctr, 0]){
240     for (m=[0,1]) {
241       mirror([0, m, 0]) {
242         linextr(-0.1, vhook_outer_dia/2)
243           VHookProfile();
244         translate([0, -vhook_inside/2 -vhook_th/2, vhook_outer_dia/2])
245           sphere(r= vhook_th/2);
246       }
247     }
248
249     intersection(){
250       VHookHookMain(outer=true);
251       linextr_y_xz(0, vhook_outer_dia/2) hull(){
252         VHookProfile();
253         translate([0,-0.1]) square(center=true, [vhook_th, 0.2]);
254       }
255     }
256
257     intersection(){
258       VHookHookMain();
259       translate([0,0, -vhook_outer_dia])
260         cube(center=true, vhook_outer_dia*2);
261     }
262   }
263
264   //translate([0, vhook_y0, 50]) rotate([0,0,-90]) color("black") cube(10);
265   // translate([0,0,-150]) rotate([0,0,180 + theta]) color("blue") cube(100);
266 }
267
268 module VHookPlanDemo(){
269   MainPlanA();
270   translate([0, vhook_ctr, 5])
271     for (m=[0,1]) {
272       mirror([0,m])
273         color("blue") VHookProfile();
274     }
275 }
276
277 // ---------- cleat ----------
278
279 function cleat_frame_theta(s) = s * cleat_horn_tl / cleat_curve_r * 360/TAU;
280 function cleat_frame_z(s) = cleat_curve_r * (1 - cos(cleat_frame_theta(s)));
281 function cleat_frame_x(s) = cleat_curve_r * sin(cleat_frame_theta(s));
282 function cleat_frame_r(s) = ( cleat_horn_d_min * s +
283                               cleat_horn_d_max * (1-s) ) * 0.5;
284
285 module CleatFrameSphere(r) {
286   scale([1, r[1]/r[0], 1])
287     sphere(r= r[0]);
288 }
289
290 module CleatFrame(s) {
291   r = cleat_frame_r(s);
292   translate([cleat_frame_x(s), 0, cleat_frame_z(s)])
293     rotate([0, 90, 0])
294     CleatFrameSphere(r);
295 }
296
297
298 module CleatHorn(){
299   for (si=[0 : cleat_frames-2]) {
300     s0 = si / (cleat_frames-1);
301     s1 = (si+1) / (cleat_frames-1);
302     hull(){
303       CleatFrame(s0);
304       CleatFrame(s1);
305     }
306   }
307 }
308
309 module CleatBase(){
310   frames = cleat_frames/2;
311   se = cleat_stem_l/2 / cleat_horn_tl;
312   r = cleat_frame_r(se);
313
314   hull(){
315     for (s = [-se, se]) {
316       for (z= [-(cleat_height + tube_dia/2),
317                cleat_frame_z(s)]) {
318         translate([cleat_frame_x(s), 0, z])
319           linear_extrude(height=0.1)
320           scale([1, r[1]/r[0]])
321           circle(r=r[0]);
322       }
323     }
324   }
325 }
326
327 module VCleat(){
328   intersection(){
329     translate([0,0, vcleat_dz]){
330       difference(){
331         translate([0, -(main_r + cleat_height), 0]) {
332           rotate([0, -90, 90]) {
333             CleatBase();
334             for (m=[0,1]) {
335               mirror([m,0,0]) {
336                 CleatHorn();
337               }
338             }
339           }
340         }
341         linextr(-cleat_stem_l, +cleat_stem_l)
342           circle(r = tube_dia/2 + 0.1);
343       }
344     }
345       translate([0,0, total_z * 0.5])
346         cube(center=true,
347              (main_r + cleat_stem_l)*4 * [1,1,0] +
348              total_z * [0,0,2]);
349   }
350 }
351
352 module VCleatA(){ ////toplevel
353   DummyA();
354   VCleat();
355 }
356
357 // ---------- hhook ----------
358
359 module HHookHookPlan(){
360   translate([0, hhook_ctr]){
361     difference(){
362       circle(r = hhook_outer_dia/2);
363       circle(r = hhook_inside/2);
364       rectfromto([+hhook_outer_dia, -hhook_outer_dia],
365                  [0,                +hhook_outer_dia]);
366     }
367     translate([0, -(hhook_inside/2 + hhook_th/2)]){
368       hull(){
369         for (x=[-0.1, hhook_l]) {
370           translate([x,0]) square(center=true, hhook_th);
371         }
372       }
373     }
374   }
375 }
376
377 module HHookA(){ ////toplevel
378   DummyA();
379   linextr(min_z, max_z) {
380     HHookHookPlan();
381   }
382 }
383
384 module HHookPlanDemo(){
385   MainPlanA();
386   HHookHookPlan();
387 }
388
389 // ---------- linear bracket ----------
390
391 module LinearBracketA(){ ////toplevel
392   difference(){
393     union(){
394       HalfClampXPositive();
395       linextr_y_xz(-open_gap/2 - 1, -open_gap/2)
396         mirror([1,0,0])
397         rectfromto([0, min_z],
398                    [max_x + linear_bracket_l, min_z + linear_bracket_h]);
399     }
400     HalfClampXNegative();
401   }
402 }
403
404 // ---------- misc ----------
405
406 module PinSitu(){ ////toplevel
407   difference(){
408     union(){
409       translate([0,0, -pin_head_th])
410         cylinder(r= pin_dia/2, h = total_z + pin_head_th + pin_tail);
411       mirror([0,0,1])
412         cylinder(r= hinge_o_r - pin_gap, h = pin_head_th);
413     }
414     translate([0,0, total_z + pin_tail/2])
415       rotate([0,90,0])
416       translate([0,0, -pin_dia])
417       cylinder(r= pin_hole_dia/2, h=pin_dia*2);
418     translate([pin_dia/2 * cos(45), -50, -pin_head_th*2])
419       cube([50,100, total_z*2]);
420   }
421 }
422
423 module Pin(){ ////toplevel
424   rotate([0,90,0]) {
425     PinSitu();
426   }
427 }
428
429 module GeneralB(){ ////toplevel
430   HalfClampX(true);
431 }
432
433 module DummyA(){ ////toplevel
434   HalfClampX();
435 }
436
437 module PlanDemo(){ ////toplevel
438   MainPlan();
439   translate([0,0,-4]) color("red") Portion(1);
440   translate([0,0,-2]) color("grey") Portion(0);
441
442   translate([0, tube_dia*1.5]) {
443     MainPlanB();
444     MainPlanA();
445   }
446
447   translate([0, -tube_dia*1.5]) {
448     VHookPlanDemo();
449   }
450   translate([tube_dia*4, 0]) {
451     HHookPlanDemo();
452   }
453 //  translate([max_x - hinge_x + 20, 0]) color("blue") MainPlanA();
454 }
455
456 module DemoA(){ DummyA(); }
457
458 module Demo(){ ////toplevel
459   color("red") rotate([180,0,0]) GeneralB();
460   color("blue") DemoA();
461   color("orange") translate([hinge_x, 0, min_z - hinge_z_gap])
462     rotate([0,0,180]) PinSitu();
463 }
464
465 module DemoPair(){ ////toplevel
466   color("red") rotate([180,0,0]) DemoA();
467   color("blue") DemoA();
468   color("orange") translate([hinge_x, 0, min_z - hinge_z_gap])
469     rotate([0,0,180]) PinSitu();
470 }
471
472 //PlanDemo();
473 //HalfClamp();