chiark / gitweb /
e2e673a9f66245d4569e5163a57fba0d83c72984
[reprap-play.git] / bike-lipo-box.scad
1 // -*- C -*-
2
3 include <commitid.scad>
4 include <utils.scad>
5 include <sealing-box.scad>
6 include <bike-lipo-box-gland.scad>
7
8 pxp6012_rad = 22.5 / 2 + 0.5; // make circular hole this size in outer wall
9 pxp6012_rad_outer = 32.0 / 2 - 0.5;
10
11 s1930_y = 30.2 + 0.2;
12 s1930_x =   22 + 0.2;
13 s1930_y_outer = 36.4 + 0.2;
14 s1930_x_outer = 27.6 + 0.2;
15
16 s1930_recess = 3;
17 s1930_around = 3;
18 s1930_behind = 3;
19
20 totx_inner = 180;
21 toty_outer = 95;
22 totz_inner = 27.0;
23
24 wallthick = 2.5;
25
26 cabledia = 8.7;
27
28 strap_w = 5 + 1;
29 strap_th = 4 + 1;
30 strap_pillar = 3;
31 strap_pillard = 5;
32 strap_over = 2;
33
34 lipokeeper_w = 10;
35 lipokeeper_h = 8;
36 lipokeeper_d_min = 2;
37 lipokeeper_slope = 0.75;
38 lipokeeper_end_d_min = 15;
39
40 straps_at_box = [45, 95, 125, 160];
41 straps_every = 30;
42
43 // calculated
44
45 totx_outer = totx_inner + wallthick*2;
46 toty_inner = toty_outer - wallthick*2;
47 totz_outer = totz_inner + wallthick*2;
48
49 sb_box_sz = [totx_outer, totz_outer, toty_inner];
50
51 // origin is at centre on outer face wall
52 // outside is towards positive x
53 // mounting is vertical
54 module S1930_Positive(){
55   d = s1930_recess + s1930_behind;
56   translate([-d/2, 0,0])
57     cube([d,
58           s1930_x_outer + s1930_around,
59           s1930_y_outer + s1930_around], center=true);
60 }
61 module S1930_Negative(){
62   cube([60, s1930_x, s1930_y],
63        center=true);
64   translate([1, 0,0])
65     cube([s1930_recess*2+2, s1930_x_outer, s1930_y_outer],
66          center=true);
67 }
68
69 module TestWall(){ ////toplevel
70   sw_ctr = [25, wallthick, 25];
71
72   rotate([0,0,-90]){
73     difference(){
74       union(){
75         cube([50, wallthick, 42]);
76       }
77
78       translate([30, -1, 20])
79         rotate([-90,0,0])
80         cylinder(r = pxp6012_rad, h=10, $fn=60);
81
82       rotate([90,0,0])
83         Commitid_BestCount([15,40]);
84     }
85   }
86
87   difference(){
88     union(){
89       cube([50, wallthick, 50]);
90       translate(sw_ctr)
91         rotate([0,0,90])
92         S1930_Positive();
93     }
94
95     translate(sw_ctr) {
96       rotate([0,0,90])
97         S1930_Negative();
98     }
99   }    
100 }
101
102 ts_totx = 30;
103 ts_toty = 25;
104 ts_totz_inner = 8;
105
106 ts_box_sz = [ts_totx, ts_toty, ts_totz_inner];
107
108 $sealingbox_wallth = wallthick;
109 $sealingbox_floorth = wallthick;
110 $sealingbox_ceilth = wallthick;
111
112 module TestSealBox(){ ////toplevel
113   $sealingbox_sz = ts_box_sz;
114
115   SealingBox_RectBox();
116   ts_cidoff = ($sealingbox_cnrrad * (1-.7) + wallthick * .8) * [1,1];
117   translate(ts_cidoff)
118     Commitid_BestCount([ts_totx,ts_toty] - 2*ts_cidoff);
119 }
120
121 module TestSealLid(){ ////toplevel
122   $sealingbox_sz = ts_box_sz;
123
124   difference(){
125     SealingBox_RectLid();
126
127     translate([ts_totx * .75, ts_toty/2, 0])
128       cylinder(h=100, r=5);
129     
130     translate([-wallthick + $sealingbox_cnrrad*.5,
131                $sealingbox_cnrrad*.5 - wallthick,
132                ts_totz_inner + $sealingbox_ceilth])
133       Commitid_BestCount([ts_totx * .75 - 2.5 - ($sealingbox_cnrrad*.5),
134                           ts_toty - ($sealingbox_cnrrad*.5 - wallthick)*2]);
135   }
136 }
137
138 module TestSealLidPrint(){ ////toplevel
139   rotate([180,0,0]) TestSealLid();
140 }
141
142 module ProfileDemos(){ ////toplevel
143   $sealingbox_sz = ts_box_sz;
144
145   SealingBox_WallProfile();
146   color("blue") SealingBox_FloorProfile();
147   SealingBox_LidProfile();
148   color("blue") SealingBox_CeilProfile();
149   color("red") translate([-5,0]) square([1,ts_totz_inner]);
150 }
151
152 module AtGlands(){
153   for (dgy=[-15,-45]) {
154     translate([totx_inner + wallthick - $sealingbox_cnrrad * .3,
155                toty_inner + dgy,
156                totz_inner/2])
157       children();
158   }
159 }
160
161 module StrapKeepers(at){
162   strap_x_tot = strap_w + strap_pillar*2;
163
164   for (sx= at) {
165     echo("strapkeeper at ",sx);
166     translate([sx - strap_x_tot, 0, 0])
167       difference(){
168       translate([0,0, -0.1])
169         cube([strap_x_tot, strap_pillard, strap_th + strap_over]);
170       translate([strap_pillar, -1, 0])
171         cube([strap_w, strap_pillard+2, strap_th]);
172     }
173   }
174 }
175
176 chargingconn_x = pxp6012_rad_outer + 1 + $sealingbox_cnrrad;
177 switch_x = chargingconn_x + pxp6012_rad_outer
178   + s1930_y_outer/2 + s1930_around;
179
180 module AtSealingBox(){
181   rotate([90,0,0])
182     translate([-wallthick,-wallthick, -toty_inner])
183     children();
184 }
185
186 module Box(){ ////toplevel
187   $sealingbox_sz = sb_box_sz;
188
189   difference(){
190     union(){
191       AtSealingBox()
192         SealingBox_RectBox();
193
194       translate([switch_x, toty_inner, totz_inner/2])
195         rotate([90,0,90])
196         S1930_Positive();
197
198       // keepers for lipo
199       for (keepers= [[ 40, lipokeeper_d_min,     lipokeeper_h,
200                        [ 10, 40, 80, 120 ] ],
201                      [ 20, lipokeeper_end_d_min, lipokeeper_h,
202                        [ 135 ] ]
203                      // each entry: [ y, d_min, h, [ x, ...] ]
204                      ])
205         for (kx= keepers[3]) {
206           translate([kx, keepers[0], -1])
207             hull(){
208               cube([lipokeeper_w, keepers[1], keepers[2] +1]);
209               cube([lipokeeper_w,
210                     keepers[1] + keepers[2] / lipokeeper_slope,
211                     1]);
212             }
213       }
214
215       AtGlands()
216         GlandPositive(cabledia);
217
218       translate([0, toty_inner+wallthick, -wallthick])
219         rotate([180, 0,0])
220         StrapKeepers(straps_at_box);
221     }
222
223     // charging connector
224     translate([chargingconn_x,
225                toty_inner - (pxp6012_rad_outer + 5),
226                10])
227       cylinder(r= pxp6012_rad, h= totz_outer);
228
229     translate([switch_x, toty_inner, totz_inner/2])
230       rotate([90,0,90])
231       S1930_Negative();
232
233     AtGlands()
234       GlandNegative(cabledia);
235
236     translate($sealingbox_cnrrad * [1,1,0] +
237               [0, toty_inner/2, -wallthick])
238       Commitid_Full16_M();
239   }
240 }
241
242 module BoxPrint(){ ////toplevel
243   rotate([-90,0,-90])
244     Box();
245 }
246
247 module Lid(){ ////toplevel
248   $sealingbox_sz = sb_box_sz;
249   difference(){
250     union(){
251       AtSealingBox()
252         SealingBox_RectLid();
253       translate([0, -wallthick, -SealingBox_lidbigger()])
254         mirror([0,0,1])
255         StrapKeepers([ straps_every : straps_every
256                        : totx_inner-straps_every ]);
257     }
258
259     translate($sealingbox_cnrrad * [1,0,1])
260       rotate([90,0,0])
261       Commitid_Full16_M();
262   }
263 }
264
265 module LidPrint(){ ////toplevel
266   rotate([90,0,-90])
267     Lid();
268 }
269
270 module Demo(){ ////toplevel
271   color("blue") Box();
272   color("red") Lid();
273 }
274
275 //TestWall();
276 //ProfileDemos();
277 //TestSealBox();
278 //TestSealLid();
279 //FArcSegment_mask(350);
280 //StrapKeepers();