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