chiark / gitweb /
air-hockey-puck: 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 // ========== 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 HalfClampX(flatten=false){
183   difference(){
184     translate([0,0, min_z]) {
185       linextr(0, total_z) mirror([0,1]) MainPlanB();
186       for (i=[0 : hinge_units-1]) {
187         translate([0,0, stride_z*i])
188           linextr(0, hinge_unit) MainPlanA(flatten);
189       }
190     }
191     for (j=[0:nbolts-1]) {
192       translate([ bolt_x, 0, min_z + (j + 0.5) * bolt_stride ]) {
193         translate([0, -tube_dia/2, 0])
194           rotate([-90,0,0])
195           cylinder(r= bolt_hole_r, h= tube_dia);
196         translate([0, -flats_y, 0])
197           rotate([90,0,0])
198           cylinder(r= bolt_flat/2, h= tube_dia/2);
199       }
200     }
201   }
202 }
203
204 // ---------- vhook ----------
205
206 module VHookProfile() {
207   translate([0, -vhook_inside/2 - vhook_th/2])
208     circle(r = vhook_th/2);
209 }
210
211 module VHookHookMain(outer=false){ ////toplevel
212   rotate([0,90,0])
213     rotate_extrude(convexity=10)
214     rotate([0,0,90])
215     hull(){
216       VHookProfile();
217       if (outer) {
218         translate([0,-vhook_outer_dia]) square(center=true, vhook_th);
219       }
220     }
221 }
222
223 module VHookA(){ ////toplevel
224   DummyA();
225
226   translate([0, vhook_ctr, 0]){
227     for (m=[0,1]) {
228       mirror([0, m, 0]) {
229         linextr(-0.1, vhook_outer_dia/2)
230           VHookProfile();
231         translate([0, -vhook_inside/2 -vhook_th/2, vhook_outer_dia/2])
232           sphere(r= vhook_th/2);
233       }
234     }
235
236     intersection(){
237       VHookHookMain(outer=true);
238       linextr_y_xz(0, vhook_outer_dia/2) hull(){
239         VHookProfile();
240         translate([0,-0.1]) square(center=true, [vhook_th, 0.2]);
241       }
242     }
243
244     intersection(){
245       VHookHookMain();
246       translate([0,0, -vhook_outer_dia])
247         cube(center=true, vhook_outer_dia*2);
248     }
249   }
250
251   //translate([0, vhook_y0, 50]) rotate([0,0,-90]) color("black") cube(10);
252   // translate([0,0,-150]) rotate([0,0,180 + theta]) color("blue") cube(100);
253 }
254
255 module VHookPlanDemo(){
256   MainPlanA();
257   translate([0, vhook_ctr, 5])
258     for (m=[0,1]) {
259       mirror([0,m])
260         color("blue") VHookProfile();
261     }
262 }
263
264 // ---------- cleat ----------
265
266 function cleat_frame_theta(s) = s * cleat_horn_tl / cleat_curve_r * 360/TAU;
267 function cleat_frame_z(s) = cleat_curve_r * (1 - cos(cleat_frame_theta(s)));
268 function cleat_frame_x(s) = cleat_curve_r * sin(cleat_frame_theta(s));
269 function cleat_frame_r(s) = ( cleat_horn_d_min * s +
270                               cleat_horn_d_max * (1-s) ) * 0.5;
271
272 module CleatFrameSphere(r) {
273   scale([1, r[1]/r[0], 1])
274     sphere(r= r[0]);
275 }
276
277 module CleatFrame(s) {
278   r = cleat_frame_r(s);
279   translate([cleat_frame_x(s), 0, cleat_frame_z(s)])
280     rotate([0, 90, 0])
281     CleatFrameSphere(r);
282 }
283
284
285 module CleatHorn(){
286   for (si=[0 : cleat_frames-2]) {
287     s0 = si / (cleat_frames-1);
288     s1 = (si+1) / (cleat_frames-1);
289     hull(){
290       CleatFrame(s0);
291       CleatFrame(s1);
292     }
293   }
294 }
295
296 module CleatBase(){
297   frames = cleat_frames/2;
298   se = cleat_stem_l/2 / cleat_horn_tl;
299   r = cleat_frame_r(se);
300
301   hull(){
302     for (s = [-se, se]) {
303       for (z= [-(cleat_height + tube_dia/2),
304                cleat_frame_z(s)]) {
305         translate([cleat_frame_x(s), 0, z])
306           linear_extrude(height=0.1)
307           scale([1, r[1]/r[0]])
308           circle(r=r[0]);
309       }
310     }
311   }
312 }
313
314 module VCleat(){
315   intersection(){
316     translate([0,0, vcleat_dz]){
317       difference(){
318         translate([0, -(main_r + cleat_height), 0]) {
319           rotate([0, -90, 90]) {
320             CleatBase();
321             for (m=[0,1]) {
322               mirror([m,0,0]) {
323                 CleatHorn();
324               }
325             }
326           }
327         }
328         linextr(-cleat_stem_l, +cleat_stem_l)
329           circle(r = tube_dia/2 + 0.1);
330       }
331     }
332       translate([0,0, total_z * 0.5])
333         cube(center=true,
334              (main_r + cleat_stem_l)*4 * [1,1,0] +
335              total_z * [0,0,2]);
336   }
337 }
338
339 module VCleatA(){ ////toplevel
340   DummyA();
341   VCleat();
342 }
343
344 // ---------- hhook ----------
345
346 module HHookHookPlan(){
347   translate([0, hhook_ctr]){
348     difference(){
349       circle(r = hhook_outer_dia/2);
350       circle(r = hhook_inside/2);
351       rectfromto([+hhook_outer_dia, -hhook_outer_dia],
352                  [0,                +hhook_outer_dia]);
353     }
354     translate([0, -(hhook_inside/2 + hhook_th/2)]){
355       hull(){
356         for (x=[-0.1, hhook_l]) {
357           translate([x,0]) square(center=true, hhook_th);
358         }
359       }
360     }
361   }
362 }
363
364 module HHookA(){ ////toplevel
365   DummyA();
366   linextr(min_z, max_z) {
367     HHookHookPlan();
368   }
369 }
370
371 module HHookPlanDemo(){
372   MainPlanA();
373   HHookHookPlan();
374 }
375
376 // ---------- misc ----------
377
378 module PinSitu(){ ////toplevel
379   difference(){
380     union(){
381       translate([0,0, -pin_head_th])
382         cylinder(r= pin_dia/2, h = total_z + pin_head_th + pin_tail);
383       mirror([0,0,1])
384         cylinder(r= hinge_o_r - pin_gap, h = pin_head_th);
385     }
386     translate([0,0, total_z + pin_tail/2])
387       rotate([0,90,0])
388       translate([0,0, -pin_dia])
389       cylinder(r= pin_hole_dia/2, h=pin_dia*2);
390     translate([pin_dia/2 * cos(45), -50, -pin_head_th*2])
391       cube([50,100, total_z*2]);
392   }
393 }
394
395 module Pin(){ ////toplevel
396   rotate([0,90,0]) {
397     PinSitu();
398   }
399 }
400
401 module GeneralB(){ ////toplevel
402   HalfClampX(true);
403 }
404
405 module DummyA(){ ////toplevel
406   HalfClampX();
407 }
408
409 module PlanDemo(){ ////toplevel
410   MainPlan();
411   translate([0,0,-4]) color("red") Portion(1);
412   translate([0,0,-2]) color("grey") Portion(0);
413
414   translate([0, tube_dia*1.5]) {
415     MainPlanB();
416     MainPlanA();
417   }
418
419   translate([0, -tube_dia*1.5]) {
420     VHookPlanDemo();
421   }
422   translate([tube_dia*4, 0]) {
423     HHookPlanDemo();
424   }
425 //  translate([max_x - hinge_x + 20, 0]) color("blue") MainPlanA();
426 }
427
428 module DemoA(){ DummyA(); }
429
430 module Demo(){ ////toplevel
431   color("red") rotate([180,0,0]) GeneralB();
432   color("blue") DemoA();
433   color("orange") translate([hinge_x, 0, min_z - hinge_z_gap])
434     rotate([0,0,180]) PinSitu();
435 }
436
437 module DemoPair(){ ////toplevel
438   color("red") rotate([180,0,0]) DemoA();
439   color("blue") DemoA();
440   color("orange") translate([hinge_x, 0, min_z - hinge_z_gap])
441     rotate([0,0,180]) PinSitu();
442 }
443
444 //PlanDemo();
445 //HalfClamp();