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