chiark / gitweb /
poster-tube-lid: WallMountBaseCutJig
[reprap-play.git] / poster-tube-lid.scad
1 // -*- C -*-
2
3 // Print, for each end:
4 //
5 //   CoverPrint
6 //   StrapMount
7 //   CatchAssembly
8
9 include <funcs.scad>
10 include <utils.scad>
11
12 coarse = false;
13 enable_head_cups = false;
14
15 main_dia = 71.2 + 0.50 - 2.26;
16 top_thick_middle = 4;
17 top_thick_by_oring = 3.0;
18 top_middle_dr = 11;
19
20 main_cnr = 6.0;
21
22 min_wall = 3;
23
24 rivet_posn = 6.0 + 0.30;
25 rivet_thick = 1.67;
26 rivet_width = 4.15 + 1.0;
27 rivet_tall = 5.51 + 1.49;
28
29 over_rivet_wall = 1.0;
30 side_rivet_gap = 1.5;
31 inside_rivet_gap = 1.5;
32
33 bayo_interf = 0.30;
34 bayo_behind = 8.5;
35 bayo_interf_width = 2.0;
36 bayo_interf_slope = 0.5;
37
38 oring_thick = 5.0;
39 oring_bore = 62.0;
40
41 oring_upper_embed_angle = 80;
42 oring_compress = 0.1; // proportion
43 oring_compress_more = 0.2;
44
45 oring_rm_beside = 8;
46 oring_rm_scale = 2.0;
47 oring_rm_angle = 20;
48
49 side_taper = 1.0;
50
51 bayo_gap = 6.0;
52
53 bayo_entry = 1.167;
54 bayo_inramp = 0.9;
55
56 bayo_slice_size = coarse ? 5 : 1;
57
58 brace_hole_width = 1.0;
59 brace_above_below = 1.2;
60 brace_end_shorter = 0.3;
61
62 jig_thick = 1.4;
63 jig_hole_dia = 3.0;
64 jig_rim = 5;
65 jig_mark = 5;
66
67 strap_loop_thick = 6;
68 strap_loop_inside = 10;
69 strap_loop_strlen = 10;
70 strap_loop_elevation = 45;
71
72 sm_inner_circum = 218 - 1.90 - 1.00 - 0.50;
73 sm_main_thick = 2.0;
74 sm_main_width = 20;
75
76 sm_bolt_dia = 3.5 + 0.1;
77 sm_bolt_shaft = 21.0;
78 sm_bolt_head_dia = 6.94 + 1.0;
79 sm_bolt_head_thick = 2.14;
80 sm_bolt_nut_width = 5.89 + 0.25;
81 sm_bolt_nut_thick = 3.68;
82 sm_bolt_tighten_allow = 2.0;
83
84 sm_bolt_y_clear = 0.75;
85 sm_bolt_y_over = 0.5;
86
87 sm_closure_cnr = 3.0;
88
89 wm_thick = 5;
90 wm_screw_dia = 4.5; // XXX
91 wm_screwdriver_dia = 6.0; // XXX
92 wm_screw_around = 4.0; // XXX
93 wm_screw_slot = 3.5;
94 wm_screw_head = 7.5; // XXX
95
96 wmb_screw_dia = 5;
97 wmb_screw_head_dia = 10; // XXX
98 wmb_screw_around_x = 4; // XXX
99 wmb_screw_around_z = 6; // XXX
100 wmb_screw_depth_min = 10;
101 web_screw_len = 15 + 1; // XXX
102 wmb_nut_across = 8; // XXX
103 wmb_nut_around_min = 2; // XXX
104 wmb_nut_behind_min = 5;
105 wmb_nut_th = 4; // XXX
106 wmb_mount_wall = 4.5;
107 wmb_mount_gap_xy = 0.5;
108 wmb_mount_gap_z = 0.5;
109 wmb_mount_y_width = 10;
110 wmb_bottom_gap = 35; // includes allowance for padding, etc.
111 wmb_bottom_th = 7;
112 wmb_bottom_th_min = 1;
113 wmb_ring_gap = 1.0;
114 wmb_base_extra_rad = 10;
115 wmb_jig_th = 2;
116 wmb_jig_around_gap = 1;
117
118 catch_stalk_h = 4.5;
119 catch_stalk_len = 50;
120 catch_tip_th = 4;
121 catch_head_th = 3;
122
123 catch_pin_slop = 0.25; // each side, and above
124 catch_pin_slop_x_extra = 0.0; // only on one side
125 catch_stalk_above_gap = 1.5;
126 catch_stalk_eff_bend_rad = catch_stalk_len * 0.75;
127
128 catch_strap_width = 12;
129 catch_stalk_base_width = 15;
130
131 catch_knob_dia = 6;
132 catch_knob_above_gap = 5;
133 catch_knob_height = 3.0;
134
135 catch_stalk_below_gap = 1.0;
136 catch_stalk_beside_gap = 2.0;
137
138 // calculated
139
140 TAU = PI*2;
141
142 bayo_entry_x = bayo_entry;
143 bayo_entry_z = bayo_entry;
144 bayo_inramp_x = bayo_inramp;
145 bayo_inramp_z = bayo_inramp;
146
147 oring_mid_dia = oring_bore + oring_thick;
148 oring_outer_dia = oring_mid_dia + oring_thick;
149
150 oring_oblate = (1 - oring_compress);
151
152 oring_y_rad = oring_thick/2 * oring_oblate;
153 oring_x_rad = oring_thick/2 / oring_oblate;
154
155 by_oring_z = oring_y_rad * (1 + cos(oring_upper_embed_angle));
156
157 side_height = rivet_posn + bayo_behind + rivet_thick/2;
158 side_thick = rivet_tall + over_rivet_wall;
159
160 top_z = top_thick_by_oring + oring_y_rad + by_oring_z;
161
162 middle_bot_z = top_z - top_thick_middle;
163
164 bayo_top_z = bayo_behind + bayo_gap;
165
166 bayo_nom_rad = main_dia/2 + side_thick;
167 bayo_real_rad = main_dia/2 + rivet_tall;
168
169 rivet_entry_width = rivet_width + side_rivet_gap;
170
171 jig_mark_rad = jig_mark + main_dia/2 + jig_thick;
172
173 handling_dia = oring_bore + oring_thick*2 + min_wall*2;
174 handling_angle = 45;
175
176 sm_inner_rad = (sm_inner_circum + sm_bolt_tighten_allow/2) / TAU;
177 sm_outer_rad = sm_inner_rad + sm_main_thick;
178
179 wm_main_width = sm_main_width;
180 wm_y_min = sqrt( pow(sm_inner_rad, 2) -
181                  pow(sm_inner_rad - (wm_thick - sm_main_thick), 2) );
182 wm_y_screw = wm_y_min + wm_screw_around + wm_screw_dia/2;
183 wm_y_max = wm_y_screw + wm_screw_dia/2 + wm_screw_around;
184 wm_y_slotc_screw = wm_y_screw + wm_screw_slot/2;
185 wm_y_slot1_screw = wm_y_screw + wm_screw_slot;
186 wm_y_slot1_max = wm_y_max + wm_screw_slot;
187 wm_z_slot0_screw = wm_main_width + wm_screwdriver_dia/2;
188 wm_z_slotc_screw = wm_z_slot0_screw + wm_screw_slot/2;
189 wm_z_slot1_screw = wm_z_slot0_screw + wm_screw_slot;
190 wm_z_max = wm_z_slot1_screw + wm_screw_around;
191
192 wmb_mount_cut_rad = sm_outer_rad + wmb_ring_gap;
193 wmb_nut_rad = wmb_nut_across / cos(30) * 0.5;
194 wmb_x_screw_plus_around_r = max(
195                                 wmb_screw_around_x + wmb_screw_dia/2,
196                                 wmb_nut_around_min + wmb_nut_across/2
197                                 );
198 wmb_x_screw = -sm_outer_rad + wmb_x_screw_plus_around_r;
199 wmb_x_outer = -sm_outer_rad + wmb_x_screw_plus_around_r * 2;
200 function wmb_screw_thing_y_min(dia) = sqrt(
201                        pow(wmb_mount_cut_rad, 2) -
202                        pow(wmb_x_screw + dia/2, 2)
203                        );
204 wmb_y_screw_end = wmb_screw_thing_y_min(wmb_screw_dia);
205 wmb_y_nut_min = wmb_screw_thing_y_min(wmb_nut_across + wmb_nut_around_min*2);
206 wmb_y_mount_max = max(
207                       wmb_y_nut_min + wmb_nut_th + wmb_nut_behind_min,
208                       wmb_y_screw_end + wmb_screw_depth_min
209                       );
210 wmb_z_screw = max(
211                   wmb_screw_around_z + wmb_screw_dia/2,
212                   wmb_nut_around_min + wmb_nut_rad
213                   );
214 wmb_z_max = wmb_z_screw * 2;
215 wmbb_y_max = wmb_y_mount_max + wmb_mount_gap_xy + wmb_mount_wall;
216 wmbb_x_outer = wmb_x_outer + (wmb_mount_gap_xy + wmb_mount_wall);
217 wmbb_z_flat_max = -wmb_bottom_gap;
218 wmbb_z_flat_whole_min = wmbb_z_flat_max - wmb_bottom_th_min;
219 wmbb_z_min      = wmbb_z_flat_max - wmb_bottom_th;
220 wmbb_r_top = main_dia/2 + wmb_base_extra_rad;
221 wmbb_r_bottom = wmbb_r_top - (wmb_bottom_th - wmb_bottom_th_min);
222
223 smc_pos = [ 0, sm_inner_rad, 0 ];
224
225 smc_bolt_nut_dia = sm_bolt_nut_width / cos(30);
226 smc_bolt_nut_eff_thick = sm_bolt_nut_thick + sm_bolt_tighten_allow;
227
228 smc_bolt_y = sm_bolt_dia/2 + sm_bolt_y_clear;
229 smc_max_y = smc_bolt_y + sm_bolt_y_over
230   + max(sm_bolt_head_dia/2, smc_bolt_nut_dia/2);
231 smc_cnr_c_x = sm_bolt_shaft/2 - sm_closure_cnr
232   + sm_bolt_head_thick/2 + smc_bolt_nut_eff_thick/2;
233
234 catch_cr = catch_knob_dia/2 + catch_stalk_beside_gap;
235 catch_strap_thick = sm_main_thick;
236
237 echo("R ", sm_inner_rad, bayo_real_rad, bayo_nom_rad);
238
239 $fs= coarse ? 2.5 : 0.5;
240 $fa= coarse ? 5 : 1;
241
242 include <poster-tube-lid-parametric.scad>
243
244 // bayonet definition
245
246 bayo_a = [ bayo_entry_x, 0 ];
247 bayo_p = [ 0, bayo_entry_z ];
248 bayo_n = [ 0, bayo_behind-bayo_inramp_z ];
249 bayo_m = [ bayo_inramp_x, bayo_behind ];
250 bayo_l = bayo_m + bayo_interf * [ 1/bayo_interf_slope,  1 ];
251 bayo_k = bayo_l + [ bayo_interf_width, 0 ];
252 bayo_j = bayo_k + bayo_interf * [ 1/bayo_interf_slope, -1 ];
253 bayo_i = bayo_j + [ rivet_width + inside_rivet_gap, 0 ];
254 bayo_h = [ bayo_i[0], bayo_behind + bayo_gap + bayo_interf ];
255 bayo_g = [ bayo_m[0] - rivet_width, bayo_h[1] ];
256
257 bayo_e = [-bayo_p[0], bayo_p[1]] - [rivet_entry_width,0];
258 bayo_d = [-bayo_a[0], bayo_a[1]] - [rivet_entry_width,0];
259 bayo_c = bayo_d + [0,-5];
260 bayo_b = bayo_a + [0,-5];
261
262 bayo_f = [ bayo_e[0], bayo_g[1] + (bayo_e[0] - bayo_g[0]) ];
263
264 bayo_polygon = [ bayo_a,
265                  bayo_b,
266                  bayo_c,
267                  bayo_d,
268                  bayo_e,
269                  bayo_f,
270                  bayo_g,
271                  bayo_h,
272                  bayo_i,
273                  bayo_j,
274                  bayo_k,
275                  bayo_l,
276                  bayo_m,
277                  bayo_n,
278                  bayo_p ];
279
280 echo(bayo_polygon);
281
282 // CATCH
283
284 cppxC = 0.41 * sm_inner_rad * TAU;
285
286 // catch pin
287
288 cpp_adj = (bayo_n[0] - bayo_f[0]) * (1 - sm_inner_rad / bayo_nom_rad);
289 // radius scaling due to nom and actual radius difference in
290 // bayo entry construction
291
292 cppa = bayo_f + [1,-1] * catch_pin_slop + [1,0] * cpp_adj;
293 cppb = bayo_g + [1,-1] * catch_pin_slop + [1,0] * cpp_adj;
294 cppd = [ bayo_n[0]
295          - catch_pin_slop - catch_pin_slop_x_extra,
296          -catch_stalk_above_gap ];
297 cppi = [ cppa[0], cppd[1] ];
298 cppc = [ cppd[0], cppb[1] ];
299 cpph = cppd + [0,-1] * catch_stalk_h;
300 cppe = cppd + [0,-1] * (catch_knob_above_gap + catch_knob_dia/2);
301 cppf = [ cppa[0], cppe[1] ];
302 cppg = [ cppa[0], cpph[1] ];
303 cppB = 0.5 * (cppf + cppe);
304
305 echo("RR", sm_inner_rad / bayo_nom_rad);
306
307 // catch assembly depression below pin
308
309 cppy6 = cppB[1] - (catch_knob_dia/2
310                    + (cppc[1] - cppd[1])
311                    + catch_stalk_below_gap);
312 cpp7 = [ cppB[0], cppy6 + catch_cr ];
313 cpp11 = cpp7 + [1,0] * catch_cr;
314 cppy9 = cppy6 + catch_strap_width * 1/3;
315 cpp9 = [ cpp7[0] + catch_cr * 2, cppy9 ];
316 cpp8 = cpp9 + [0,-1] * catch_cr;
317 cpp10 = cpp8 + [-1,0] * catch_cr;
318 cppC = [ cppxC, cpp9[1] ];
319 cppD = cppC + [0,-1] * catch_strap_width;
320
321 // catch assembly stalk and so on
322
323 catch_cr3 = catch_cr + catch_stalk_h;
324
325 cppF = [ cppg[0] - catch_stalk_eff_bend_rad, cppd[1] ];
326 cpp4 = [ cppg[0] - catch_stalk_len, cpph[1] ] + [1,-1] * catch_cr;
327 cpp5 = [ cpp4[0], cppC[1] + catch_cr ];
328 cpp2 = cpp5 + [-1,0] * (catch_cr * 2 + catch_stalk_base_width);
329 cpp2r = cpp2 + [1,0] * catch_cr;
330 cpp2d = cpp2 + [0,-1] * catch_cr;
331 cpp3 = [ cpp2[0] + catch_cr + catch_cr3, cppd[1] - catch_cr3 ];
332 cppA = [ -cppxC, cpp9[1] ];
333 cppE = [ cppA[0], cppD[1] ];
334
335 catch_assembly_dy = -cppy9 + catch_strap_width;
336
337
338 module MainProfile(){
339   main_cnr_pos = [ side_thick, top_z ] - [1,1]*main_cnr;
340   difference(){
341     union(){
342       translate(main_cnr_pos){
343         intersection(){
344           difference(){
345             circle(r = main_cnr);
346             circle(r = main_cnr * 0.5);
347           }
348           square([10,10]);
349         }
350       }
351       polygon([[ -top_middle_dr,        middle_bot_z      ],
352                [ -top_middle_dr,        top_z             ],
353                [ main_cnr_pos[0],       top_z             ],
354                [ side_thick,            main_cnr_pos[1]   ],
355                [ side_thick,            -side_height      ],
356                [ side_taper,            -side_height      ],
357                [ 0,                     -rivet_posn       ],
358                [ 0,                     by_oring_z        ],
359                [ -oring_x_rad,          by_oring_z        ],
360                ],
361               convexity=10);
362     }
363     translate([ oring_mid_dia/2 - main_dia/2, 0 ])
364       hull(){
365       translate([ 0, oring_y_rad ])
366         scale([ 1/oring_oblate * (oring_compress_more+1) , oring_oblate ])
367         circle(oring_thick/2);
368       translate([ 0, oring_y_rad*2 - oring_thick/2 ])
369         circle(oring_thick/2);
370     }
371   }
372 }
373
374 module StrapLoopProfile(){
375   circle(r = strap_loop_thick/2);
376 }
377
378 module StrapLoop(){ ////toplevel
379   bigrad = strap_loop_inside/2 + strap_loop_thick/2;
380   extralen = strap_loop_thick * 5;
381
382   intersection(){
383     rotate([strap_loop_elevation, 0,0]){
384       for (x= [ -1, +1 ] * bigrad) {
385         translate([x, -extralen, 0])
386           rotate([-90,0,0])
387           linear_extrude(height= extralen + strap_loop_strlen + 0.1,
388                          convexity=10)
389           StrapLoopProfile();
390       }
391       translate([0, strap_loop_strlen, 0]){
392         intersection(){
393           rotate_extrude(convexity=10)
394             translate([bigrad, 0,0])
395             StrapLoopProfile();
396           translate([0,50,0])
397             cube([100,100,100], center=true);
398         }
399       }
400     }
401     translate([0, 50, 0])
402       cube(100, center=true);
403   }
404 }
405
406 module RotateProjectSlice(offset, slice_size, nom_rad, real_rad){
407   // nom_rad > real_rad
408   rotate([0,0, atan2(offset, nom_rad) ]){
409     intersection(){
410       translate([-offset, -10, 0])
411         rotate([90,0,0])
412         linear_extrude(height= nom_rad*2, convexity=50)
413         children(0);
414       translate([0,0, -25])
415         cylinder(h=50, r= real_rad);
416       translate([0,0, -25])
417         linear_extrude(height= 50, convexity=50)
418         polygon([ [ 0,0 ],
419                   [ -slice_size, -real_rad*2 ],
420                   [ +slice_size, -real_rad*2 ] ]);
421     }
422   }
423 }
424
425 module RotateProject(x_min, x_max, slice_size, nom_rad, real_rad){
426   offs = [ for (i=[ x_min :
427                     slice_size :
428                     x_max + slice_size ]) i ];
429   echo (offs);
430   for (off=offs)
431     RotateProjectSlice(off, slice_size, nom_rad, real_rad)
432     children(0);
433 }
434
435 module BayonetCutout(){
436   RotateProject(bayo_c[0], bayo_i[0], bayo_slice_size,
437                 bayo_nom_rad, 
438                 bayo_real_rad)
439     translate([-0.5 * (bayo_a[0] + bayo_d[0]), 0])
440     polygon(bayo_polygon, convexity=10);
441 }
442
443 module ProfilesDemo(){ ////toplevel
444   translate([-10,0]) MainProfile();
445   translate([+10, -side_height]) polygon(bayo_polygon, convexity=10);
446 }
447
448 module LimitForHandling(){ ////toplevel
449   hull() for (r=[0,180])
450     rotate([0,0,r]) {
451       for (rs=[-1,+1]) {
452         for (xd=[0,1]) {
453           rotate([0,0, rs * handling_angle/2]) {
454             translate([rs * xd * main_dia/2 * tan(handling_angle/2),
455                        main_dia/2 + side_thick - main_cnr,
456                        top_z - main_cnr]) {
457               mirror([0,0,1])
458                 cylinder(r= main_cnr, h=50);
459               sphere(main_cnr);
460             }
461           }
462         }
463       } 
464     }
465   hull() rotate_extrude(convexity=10){
466     translate([ handling_dia/2 - main_cnr, top_z - main_cnr ]) {
467       circle(r = main_cnr);
468       mirror([0,1]) square([ main_cnr, 50 ]);
469     }
470   }
471   //cylinder(r= handling_dia/2, h=20);
472 }
473
474 module Cover(){ ////toplevel
475   render() difference(){
476     intersection(){
477       union(){
478         rotate_extrude(convexity=10)
479           translate([main_dia/2, 0])
480           MainProfile();
481         translate([0,0, middle_bot_z])
482           cylinder(h= top_thick_middle, r = main_dia/2 - top_middle_dr + 1);
483       }
484       LimitForHandling();
485     }
486     for (r=[0,180]){
487       rotate([0,0, r])
488         translate([0,0, -side_height])
489         BayonetCutout();
490       rotate([0,0, r + asin((-oring_rm_beside) / (main_dia/2))])
491         translate([0,
492                    oring_mid_dia/2 + oring_thick/4 * oring_rm_scale,
493                    oring_y_rad * 1.5])
494         rotate([-oring_rm_angle, 0, 0])
495         mirror([0,0,1])
496         cylinder(r = oring_thick/4 * oring_rm_scale, h=20);
497     }
498     for (r=[0 : 60 : 179]) {
499       rotate([0,0, r]) {
500         height = top_thick_middle - brace_above_below*2;
501         translate([0,0, middle_bot_z + brace_above_below + height/2 ])
502         cube(center=true, [ oring_bore - brace_end_shorter,
503                             brace_hole_width, height ]);
504       }
505     }
506   }
507   if (enable_head_cups)
508     for (r=[0,180])
509       rotate([0,0,r])
510         translate([-implheadcup_large_dia * .5 - implheadcup_thick/2,
511                    -implheadcup_large_dia * .0,
512                    middle_bot_z + 0.1])
513         ImplHeadCup();
514
515 //  translate(strap_loop_thick * [-0.5, 0, +1])
516 //    translate([handling_dia/2, 0, -side_height])
517 //    rotate([0,180,0]) rotate([0,0,90])
518 //    StrapLoop();
519 }
520
521 module SavingHole(){
522   translate([0,0, -10])
523     cylinder(r= main_dia/2 - jig_rim, h=20);
524 }
525
526 module Jig(){ ////toplevel
527   difference(){
528     union(){
529       translate([0,0, -side_height]){
530         cylinder(r= main_dia/2 + jig_thick, h= side_height + jig_thick);
531       }
532       translate([-jig_mark_rad, 0, jig_thick - jig_mark])
533         cube([jig_mark_rad*2, jig_mark, jig_mark]);
534     }
535     translate([0,0, -side_height-1])
536       cylinder(r= main_dia/2, h= side_height + 1);
537     SavingHole();
538     translate([0,0, -rivet_posn])
539       rotate([90, 0,0])
540       translate([0,0, -100])
541       cylinder(r= jig_hole_dia/2, h = 200);
542   }
543 }
544
545 module CoverPrint(){ ////toplevel
546   rotate([0,180,0]) Cover();
547 }
548
549 module CoverTest2(){ ////toplevel
550   difference(){
551     Cover();
552     SavingHole();
553   }
554 }
555
556 module CoverTest1(){ ////toplevel
557   difference(){
558     CoverTest2();
559     difference(){
560       for (r= [ 40, 147 ]){
561         rotate([0,0, r]){
562           translate([0,0, -10]) {
563             cube([ main_dia*3, main_dia * .53, 18], center=true);
564           }
565         }
566       }
567 //      translate([ 50, 0, 0 ])
568 //      cube([ 100,
569 //             strap_loop_inside + strap_loop_thick*2 + 1,
570 //             100 ],
571 //           center=true);
572     }
573   }
574 }
575
576 module ImplHeadCupTest(){ ////toplevel
577   for (r=[0,180])
578     rotate([0,0,r])
579       translate([-17,0,0])
580       ImplHeadCup();
581 }
582
583 module SomeStrap(width, cut_width=0){
584   // children(0) is to add, (1) subtract
585   difference(){
586     union(){
587       cylinder(r=sm_outer_rad, h=width);
588       StrapMountProtrusion(smc_cnr_c_x + sm_closure_cnr,
589                            smc_max_y,
590                            sm_closure_cnr,
591                            width);
592       children(0);
593     }
594     translate([0,0,-1])
595       cylinder(r=sm_inner_rad, h=max(width+2, cut_width));
596     translate(smc_pos)
597       StrapMountBolt(10, width);
598     translate(smc_pos)
599       cube([ sm_bolt_tighten_allow, 40,100 ], center=true);
600     children(1);
601   }
602 }
603
604 module StrapMountBolt(l_delta, strap_width){ ///toplevel
605   // positioned relative to smc_pos
606   translate([(smc_bolt_nut_eff_thick - sm_bolt_head_thick)/2,
607              smc_bolt_y,
608              strap_width/2]){
609     translate([ -sm_bolt_shaft/2-1, 0,0 ]){
610       rotate([0,90,0]) cylinder(r= sm_bolt_dia/2, h= sm_bolt_shaft+2);
611     }
612     translate([ -sm_bolt_shaft/2, 0,0 ])
613       rotate([0,-90,0])
614       cylinder($fn=6, r=smc_bolt_nut_dia/2,
615                h=smc_bolt_nut_eff_thick + l_delta);
616     translate([ sm_bolt_shaft/2, 0,0 ])
617       rotate([0,90,0])
618       cylinder(r=sm_bolt_head_dia/2, h=sm_bolt_head_thick + l_delta);
619   }
620 }
621
622 module StrapMountProtrusion(half_x, max_y, cnr, width){
623   translate(smc_pos){
624     linear_extrude(height=width, convexity=10){
625       hull(){
626         for (m = [0,1]) mirror([m,0,0]) {
627           translate([-(half_x - cnr), max_y - cnr])
628             circle(r=cnr);
629           translate([-half_x, -sm_inner_rad])
630             square([1,1]);
631         }
632       }
633     }
634   }
635 }
636
637 module StrapMount(){ ////toplevel
638   SomeStrap(sm_main_width){
639     rotate([0,0,180]){
640       StrapMountProtrusion(strap_loop_inside/2 + strap_loop_thick,
641                            strap_loop_thick,
642                            sm_closure_cnr,
643                            sm_main_width);
644       translate(smc_pos +
645                 [0,0, sm_main_width] +
646                 strap_loop_thick * [ 0, 0.5, -1.0 ])
647         StrapLoop();
648     }
649     union(){ };
650   }
651 }
652
653 module WallScrewHoleSlot(){ ////toplevel
654   ds = [-1,+1] * wm_screw_slot/2;
655   linextr_x_yz(-(wm_thick + 1), 1) {
656     hull(){
657       for (d = ds)
658         translate([d, 0])
659           circle(r = wm_screw_dia/2);
660     }
661   }
662   hull(){
663     for (d = ds){
664       translate([0, d, 0]){
665         linextr_x_yz(0, 1)
666           circle(r = wm_screw_head/2);
667         linextr_x_yz(-(wm_screw_head - wm_screw_dia)/2, 0)
668           circle(r = wm_screw_dia/2);
669       }
670     }
671   }
672 }
673
674 module WallMountMounts(){
675   linextr(0, wm_z_max){
676     translate([ -sm_outer_rad, 0 ])
677       rectfromto([ 0, -wm_y_max ],
678                  [ wm_thick, wm_y_slot1_max ]);
679   }
680 }
681 module WallMountScrewHoles(){
682   translate([ -sm_outer_rad + wm_thick, 0, wm_z_slotc_screw]) {
683     translate([ 0, wm_y_slotc_screw, 0 ])
684       WallScrewHoleSlot();
685     translate([ 0, -wm_y_slotc_screw, 0 ])
686       rotate([90,0,0])
687       WallScrewHoleSlot();
688   }
689 }
690
691 module WallMount(){ ////toplevel
692   SomeStrap(sm_main_width, wm_z_max + 2){
693     WallMountMounts();
694     WallMountScrewHoles();
695   }
696 }
697
698 module WallMountBaseRingCut(){
699   circle(r = wmb_mount_cut_rad);
700 }
701
702 module WallMountBaseMounts(){
703   linextr(0, wmb_z_max) {
704     difference(){
705       rectfromto([ -sm_outer_rad, -wmb_y_mount_max ],
706                  [ wmb_x_outer,   +wmb_y_mount_max ]);
707       WallMountBaseRingCut();
708     }
709   }
710 }
711
712 // screws, nuts, slots for nuts to go down into
713 module WallMountBaseScrewsEtc(){ ////toplevel
714   for (my=[0,1]) {
715     mirror([0, my, 0]) {
716       translate([wmb_x_screw, 0, wmb_z_screw]) {
717         linextr_y_xz(wmb_y_screw_end,
718                      wmb_y_screw_end + 100) // XXX change 100
719           circle(r = wmb_screw_dia/2);
720         linextr_y_xz(wmb_y_screw_end + web_screw_len,
721                      wmb_y_screw_end + 100) // XXX change 100
722           circle(r = wmb_screw_head_dia/2);
723         linextr_y_xz(wmb_y_nut_min,
724                      wmb_y_nut_min + wmb_nut_th) {
725           hull(){
726             rotate(30)
727               circle(r = wmb_nut_rad, $fn = 6);
728             translate([0, 100]) // XXX change 100
729               square(wmb_nut_across, center=true);
730           }
731         }
732       }
733     }
734   }
735 }
736
737 module WallMountForBase(){ ////toplevel
738   SomeStrap(sm_main_width, wm_z_max + 2){
739     union(){
740       WallMountMounts();
741       WallMountBaseMounts();
742     }
743     union(){
744       WallMountScrewHoles();
745       WallMountBaseScrewsEtc();
746     }
747   }
748 }
749
750 module WallMountBasePillarsPlan(){
751   for (my = [0,1]) {
752     mirror([0, my]) {
753       rectfromto([ -sm_outer_rad, wmbb_y_max - wmb_mount_y_width ],
754                  [ wmbb_x_outer, wmbb_y_max ]);
755     }
756   }
757 }
758
759 // trim parts that are would foul the wall
760 module WallMountTrimWallFoulPlan(){
761     translate([ -sm_outer_rad, 0])
762     rectfromto([ -wmbb_r_top, -(wmbb_r_top + 1) ],
763                [ 0,           +(wmbb_r_top + 1) ]);
764 }
765
766 module WallMountBase(){ ////toplevel
767   difference(){
768     union(){
769       // vertical blocks rising to join to wall mount
770       linextr(wmbb_z_min, wmb_z_max) {
771         difference(){
772           WallMountBasePillarsPlan();
773           WallMountBaseRingCut();
774         }
775       }
776
777       hull(){
778         linextr(wmbb_z_flat_whole_min, wmbb_z_flat_max)
779           circle(r = wmbb_r_top);
780         linextr(wmbb_z_min, wmbb_z_flat_max)
781           circle(r = wmbb_r_bottom);
782       }
783       linextr(wmbb_z_min, wmbb_z_flat_max) {
784         hull(){
785           WallMountBasePillarsPlan();
786           circle(r = wmbb_r_bottom);
787         }
788       }
789     }
790
791     // cutaway for mount part
792     linextr(-wmb_mount_gap_z, wmb_z_max+1) {
793       for (my = [0,1]) {
794         mirror([0, my])
795           rectfromto([ -sm_outer_rad-1, wmb_y_mount_max + wmb_mount_gap_xy ],
796                      [ wmb_x_outer + wmb_mount_gap_xy, 1 ]);
797       }
798     }
799
800     linextr(wmbb_z_min - 1, wmb_z_max + 1)
801       WallMountTrimWallFoulPlan();
802     WallMountBaseScrewsEtc();
803   }
804 }
805
806 module WallMountBaseCutJigPlan(){ ////toplevel
807   difference(){
808     union(){
809       circle(r = wmbb_r_top);
810     }
811
812     translate([ wmb_jig_around_gap, 0 ])
813       WallMountTrimWallFoulPlan();
814
815     offset(delta = wmb_jig_around_gap)
816       WallMountBasePillarsPlan();
817   }
818 }
819
820 module WallMountBaseCutJig(){ ////toplevel
821   translate([ 0,0, wmbb_z_flat_max + 0.5 ])
822     linextr(0, wmb_jig_th)
823     WallMountBaseCutJigPlan();
824 }
825
826 module WallMountForBaseDemo(){ ////toplevel
827   render() WallMountForBase();
828   color("blue") render() WallMountBase();
829   %WallMountBaseScrewsEtc();
830   %WallMountBaseCutJig();
831 }
832
833 module CatchAssemblyCoreProfile(){
834   difference(){
835     union(){
836       hull(){
837         translate(cpp3) circle(r= catch_cr3);
838         polygon([ cpp3,
839                   cpp2r,
840                   cpp5,
841                   cpph,
842                   cppd
843                   ]);
844       }
845       polygon([cppD,
846                cppC,
847                cpp9,
848                cpp10,
849                cpp11,
850                cpp4,
851                cpp2r,
852                cpp2d,
853                cppA,
854                cppE
855                ]);
856       translate(cpp8) circle(r= catch_cr);
857     }
858     hull(){
859       translate(cpp4) circle(r= catch_cr);
860       translate(cpp5) circle(r= catch_cr);
861       translate(cpp7) circle(r= catch_cr);
862       polygon([cpp4,
863                cppg,
864                cpph,
865                cpp10,
866                cpp11,
867                ]);
868     }
869     translate(cpp2) circle(r= catch_cr);
870   }
871   // if cpp11 is above cpp10, the subtracted hull above
872   // can go down too far.  Ensure we do not cut off below cppy6.
873   polygon([ cppE,
874             cppD,
875             cpp9,
876             [ cpp9[0],            cppy6 ],
877             [ cpp7[0] - catch_cr, cppy6 ],
878             cpp2d
879             ]);
880 }
881
882 module CatchTipProfile(dy){
883   ddy = [0,dy];
884   intersection(){
885     translate(cppF){
886       difference(){
887 //      circle(r = dist2d(cppF, cppd));
888         //circle(r = dist2d(cppF, cppa));
889       }
890     }
891     polygon([ cppa,
892               cppi + ddy,
893               cppd + ddy,
894               cppc,
895               cppb ]);
896   }
897 }
898
899 module CatchHeadProfile(){
900   polygon([ cppd,
901             cppd,
902             cppi,
903             cppf,
904             cppe,
905             cpph ]);
906 }
907
908
909 module CatchCore(){ /////toplevel
910   linear_extrude(height=catch_strap_thick, convexity=10)
911     CatchAssemblyCoreProfile();
912
913   hull(){
914     linear_extrude(height=catch_head_th, convexity=10)
915       CatchTipProfile(0);
916     linear_extrude(height=catch_tip_th, convexity=10)
917       CatchTipProfile(catch_tip_th - catch_head_th);
918   }
919
920   linear_extrude(height=catch_head_th, convexity=10)
921     CatchHeadProfile();
922
923   translate(concat(cppB,[0])) hull(){
924     translate([0,0, catch_knob_height + catch_head_th - catch_knob_dia/2])
925       sphere(r = catch_knob_dia/2);
926     cylinder(r = catch_knob_dia/2, h = 0.1);
927   }
928 }
929
930 module CatchPreDistort(){ /////toplevel
931   scale(100 / sm_inner_rad)
932     rotate([90,0,0])
933     CatchCore();
934 }
935
936 module CatchAssembly(){ /////toplevel
937   rotate([0,0, -(cppe[0] + cppB[0] + catch_pin_slop) / sm_inner_rad * 360/TAU])
938     translate([0,0, catch_assembly_dy])
939     scale(sm_inner_rad / 100)
940     import(str("poster-tube-lid,CatchPostDistort-fa",
941                (coarse ? 20 : 3),
942                ".stl"),
943            convexity=20);
944
945   SomeStrap(catch_strap_width){
946     union(){ }
947     union(){
948       translate([-200, -200, -200])
949         cube([400, 200, 400]);
950     }
951   }
952 }
953
954 module CatchDemo(){ /////toplevel
955   color("blue") translate([0,0,
956                            -catch_assembly_dy
957              ])
958     CatchAssembly();
959   translate([0,0,+side_height
960              ])
961     Cover();
962 }
963
964 module CatchDemoS(){ /////toplevel
965   color("blue") translate([0,0,
966              -catch_assembly_dy
967              ])
968     CatchAssembly();
969   intersection(){
970     translate([0,0,+side_height
971                ])
972       Cover();
973     mirror([0,1,0]) translate([-250,33,0]) cube([500,500,500]);
974   }
975   color("black")
976     translate([0,-33,0])
977     cube([6.15, 2,2], center=true);
978 }
979
980 module CatchPinProfileDemo(){ /////toplevel
981   translate([0, 0 * -bayo_behind,0]) {
982     echo("G ",
983          bayo_n[0] - bayo_e[0]);
984     color("blue") translate([0,0,
985                              +1,
986                ]) {
987       CatchAssemblyCoreProfile();
988       CatchHeadProfile();
989     }
990     translate([0,0,10])
991       color("red")
992       CatchTipProfile(0);
993
994     polygon(bayo_polygon, convexity=10);
995
996     // adhoc show a position
997     color("purple")
998     translate(concat(
999                      cppa,
1000                      10
1001                      )) difference(){ circle(2.5); circle(2.0); }
1002
1003  }
1004 }
1005
1006 //ProfilesDemo();
1007 //BayonetCutout();
1008 //MainProfile();
1009 //Cover();
1010 //Jig();
1011 //CoverTest();