]> www.fi.muni.cz Git - heater.git/blob - case.scad
c1df55c6f9c6be01c7f651b5d29dd6eb4f8203bd
[heater.git] / case.scad
1 lowres = 0; // fast rendering or fine printing with print-friendly orientation
2
3 eps = 0.01;
4 infty = 300;
5
6 wall = 1.5; // generic wall thickness
7
8 // 18650 is ~18mm diameter, ~65mm length, 
9 batt_diam = 18 + 0.8;
10 batt_len = 65 + 2.0;
11
12 cable_sep = 1.5;
13
14 // front flat area
15 front_flat_len = batt_len + 4*wall + 2*cable_sep;
16
17 // PCB-related dimensions
18 pcb_len = 36 + 1;       // length of the board
19 pcb_width = 11 + 0.5;   // width of the board
20 pcb_thick = 1.2 + 0.3;  // thickness of the board
21 pcb_comp_h = 2.2;       // height of the components on board
22 pcb_groove = 1;
23
24 body_top_h = 0.35 * batt_diam; // cube-shaped part of the body
25
26 wire_thick = 2.2;
27 wire_sep = 3.5;
28
29 batt_end_h = wire_sep/2 + wire_thick/2 + 1.5;;
30
31 lid_sep = 0.2; // the lid is made this much smaller to separate from the body
32
33 sw_diam = 2.5 + 0.5;
34 led_diam = 3 + 0.5;
35 sw_xoff =  250 * 25.4/1000; // x offset of microswitches
36 pcb_xoff = 90 * 25.4/1000; // offset of the LED from the middle of the PCB
37
38 prg_len = 10; // programming connector
39 prg_width = 7;
40
41 outcable_h = 4.5;
42 outcable_w = 2.5;
43
44 // mounting cylinder + holes
45 mounthole_w = 5;
46 mounthole_h = 3;
47 mountcyl_w = mounthole_w + 4*wall;
48 mountcyl_h = 2*wall;
49 mountcone_h = mounthole_h + 2*wall;
50
51 clip_pretension = 0.5;
52
53 module case_body() {
54         hull() {
55                 translate([-batt_len/2-2*wall-cable_sep, -batt_diam/2-wall, 0])
56                         cube([batt_len + 4*wall + 2*cable_sep,
57                                 batt_diam+2*wall, body_top_h]);
58                 difference() {
59                         translate([-batt_len/2-2*wall-cable_sep, 0, 0])
60                                 rotate([0, 90, 0])
61                                 cylinder(r=batt_diam/2+wall,
62                                         h = batt_len + 4*wall + 2*cable_sep);
63                         translate([-infty/2, -infty/2, eps]) cube(infty);
64                 };
65                 translate([-front_flat_len/2,
66                         batt_diam/2 - pcb_width,
67                         -batt_diam/2-2*pcb_comp_h-pcb_thick-wall])
68                         cube([front_flat_len, pcb_width+wall, eps]);
69         };
70         // mounting cylinders
71         for (x = [-1, 1]) translate([x*(batt_len/2-mounthole_w/2),
72                 batt_diam/2+wall, 0]) {
73                         translate([0, 0, -batt_diam/2-wall-2*pcb_comp_h-pcb_thick])
74                                 mount_cyl(); // front
75                         translate([0, 0, body_top_h]) // rear
76                                 scale([1, 1, -1])
77                                 mount_cyl();
78         };
79 };
80
81 module mount_cyl() {
82         assign(h = mounthole_h+wall)
83         hull () {
84                 translate([0, -mountcyl_w/2+mounthole_h + wall])
85                         cylinder(r = mountcyl_w/2, h = mountcyl_h);
86                 assign(l = 2*sqrt(h*(mountcyl_w-h)))
87                 translate([-l/2, 0, mountcyl_h + mountcone_h])
88                         cube([l, eps, eps]);
89         };
90 };
91         
92 module case() {
93         difference() {
94                 case_body();
95                 // upper cube-shaped part
96                 // rotate([20, 0, 0])
97                 translate([-batt_len/2, -batt_diam/2, 0])
98                         cube([batt_len, batt_diam, batt_diam]);
99
100                 // battery cylinder for the lower part
101                 translate([-batt_len/2, 0, 0])
102                         rotate([0, 90, 0])
103                         cylinder(r=batt_diam/2, h = batt_len);
104
105                 // hole for PCB
106                 translate([-pcb_len/2-pcb_xoff,
107                         batt_diam/2-pcb_width,
108                         -batt_diam/2-pcb_thick - pcb_comp_h])
109                         cube([pcb_len, pcb_width,
110                                 batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
111                 // hole above the PCB for the outgoing cable
112                 translate([-pcb_len/2-pcb_xoff-2*wall-outcable_w,
113                         batt_diam/2-pcb_width,
114                         -batt_diam/2-pcb_comp_h])
115                         cube([pcb_len, pcb_width,
116                                 batt_diam/2 + pcb_comp_h + eps]);
117                 // cable outlet
118                 translate([-pcb_xoff-pcb_len/2-wall-outcable_w,
119                         -pcb_width+batt_diam/2,
120                         -batt_diam/2-outcable_h])
121                         cube([outcable_w, infty, outcable_h]);
122                 // hole under the PCB
123                 translate([-pcb_len/2+pcb_groove-pcb_xoff,
124                         batt_diam/2-pcb_width + pcb_groove,
125                         -batt_diam/2-pcb_thick - 2*pcb_comp_h])
126                         cube([pcb_len-2*pcb_groove, pcb_width-2*pcb_groove,
127                                 batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
128                 // hole for prog connector
129                 translate([pcb_len/2-pcb_xoff-pcb_groove-eps,
130                         batt_diam/2-pcb_width/2-prg_width/2,
131                         -batt_diam/2-pcb_thick - 2*pcb_comp_h])
132                         difference() {
133                                 cube([prg_len+pcb_groove+eps, prg_width,
134                                         batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
135                                 translate([prg_len/2+pcb_groove, -eps, pcb_comp_h])
136                                         cube([prg_len/2+eps, prg_width+2*eps, pcb_thick]);
137                         };
138                 // LED hole
139                 translate([0, batt_diam/2-pcb_width/2, -infty/2]) {
140                         cylinder(r=led_diam/2, h=infty, $fn=6);
141                         translate([sw_xoff, 0, 0])
142                                 cylinder(r=sw_diam/2, h=infty, $fn=6);
143                         translate([-sw_xoff, 0, 0])
144                                 cylinder(r=sw_diam/2, h=infty, $fn=6);
145                 };
146                 // space under the wire holes for battery contacts
147                 translate([-batt_len/2-2*wall-cable_sep-eps, 0, 0])
148                         difference() {
149                                 rotate([0, 90, 0])
150                                         cylinder(r = batt_diam/2-wall, h = batt_len + 4*wall + 2*cable_sep + 2*eps);
151                                 translate([-infty/2, -infty/2, -batt_end_h])
152                                         cube(infty);
153                         };
154                 // space above the wire holes for battery contacts
155                 translate([-batt_len/2-2*wall-cable_sep-eps, -batt_diam/2, batt_end_h])
156                         cube([batt_len + 4*wall + 2*cable_sep + 2*eps, 
157                                 batt_diam,
158                                 batt_end_h]);
159                 // wire holes for battery contacts
160                 for (x = [-1, 1])
161                 for (y = [-1, 1])
162                         translate([-batt_len/2-wall-eps, x*wire_sep/2, y*wire_sep/2])
163                         rotate([0, 90, 0])
164                                 cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
165                 // wire hole from PCB to battery contacts
166                 // translate([-batt_len/2-wall-eps, 0, -batt_diam/2-pcb_comp_h + wire_thick/2])
167                 rotate([40, 0, 0])
168                 translate([-batt_len/2-wall-eps, 0, -batt_diam/2 - wall/2 - wire_thick/2])
169                         rotate([0, 90, 0])
170                                 cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
171                 // hole behind the battery contacts
172                 for(x=[1, -1])
173                 scale([x, 1, 1]) translate([batt_len/2+wall+cable_sep, 0, 0]) hull() {
174                         translate([0, -batt_diam/2, 0])
175                                 cube([wall + eps, batt_diam, infty]);
176                         rotate([0, 90, 0])
177                                 cylinder(r = batt_diam/2, h = wall+eps);
178                         translate([0, batt_diam/2 - pcb_width,
179                                 -batt_diam/2-pcb_comp_h-pcb_thick])
180                                 cube([wall + eps, pcb_width, eps]);
181                         translate([0, batt_diam/2 - pcb_width + 0.5*wall,
182                                 -batt_diam/2-2*pcb_comp_h-pcb_thick])
183                                 cube([wall + eps, pcb_width-0.5*wall, eps]);
184                 };
185                 // inner hole behind the battery contacts
186                 for(x=[1, -1])
187                 scale([x, 1, 1]) translate([batt_len/2+wall, 0, 0]) hull() {
188                         translate([0, -batt_diam/2+wall, 0])
189                                 cube([cable_sep + eps, batt_diam-2*wall, infty]);
190                         rotate([0, 90, 0])
191                                 cylinder(r = batt_diam/2-wall, h = cable_sep+eps);
192                 };
193                 // cable lead to battery contacts
194                 for (x=[1, -1]) scale([x, 1, 1])
195                         rotate([-140, 0, 0])
196                         translate([batt_len/2-eps, -wire_thick/2, batt_diam/2-2.7])
197                                 cube([wall+cable_sep+2*eps, wire_thick, 5.4]);
198                 
199                 // mounting holes
200                 for(x=[-1,1]) scale([x, 1, 1])
201                 translate([batt_len/2-mounthole_w/2, batt_diam/2+wall+mounthole_h/2, -infty/2])
202                         scale([1, mounthole_h/mounthole_w, 1])
203                         cylinder(r = mounthole_w/2, h = infty);
204                 // grabbing gap
205                 for(x=[-1,1]) scale([x, 1, 1])
206                 translate([batt_len/2+cable_sep+wall+10, batt_diam/2-pcb_width/2, -batt_diam/2-2*pcb_comp_h-pcb_thick-wall-eps])
207                         cylinder(r1 = 10, r2 = 10 - wall, h = wall + 2*eps);
208         };
209         // clip barrier
210         for (x = [-1, 1]) scale([x, 1, 1]) hull () {
211                 translate([batt_len/2+wall+cable_sep-eps, batt_diam/2-pcb_width+wall/2+lid_sep,
212                         -batt_diam/2-pcb_thick-pcb_comp_h + wall + lid_sep])
213                         cube([wall+eps, pcb_width-2*wall-2*lid_sep, wall]);
214                 translate([batt_len/2+wall+cable_sep-eps, batt_diam/2-pcb_width+3*wall/2+lid_sep,
215                         -batt_diam/2-pcb_thick-pcb_comp_h + 3*wall + lid_sep])
216                         cube([eps, pcb_width-4*wall-2*lid_sep, eps]);
217         };
218 };
219
220 module lid_body() {
221         translate([-batt_len/2 - wall - cable_sep - lid_sep, -batt_diam/2+lid_sep, -batt_diam/2 -wall])
222                 cube([batt_len + 2*wall + 2*cable_sep + 2*lid_sep, batt_diam-2*lid_sep, batt_diam/2 - batt_end_h + wall - lid_sep]);
223         hull () {
224                 translate([-batt_len/2 - 2*wall - cable_sep,
225                         -batt_diam/2, -batt_diam/2-wall])
226                         cube([batt_len + 4*wall + 2*cable_sep,
227                                 batt_diam, eps]);
228                 translate([-batt_len/2 - 3*wall - cable_sep,
229                         -batt_diam/2 - wall, -body_top_h-wall/2-lid_sep])
230                         cube([batt_len + 6*wall + 2*cable_sep,
231                                 batt_diam + 2*wall, wall/2]);
232         };
233         // clip behind the battery contacts
234         for(x=[1, -1])
235                 scale([x, 1, 1]) translate([batt_len/2+wall+cable_sep+lid_sep, 0, 0]) hull() {
236                         translate([0, -batt_diam/2+lid_sep, -batt_diam/2])
237                                 cube([wall-lid_sep, batt_diam-2*lid_sep, eps]);
238                         rotate([0, 90, 0])
239                                 cylinder(r = batt_diam/2-lid_sep, h = wall-lid_sep);
240                         translate([-clip_pretension, batt_diam/2 - pcb_width + 0.5*wall + lid_sep,
241                                 batt_diam/2+2*pcb_comp_h+pcb_thick-lid_sep])
242                                 cube([wall+clip_pretension, pcb_width-0.5*wall-1.5*lid_sep, eps]);
243                 };
244         // outer part of the clip behind the battery contacts
245         for (x=[1, -1]) scale([x, 1, 1]) translate([batt_len/2+2*wall+cable_sep+lid_sep, 0, 0]) hull() {
246                 translate([0, -batt_diam/2 - wall, -body_top_h-wall/2-lid_sep])
247                         cube([wall-lid_sep, batt_diam + 2*wall, wall/2]);
248                 difference() {
249                         scale([0.3, 1, 1])
250                                 sphere(batt_diam/2+wall);
251                         translate([-infty/2, -infty/2, -infty-body_top_h-lid_sep+2*wall])
252                                 cube(infty);
253                         translate([-infty-clip_pretension, -infty/2, -infty/2])
254                                 cube(infty);
255                 };
256                 translate([-clip_pretension,
257                         batt_diam/2 - pcb_width,
258                         batt_diam/2+2*pcb_comp_h+pcb_thick+wall])
259                         cube([wall-lid_sep, pcb_width+wall, eps]);
260         };
261 };
262
263 module lid() {
264         difference() {
265                 lid_body();
266                 translate([-batt_len/2+eps, 0, 0]) rotate([0, 90, 0])
267                         cylinder(r=batt_diam/2, h=batt_len-2*eps);
268         // clip barrier
269         for (x = [-1, 1]) scale([x, 1, 1]) hull () {
270                 translate([batt_len/2+wall+cable_sep-clip_pretension, batt_diam/2-pcb_width+wall/2,
271                         batt_diam/2+pcb_thick+pcb_comp_h-2*wall])
272                         cube([wall+clip_pretension+eps, pcb_width-2*wall, wall]);
273                 translate([batt_len/2+wall+cable_sep-eps, batt_diam/2-pcb_width+wall/2,
274                         batt_diam/2+pcb_thick+pcb_comp_h-4*wall + lid_sep])
275                         cube([eps, pcb_width-2*wall, eps]);
276         };
277 /*
278                 hull() {
279                         difference() {
280                                 translate([-batt_len/2-cable_sep-wall, 0, 0]) rotate([0, 90, 0])
281                                         cylinder(r=batt_diam/2-wall-lid_sep, h=batt_len+2*wall+2*cable_sep);
282                                 translate([-infty/2, -batt_diam/2, -infty-wire_sep/2-wire_thick/2])
283                                         cube([infty, batt_diam, infty]);
284                         };
285                         translate([-batt_len/2-cable_sep-wall, batt_diam/2-pcb_width+0.5*wall+0.5*lid_sep, batt_diam/2 + pcb_comp_h+pcb_thick-wall-lid_sep])
286                         cube([batt_len + 2*wall + 2* cable_sep, pcb_width-1.5*wall-1.5*lid_sep, eps]);
287                 };
288 */
289         };
290 };
291
292 if (lowres) {
293         translate([0, 15, 0]) case();
294         translate([0, -15, 0]) rotate([180, 0, 0]) lid();
295 } else {
296         translate([0, 15, batt_diam/2+pcb_thick+2*pcb_comp_h+wall])
297                 case($fn=128);
298         translate([0, -15, batt_diam/2+wall])
299                 lid($fn=128);
300 }
301