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