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