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