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