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