chiark / gitweb /
a5dab4fdf184c5d9a66c0c7abc3ac7433f0969c9
[reprap-play.git] / screw-recess-test.scad
1 // -*- C -*-
2
3 module RecessScrewCutout_RecessCylinder(recessdia,zbelow, h){
4   translate([0,0,-zbelow]) cylinder(r=recessdia/2, h=h+1, $fn=40);
5 }
6
7 RecessedScrewCutout_defaultrecessdepth_flat = -0.30;
8 RecessedScrewCutout_defaultrecessdepth_hex = -0.60;
9
10 function RecessedScrewCutout_recessdepth(recessdia,
11         recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) =
12   recessdepth_arg >= 0 ? recessdepth_arg : -recessdepth_arg * recessdia;
13
14 function RecessedScrewCutout_totaldepth(recessdia,
15         recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) =
16   RecessedScrewCutout_recessdepth(recessdia, recessdepth_arg) +
17   + 0.5*recessdia + 0.1;
18
19 module RecessedScrewCutout(shaftdia, recessdia, shaftlen,
20         zbelow=1,
21         recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) {
22   // pass recessdepth_arg=-1 for the default for flat heads
23   // pass recessdepth_arg=-1 for the default for flat heads
24   recessdepth = RecessedScrewCutout_recessdepth(recessdia, recessdepth_arg);
25   recesstopz = RecessedScrewCutout_totaldepth(recessdia, recessdepth_arg);
26
27   translate([0,0,-zbelow]) cylinder(r=shaftdia/2, h=shaftlen+zbelow, $fn=20);
28   RecessScrewCutout_RecessCylinder(recessdia,zbelow, recessdepth);
29   intersection(){
30     cube([recessdia + 1, shaftdia + 0.1, recesstopz*2 + 1], center=true);
31     translate([0, -recessdia, recesstopz])
32       rotate([0,135,0]) cube([recessdia, recessdia*2, 10]);
33     RecessScrewCutout_RecessCylinder(recessdia,zbelow, recesstopz+1);
34   }
35 }
36
37 //              nom.   shaft
38 //              shaft   slop
39 screw_info_M2   = [2,   1.5];
40 screw_info_M3   = [3,   1.5];
41 screw_info_M4   = [4,   1.2];
42 screw_info_M5   = [5,   1.0];
43 screw_info_M6   = [6,   0.9];
44
45 function screw_shaft_dia_nom(info)      = info[0];
46 function screw_shaft_dia_use(info)      = info[0] + info[1];
47 function screw_recess_dia_use(info)     = info[0] * 2.5;
48 function screw_recess_depth(info)       = info[0] *  .65;
49 function screw_recess_depth_allen(info) = info[0] * 1.20;
50
51 function RecessedScrewCutoutStandard_totaldepth(info) =
52   RecessedScrewCutout_totaldepth(screw_recess_dia_use(info),
53                                  screw_recess_depth(info));
54
55 function RecessedScrewCutoutStandardAllen_totaldepth(info) =
56   RecessedScrewCutout_totaldepth(screw_recess_dia_use(info),
57                                  screw_recess_depth_allen(info));
58
59 module RecessedScrewCutoutStandard(info, shaftlen, zbelow=1) {
60   RecessedScrewCutout(screw_shaft_dia_use(info),
61                       screw_recess_dia_use(info),
62                       shaftlen, zbelow,
63                       screw_recess_depth(info));
64 }                                
65
66 module RecessedScrewCutoutStandardAllen(info, shaftlen, zbelow=1) {
67   RecessedScrewCutout(screw_shaft_dia_use(info),
68                       screw_recess_dia_use(info),
69                       shaftlen, zbelow,
70                       screw_recess_depth_allen(info));
71 }                                
72
73 tests = [
74          screw_info_M2,
75          screw_info_M3,
76          screw_info_M4,
77          screw_info_M5,
78          screw_info_M6
79          ];
80
81 function Test_blocksz(t) = screw_recess_dia_use(t) + 7;
82
83 module OneTestCore(t, h){
84   blocksz = Test_blocksz(t);
85   difference(){
86     translate([-blocksz/2, -blocksz/2, 0])
87       cube([blocksz, blocksz, h]);
88     child();
89   }
90 }
91
92 module OneTest(t){
93   h = RecessedScrewCutoutStandard_totaldepth(t);
94   OneTestCore(t, h){
95     RecessedScrewCutoutStandard(t, h+1);
96   }
97 }
98
99 function Test_x(i) = i<=0 ? 0 :
100   Test_x(i-1) + Test_blocksz(tests[i-1])/2 + Test_blocksz(tests[i])/2 - 3;
101
102 module Tests(){
103   for (i = [0:len(tests)-1]) {
104     echo(i, Test_x(i));
105     translate([Test_x(i), 0, 0])
106       OneTest(tests[i]);
107   }
108 }
109
110 //OneTest(tests[1]);
111 Tests();
112 //Hole();
113 //Holes();