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