chiark / gitweb /
bike-lipo-box: TestWall: replace ad-hoc with S1930_Negative (nfc)
[reprap-play.git] / bike-lipo-box.scad.m4
1 // -*- C -*-
2
3 include <commitid.scad>
4 include <utils.scad>
5
6 pxp6012_rad = 22.5 / 2 + 0.5;
7 pxp6012_rad_outer = 32.0 / 2 - 0.5;
8
9 s1930_y = 30.2 + 0.2;
10 s1930_x =   22 + 0.2;
11 s1930_y_outer = 36.4 + 0.2;
12 s1930_x_outer = 27.6 + 0.2;
13
14 s1930_recess = 3;
15 s1930_around = 3;
16 s1930_behind = 3;
17
18 wallthick = 2.5;
19
20 // origin is at centre on outer face wall
21 // outside is towards positive x
22 // mounting is vertical
23 module S1930_Positive(){
24   d = s1930_recess + s1930_behind;
25   translate([-d/2, 0,0])
26     cube([d,
27           s1930_x_outer + s1930_around,
28           s1930_y_outer + s1930_around], center=true);
29 }
30 module S1930_Negative(){
31   cube([60, s1930_x, s1930_y],
32        center=true);
33   translate([1, 0,0])
34     cube([s1930_recess*2+2, s1930_x_outer, s1930_y_outer],
35          center=true);
36 }
37
38 module TestWall(){ ////toplevel
39   sw_ctr = [25, 0, 25];
40   sw_ctr_new = [25,
41                 wallthick + 0.5, // xxx compatibility bug
42                 25];
43
44   rotate([0,0,-90]){
45     difference(){
46       union(){
47         cube([50, wallthick, 42]);
48       }
49
50       translate([30, -1, 20])
51         rotate([-90,0,0])
52         cylinder(r = pxp6012_rad, h=10, $fn=60);
53
54       rotate([90,0,0])
55         Commitid_BestCount([15,40]);
56     }
57   }
58
59   difference(){
60     union(){
61       cube([50, wallthick, 50]);
62       translate(sw_ctr_new)
63         rotate([0,0,90])
64         S1930_Positive();
65     }
66
67     translate(sw_ctr_new) {
68       rotate([0,0,90])
69         S1930_Negative();
70     }
71   }    
72 }
73
74 floorth = 2.5;
75 ceilth = 2.5;
76 innertube = 1.0 + 0.2;
77 lidoverlap = 1.5;
78 lidoverhang = 6;
79 tubesealrad = 2.0;
80
81 ts_xbox = 30;
82 ts_ybox = 25;
83 ts_cnrrad = 10;
84 ts_zbox = 8;
85
86 ts_cidoff = (ts_cnrrad * (1-.7) + wallthick * .8) * [1,1];
87
88 m4_dnl Box_Part($1=transl_x,$2=transl_y, $3=rot_z,$4=mirror_xy)
89 m4_dnl          $5=kind, $6=kindargs, $7=profile(profileargsargs))
90 m4_define(`Box_Part',`
91   translate([($1),($2)])
92     rotate([0,0,($3)])
93     mirror([($4),0,0])
94     BoxPart_Extrude_$5($6, $7)') m4_dnl
95
96 boxpart_d = 0.01;
97
98 m4_dnl BoxPart_Extrude_Linear(dist, `profile(...);');
99 m4_define(`BoxPart_Extrude_Linear',`
100   rotate([90,0,0])
101     translate([0,0, -($1)])
102     linear_extrude(height= boxpart_d + ($1)) {
103       $2
104     }
105 ')
106
107 m4_dnl BoxPart_Extrude_Arc(x0_radius, swept_angle, `profile(...);')
108 m4_dnl  arc starting at transl_x, transl_y, moving towards positive
109 m4_dnl  y at first and then bending towards negative x, until
110 m4_dnl  use negative x0_radius to inciate bending towards positive x
111 m4_dnl  swept_angle is reached
112 m4_dnl  x0_radius is the radius of the extruded part at x=0, not of the box
113 m4_define(`BoxPart_Extrude_Arc',`
114   translate([-($1),0,0])
115     intersection(){
116       translate([0,0,-500])
117         linear_extrude(height=1000)
118         scale(500)
119         mirror([($1)<0, 0,0])
120         FArcSegment_mask($2);
121       rotate_extrude(convexity=10, $fs=1, $fn=36)
122         mirror([($1)<0, 0,0])
123         translate([+($1),0,0]){
124           $3
125         }
126     }
127 ')
128
129 ts_xbox_lin = ts_xbox - ts_cnrrad*2;
130 ts_ybox_lin = ts_ybox - ts_cnrrad*2;
131
132 m4_dnl TestSealDoBoxShape(`profile(profileargs)');
133 m4_define(`TestSealDoBoxShape',`
134   Box_Part(0,               ts_cnrrad,    0,0, Linear,`ts_ybox_lin', `$1' )
135   Box_Part(0, ts_ybox-ts_cnrrad,          0,0, Arc,`-ts_cnrrad,90' , `$1' )
136   Box_Part(ts_cnrrad,       ts_ybox,    -90,0, Linear,`ts_xbox_lin', `$1' )
137   Box_Part(ts_xbox-ts_cnrrad, ts_ybox,  -90,0, Arc,`-ts_cnrrad,90' , `$1' )
138   Box_Part(ts_xbox, ts_ybox-ts_cnrrad, -180,0, Linear,`ts_ybox_lin', `$1' )
139   Box_Part(ts_xbox,         ts_cnrrad, -180,0, Arc,`-ts_cnrrad,90' , `$1' )
140   Box_Part(ts_xbox-ts_cnrrad, 0,       -270,0, Linear,`ts_xbox_lin', `$1' )
141   Box_Part(ts_cnrrad,         0,       -270,0, Arc,`-ts_cnrrad,90' , `$1' )
142 ')
143
144 m4_dnl '
145
146 module WallProfile(){
147   z = ts_zbox - innertube - tubesealrad;
148   translate([0, -0.1]) square([wallthick, z]);
149   translate([tubesealrad, z]) circle(r=tubesealrad, $fn=20);
150 }
151
152 module FloorProfile(){
153   mirror([0,1]) square([wallthick, floorth]);
154 }
155
156 module LidProfile(){
157   rad = tubesealrad + innertube;
158   morex = wallthick;
159   difference(){
160     translate([-lidoverlap - innertube,
161                ts_zbox - lidoverhang - innertube])
162       square([lidoverlap + innertube + wallthick,
163               lidoverhang + innertube + ceilth]);
164     hull(){
165       translate([tubesealrad,
166                  ts_zbox - innertube - tubesealrad])
167         for (t=[ [0,0],
168                  [morex*2, 0],
169                  [0, -ts_zbox]
170                  ]) {
171           translate(t)
172             circle(r= tubesealrad + innertube, $fn=20);
173         }
174     }
175   }
176 }
177
178 module CeilProfile(){
179   translate([0, ts_zbox])
180     square([wallthick*2, ceilth]);
181 }
182
183 module TestSealBox(){ ////toplevel
184   TestSealDoBoxShape(WallProfile(););
185   hull(){ TestSealDoBoxShape(FloorProfile();); }
186   translate(ts_cidoff)
187     Commitid_BestCount([ts_xbox,ts_ybox] - 2*ts_cidoff);
188 }
189
190 module TestSealLid(){ ////toplevel
191   difference(){
192     union(){
193       TestSealDoBoxShape(LidProfile(););
194       hull(){ TestSealDoBoxShape(CeilProfile();); }
195     }
196     translate([ts_xbox * .75, ts_ybox/2, 0])
197       cylinder(h=100, r=5);
198     
199     translate([-wallthick + ts_cnrrad*.5,
200                ts_cnrrad*.5 - wallthick,
201                ts_zbox + ceilth])
202       Commitid_BestCount([ts_xbox * .75 - 2.5 - (ts_cnrrad*.5),
203                           ts_ybox - (ts_cnrrad*.5 - wallthick)*2]);
204   }
205 }
206
207 module TestSealLidPrint(){ ////toplevel
208   rotate([180,0,0]) TestSealLid();
209 }
210
211 module ProfileDemos(){
212   WallProfile();
213   color("blue") FloorProfile();
214   LidProfile();
215   color("blue") CeilProfile();
216 }
217                           
218 //TestWall();
219 //ProfileDemos();
220 //TestSealBox();
221 //TestSealLid();
222 //FArcSegment_mask(350);