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