chiark / gitweb /
poster-tube-lid: sloping bottom of catch tip
[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.2];
40 screw_info_M3   = [3,   1.2];
41 screw_info_M4   = [4,   1.1];
42 screw_info_M5   = [5,   1.0];
43 screw_info_M6   = [6,   1.2];
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.50 + 1.0;
48 function screw_recess_depth(info)       = info[0] * 1.00 + 0.50;
49 function screw_recess_depth_allen(info) = info[0] * 1.55 + 0.50;
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, ymul, labelnumber=false){
84   blocksz = Test_blocksz(t);
85   translate([0, ymul * (blocksz*0.5 - 1.5), 0]) {
86     difference(){
87       translate([-blocksz/2, -blocksz/2, 0])
88         cube([blocksz, blocksz, h]);
89       child();
90     }
91     if (labelnumber) {
92       rotate([90,0,0])
93         translate([-blocksz/4,blocksz/5, blocksz/2-1])
94         linear_extrude(height=0.3+1)
95       import(file=str("screw-recess-test-number-s",t[0],".dxf"), convexity=100);
96     }
97   }
98 }
99
100 module OneTest(t){
101   h = RecessedScrewCutoutStandard_totaldepth(t) + 3;
102   ha = RecessedScrewCutoutStandardAllen_totaldepth(t) + 3;
103   OneTestCore(t, h, 1){
104     RecessedScrewCutoutStandard(t, h+1);
105   }
106   OneTestCore(t, ha, -1, true){
107     RecessedScrewCutoutStandardAllen(t, ha+1);
108   }
109 }
110
111 function Test_x(i) = i<=0 ? 0 :
112   Test_x(i-1) + Test_blocksz(tests[i-1])/2 + Test_blocksz(tests[i])/2 - 3;
113
114 module Tests(){
115   for (i = [0:len(tests)-1]) {
116     echo(i, Test_x(i));
117     translate([Test_x(i), 0, 0])
118       OneTest(tests[i]);
119   }
120 }
121
122 //OneTest(tests[1]);
123 Tests();
124 //Hole();
125 //Holes();