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