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