chiark / gitweb /
sewing-table: Machine_Rear: adj rearcurve_rad_slop, ad-hoc
[reprap-play.git] / sewing-table.scad.m4
1 // -*- C -*-
2
3 include <funcs.scad>
4 include <commitid.scad>
5
6 ply_th = 18;
7 ply_hole_dia = 15;
8 ply_edge_min = 10;
9
10 tile_th = 3;
11 post_dia = 8;
12
13 post_shorter = 1;
14
15 screw_dia = 2.2;
16 screw_big_dia = 3.6;
17 screw_big_len = 4.0;
18
19 round_edge_rad = 2.0;
20
21 round_cnr_rad = 10;
22
23 interlock_dia = 10;
24 interlock_fine = 0.66;
25
26 interlock_fine_slope = 1.0;
27 interlock_fine_lenslop = 1.0;
28
29 demo_slop = 0.1;
30
31 // cutout
32
33 cutout_l_end_y_front_slop = 0.5;
34 cutout_l_end_y_rear_slop = 0.5;
35 cutout_l_end_x_slop = 0.25;
36
37 cutout_l_end_x = 22;
38 cutout_l_end_y = 85;
39 cutout_l_end_curve = 1;
40 cutout_l_end_y_total = cutout_l_end_y
41   + cutout_l_end_y_front_slop + cutout_l_end_y_rear_slop;
42
43 tile01_tr = [250, 0];
44
45 cutout_tile01_y = 170 - 147 + cutout_l_end_y_front_slop;
46 cutout_tile11_x = cutout_l_end_x + cutout_l_end_curve;
47 cutout_tile11_y = cutout_l_end_y_total - cutout_tile01_y;
48
49 // rear curve
50
51 rearedge_len = 170;
52
53 rearcurve_rad = 25.4;
54 rearcurve_strt_len = 65;
55 rearcurve_total_len = 84;
56
57 rearcurve_rad_slop = 0.75;
58
59 rearcurve_avoid_y = rearcurve_rad + 10;
60
61 reartablet_z = 2.54;
62 reartablet_x = 5 + 1;
63 reartablet_y = 5;
64
65 // calculated
66
67 TEST = false;
68
69 ply_edge_hole_dist = ply_edge_min + ply_hole_dia/2;
70
71 echo(str("HOLES IN PLY ctr dist from PLY edge = ", ply_edge_hole_dist));
72
73 hole_slop = (ply_hole_dia - post_dia)/2;
74 tile_hard_edge_hole_dist = ply_edge_hole_dist + hole_slop;
75
76 echo(str("HOLES IN PLY ctr dist from TILE HARD edge = ",
77          tile_hard_edge_hole_dist));
78
79 echo(str("HOLES IN PLY ctr dist from TILE ROUND edge = ",
80          tile_hard_edge_hole_dist + round_edge_rad));
81
82 thehd = [ tile_hard_edge_hole_dist, tile_hard_edge_hole_dist ];
83 thehd_tr = thehd;
84 thehd_tl = [ -thehd_tr[0], thehd_tr[1] ];
85 thehd_bl = -thehd_tr;
86 thehd_br = -thehd_tl;
87
88 interlock_rad = interlock_dia/2;
89 interlock_negative_rad = interlock_rad + 0.125;
90
91 interlock_sq_adj = 0.2; // arbitrary
92
93 module Post(){
94   mirror([0,0,1]) {
95     difference(){
96       cylinder(r= post_dia/2, h= tile_th + ply_th - post_shorter);
97       translate([0,0, tile_th]) {
98         cylinder(r= screw_big_dia/2, h= screw_big_len);
99         cylinder(r= screw_dia/2, h= ply_th, $fn=20);
100       }
101     }
102     if (TEST) {
103       tsz = tile_hard_edge_hole_dist - test_edge + 1;
104       translate([0,0, tile_th/2]) {
105         cube([post_dia, tsz*2, tile_th], center=true);
106         cube([tsz*2, post_dia, tile_th], center=true);
107       }
108     }
109   }
110 }
111
112 module Posts(posts) {
113   for (p= posts) {
114     translate(concat(p, [0]))
115       Post();
116   }
117 }
118
119 module TileBase(botleft, topright){
120   size = topright - botleft;
121   botleft_post = botleft + thehd_tr;
122   topright_post = topright + thehd_bl;
123   difference(){
124     mirror([0,0,1])
125       translate(concat(botleft, [0]))
126       cube(concat(size, [tile_th]));
127     if (!TEST) {
128       translate( concat(botleft_post, [ -tile_th ])
129                  + 0.5 * [ post_dia, post_dia, 0 ] )
130         Commitid_BestCount_M( topright_post-botleft_post
131                               + [-post_dia,-post_dia]
132                               + [0, thehd[1]]);
133     }
134     if (TEST) {
135       translate( concat(botleft + [thehd[0], 0], [0]) )
136         Commitid_BestCount([ size[0] - thehd[0]*2, thehd[1] ]);
137       difference(){
138         mirror([0,0,1]) {
139           translate(concat(botleft + [test_edge,test_edge], [test_tile_th]))
140             cube(concat(size - [test_edge,test_edge]*2, [tile_th]));
141           translate(concat(botleft_post, [-1]))
142             cube(concat(topright_post-botleft_post, [tile_th+2]));
143         }
144         minkowski(){
145           Machine();
146           cube(max(test_edge, tile_hard_edge_hole_dist)*2, center=true);
147         }
148       }
149     }
150   }
151 }
152
153 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars) { body; }
154 m4_define(`INREFFRAME',`
155   length_vec = ($2) - ($1);
156   length = dist2d([0,0], length_vec);
157   length_uvec = length_vec / length;
158   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
159   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
160         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
161         [ 0,              0,              1,            0, ],
162         [ 0,              0,              0,            1, ] ];
163   $3
164   multmatrix(m)
165 ')
166
167 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars)
168 m4_dnl    INREFFRAME_EDGE { body; }
169 m4_define(`INREFFRAME_EDGE',`
170   translate([0,0, -round_edge_rad])
171 ')
172
173 module RoundEdge(left_cnr, right_cnr) {
174   INREFFRAME(left_cnr, right_cnr)
175     INREFFRAME_EDGE {
176     difference(){
177       rotate([0,90,0])
178         cylinder(r= round_edge_rad, h= length, $fn=50);
179       translate([-1, 0, -20])
180         cube([length+2, 20, 20]);
181     }
182   }
183 }
184
185 module RoundCornerCut(ci) {
186   // ci should be [this_cnr, right_cnr]
187   // where right_cnr is to the right (ie, anticlockwise)
188   this_cnr = ci[0];
189   right_cnr = ci[1];
190   offr= round_cnr_rad - round_edge_rad;
191   INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
192     difference(){
193       cube(offr*2 - 0.1, center=true);
194       translate([offr, offr, 0])
195         cylinder(center=true, h=20, r= offr);
196     }
197   }
198 }
199
200 module RoundCornerAdd(ci) {
201   this_cnr = ci[0];
202   right_cnr = ci[1];
203   bigr = round_cnr_rad - round_edge_rad;
204   INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
205     intersection(){
206       cube(bigr*2 + 0.1, center=true);
207       translate([bigr, bigr, 0])
208         rotate_extrude(convexity=10, $fn=50)
209         translate([bigr, 0])
210         difference(){
211           circle(r= round_edge_rad, $fn=50);
212           mirror([1,1])
213             square([20,20]);
214         }
215     }
216   }
217 }
218
219 module InterlockLobePlan(negative) {
220   r = negative ? interlock_negative_rad : interlock_rad;
221   ymir = negative ? 0 : 1;
222
223   dx = sqrt(3) * r;
224   $fn= 80;
225   translate([thehd[0], 0]){
226     mirror([0,ymir]){
227       circle(r=r);
228       difference(){
229         translate([-dx, -0.1])
230           square([ dx*2, r/2 + 0.1 ]);
231         for (xi = [-1, 1]) {
232           translate([ xi*dx, r ])
233             circle(r=r);
234         }
235       }
236     }
237   }
238 }
239
240 module InterlockEdgePlan(negative, nlobes, length, dosquare=true) {
241   for (lobei = [ 0 : nlobes-1 ]) {
242     lobex = (length - thehd[0]*2) * (lobei ? lobei / (nlobes-1) : 0);
243     translate([lobex, 0, 0]) {
244       InterlockLobePlan(negative);
245     }
246   }
247
248   if (dosquare) {
249     iadj = 0;
250     slotshorter = negative ? -0.1 : interlock_fine_lenslop;
251     mirror([0, negative])
252       translate([slotshorter, iadj])
253       square([length - slotshorter*2, interlock_fine + iadj*2]);
254   }
255 }
256
257 module InterlockEdge(left_cnr, right_cnr, negative=0, nlobes=2) {
258   plusth = negative * 1.0;
259   protr = interlock_fine + interlock_sq_adj;
260
261   z2 = -tile_th/2;
262   z1 = -tile_th/2 - protr / interlock_fine_slope;
263   z3 = -tile_th/2 + protr / interlock_fine_slope;
264
265   negsign = negative ? -1 : +1;
266   yprotr = negsign * protr;
267
268   INREFFRAME(left_cnr, right_cnr) {
269     for (vsect = [ // zs0            zs1      ys0,            ys1
270                   [ -tile_th-plusth, plusth,  0,              0],
271                   [ z1,              z2,      0, yprotr],
272                   [ z2,              z3,      yprotr, 0],
273                   ]) {
274       zs0 = vsect[0];
275       zs1 = vsect[1];
276       zsd = zs1-zs0;
277       ys0 = vsect[2];
278       ys1 = vsect[3];
279       ysd = ys1-ys0;
280       sl = ysd/zsd;
281       m = [ [ 1,0,   0,    0 ],
282             [ 0,1, -sl, -ys0 + negsign*interlock_sq_adj ],
283             [ 0,0,   1,  zs0 ],
284             [ 0,0,   0,    1 ] ];
285       multmatrix(m)
286         linear_extrude(height=zsd, convexity=10)
287         InterlockEdgePlan(negative, nlobes, length, !!ysd);
288     }
289   }
290 }
291
292 function TestPiece_holes2corners(holes) =
293   [ holes[0] + thehd_bl,
294     holes[1] + thehd_br,
295     holes[1] + thehd_tr,
296     holes[0] + thehd_tl ];
297
298 module TestPiece1(){ ////toplevel
299   holes = [ [-100, 0],
300             [   0, 0]
301             ];
302   corners = TestPiece_holes2corners(holes);
303   rcs = [corners[0], corners[1]];
304   difference(){
305     union(){
306       TileBase(corners[0], corners[2]);
307       Posts(holes);
308       RoundEdge(corners[0], corners[1]);
309       RoundEdge(corners[3], corners[0]);
310     }
311     InterlockEdge(corners[1], corners[2], 1, nlobes=1);
312     RoundCornerCut(rcs);
313   }
314   RoundCornerAdd(rcs);
315 }
316
317 module TestPiece2(){ ////toplevel
318   holes = [ [   0, 0],
319             [  50, 0]
320             ];
321   corners = TestPiece_holes2corners(holes);
322   TileBase(corners[0], corners[2]);
323   Posts(holes);
324   RoundEdge(corners[0], corners[1]);
325   InterlockEdge(corners[3], corners[0], 0, nlobes=1);
326 }
327
328 module TestDemo(){ ////toplevel
329   translate([ -thehd[0], 0 ])
330     color("blue")
331     TestPiece1();
332   translate([ +thehd[0] + demo_slop, 0 ])
333     TestPiece2();
334 }
335
336 module Machine_Arm(){
337   ysz = cutout_l_end_y_total;
338   // assume the round end is arc of a circle
339   chordlen = dist2d([0,0], [ cutout_l_end_y, cutout_l_end_curve ]);
340   endrad = cutout_l_end_y / cutout_l_end_curve * chordlen;
341   
342   translate([0,0,-30]) linear_extrude(height=60) {
343     translate(tile01_tr + [0, (-cutout_tile01_y + cutout_tile11_y)/2]) {
344       intersection(){
345         translate([-100, -ysz/2])
346           square([400, ysz]);
347         translate([ endrad - cutout_tile11_x - cutout_l_end_x_slop, 0 ])
348           circle(r=endrad, $fa=0.01,$fd=5);
349       }
350     }
351   }
352 }
353
354 module Machine_Rear(){ ////toplevel
355   big_rad = rearcurve_total_len - rearcurve_strt_len + rearcurve_rad;
356   small_rad = rearcurve_rad + rearcurve_rad_slop;
357   translate([ 250 - cutout_l_end_x + rearedge_len,
358               cutout_tile11_y,
359               0 ]){
360     //%cube([20,20,20]);
361     translate([ -reartablet_x,
362                 -1,
363                 -reartablet_z])
364       mirror([0,0,1])
365       cube([ reartablet_x+1,
366              reartablet_y+1,
367              20 ]);
368     translate([ rearcurve_strt_len,
369                 0,
370                 0 ]){
371       translate([ 0,
372                   0,
373                   -rearcurve_rad
374                   ]){
375         rotate([0,-90,0]){
376           rotate([0,0, 360/8/2])
377             cylinder(r = small_rad, h= rearcurve_strt_len);
378         }
379       }
380       translate([ 0,
381                   0,
382                   big_rad - rearcurve_rad ]) {
383         intersection(){
384           rotate([90,0,0]){
385             rotate_extrude(convexity=10) {
386               translate([ big_rad,
387                           0 ]) {
388                 hull(){
389                   circle(r= small_rad);
390                   translate([200,0])
391                     circle(r= small_rad);
392                 }
393               }
394             }
395           }
396           mirror([0,0,1])
397             cube([150,150,150]);
398         }
399       }
400     }
401   }
402 }
403
404 module Machine(){ ////toplevel
405   Machine_Arm();
406   Machine_Rear();
407 }
408   
409 function Rectangle_corners(c0, sz) =
410   // returns the corners of a rectangle from c0 to c0+sz
411   // if sz is positive, the corners are anticlockwise starting with c0
412   [ c0 + [ 0,     0     ],
413     c0 + [ sz[0], 0     ],
414     c0 + [ sz[0], sz[1] ],
415     c0 + [ 0,     sz[1] ] ];
416
417 function Rectangle_corners2posts(c) =
418   [ c[0] + thehd_tr,
419     c[1] + thehd_tl,
420     c[2] + thehd_bl,
421     c[3] + thehd_br ];
422
423 module Rectangle_TileBase(c) { TileBase(c[0], c[2]); }
424
425 function Posts_interpolate_one(c0,c1) = [c0, (c0+c1)/2, c1];
426
427 m4_dnl   R_EDGE(c,ix)
428 m4_dnl        c is from Rectangle_corners and
429 m4_dnl        ix is a corner number
430 m4_dnl    expands to two comma-separated corners:
431 m4_dnl    that denoted by ix, and the next one anticlockwise
432 m4_define(`R_EDGE',`$1[$2],$1[(($2)+1)%4]')
433
434 module Tile02(){ ////toplevel
435   sz = [100,170];
436   c0 = -sz;
437   c = Rectangle_corners(c0, sz);
438   posts = Rectangle_corners2posts(c);
439   rcs = [R_EDGE(c,0)];
440   difference(){
441     union(){
442       Rectangle_TileBase(c);
443       Posts(posts);
444       RoundEdge(R_EDGE(c,0));
445       RoundEdge(R_EDGE(c,3));
446       InterlockEdge(R_EDGE(c,2), 0);
447     }
448     InterlockEdge(R_EDGE(c,1), 1);
449     RoundCornerCut(rcs);
450   }
451   RoundCornerAdd(rcs);
452 }
453
454 module Tile12(){ ////toplevel
455   sz = [100,250];
456   c0 = [-sz[0], 0];
457   c = Rectangle_corners(c0, sz);
458   posts = Rectangle_corners2posts(c);
459   rcs = [R_EDGE(c,3)];
460   difference(){
461     union(){
462       Rectangle_TileBase(c);
463       Posts(posts);
464       RoundEdge(R_EDGE(c,2));
465       RoundEdge(R_EDGE(c,3));
466     }
467     InterlockEdge(R_EDGE(c,0), 1);
468     InterlockEdge(R_EDGE(c,1), 1);
469     RoundCornerCut(rcs);
470   }
471   RoundCornerAdd(rcs);
472 }
473
474 tile_01_11_cnr = [250, 0] + [-cutout_tile11_x, 0];
475 tile_11_10_cnr = [250, 0] + [0, cutout_tile11_y];
476
477 module Tile11(){ ////toplevel
478   sz = [250,250];
479   c0 = [0,0];
480   c = Rectangle_corners(c0, sz);
481   cnr_posts = Rectangle_corners2posts(c);
482   posts = concat(
483                  Posts_interpolate_one(cnr_posts[0],
484                                        cnr_posts[1] - [cutout_tile11_x, 0]),
485                  [ cnr_posts[1] + [0, cutout_tile11_y],
486                    cnr_posts[2],
487                    cnr_posts[3]
488                    ]);
489   difference(){
490     union(){
491       Rectangle_TileBase(c);
492       Posts(posts);
493       RoundEdge(R_EDGE(c,2));
494       InterlockEdge(R_EDGE(c,3));
495     }
496     InterlockEdge(c[0], tile_01_11_cnr, 1);
497     InterlockEdge(tile_11_10_cnr, c[2], 1);
498     Machine();
499   }
500 }    
501
502 tile_01_00_cnr = [250, 0] + [0, -cutout_tile01_y];
503
504 module Tile01(){ ////toplevel
505   sz = [250,170];
506   c0 = [0,-sz[1]];
507   c = Rectangle_corners(c0, sz);
508   cnr_posts = Rectangle_corners2posts(c);
509   posts = concat(
510                  Posts_interpolate_one(R_EDGE(cnr_posts,0)),
511                  [ cnr_posts[2] + [0, -cutout_tile01_y] ],
512                  Posts_interpolate_one(cnr_posts[2] - [cutout_tile11_x, 0],
513                                        cnr_posts[3])
514                  );
515   difference(){
516     union(){
517       Rectangle_TileBase(c);
518       Posts(posts);
519       RoundEdge(R_EDGE(c,0));
520       InterlockEdge(tile_01_11_cnr, c[3]);
521       InterlockEdge(R_EDGE(c,3));
522     }
523     InterlockEdge(c[1], tile_01_00_cnr, 1);
524     Machine();
525   }
526 }    
527
528 module Tile10(){ ////toplevel
529   sz = [250,250];
530   c0 = [sz[0],0];
531   c = Rectangle_corners(c0, sz);
532   cnr_posts = Rectangle_corners2posts(c);
533   cty = cutout_tile11_y;
534   rcy = cty + rearcurve_avoid_y;
535   posts = [ cnr_posts[0] + [ 0,                             cty ],
536             cnr_posts[1] + [ -sz[1] + rearedge_len - cutout_l_end_x, cty ],
537             cnr_posts[1] + [ 0,                             rcy ],
538             cnr_posts[2],
539             cnr_posts[3] ];
540   rcs = [R_EDGE(c,2)];
541   difference(){
542     union(){
543       Rectangle_TileBase(c);
544       Posts(posts);
545       RoundEdge(R_EDGE(c,1));
546       RoundEdge(R_EDGE(c,2));
547       InterlockEdge(c[3], tile_11_10_cnr);
548     }
549     RoundCornerCut(rcs);
550     Machine();
551   }
552   RoundCornerAdd(rcs);
553 }
554
555 module Demo(){ ////toplevel
556   translate(demo_slop*[-2,1]) color("blue") Tile12();
557   translate(demo_slop*[-2,0]) color("red")  Tile02();
558   translate(demo_slop*[-2,1]) color("orange") Tile11();
559   translate(demo_slop*[-2,0]) color("purple") Tile01();
560   translate(demo_slop*[-3,1]) color("blue")   Tile10();
561   %Machine();
562 }
563   
564 //TestPiece1();
565 //TestPiece2();
566 //Demo();