status LED visual feedback
[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 plus_width = 4.5; // width of the + sign
54
55 module case_body() {
56         hull() {
57                 translate([-batt_len/2-2*wall-cable_sep, -batt_diam/2-wall, 0])
58                         cube([batt_len + 4*wall + 2*cable_sep,
59                                 batt_diam+2*wall, body_top_h]);
60                 difference() {
61                         translate([-batt_len/2-2*wall-cable_sep, 0, 0])
62                                 rotate([0, 90, 0])
63                                 cylinder(r=batt_diam/2+wall,
64                                         h = batt_len + 4*wall + 2*cable_sep);
65                         translate([-infty/2, -infty/2, eps]) cube(infty);
66                 };
67                 translate([-front_flat_len/2,
68                         batt_diam/2 - pcb_width,
69                         -batt_diam/2-2*pcb_comp_h-pcb_thick-wall])
70                         cube([front_flat_len, pcb_width+wall, eps]);
71         };
72         // mounting cylinders
73         for (x = [-1, 1]) translate([x*(batt_len/2-mounthole_w/2),
74                 batt_diam/2+wall, 0]) {
75                         translate([0, 0, -batt_diam/2-wall-2*pcb_comp_h-pcb_thick])
76                                 mount_cyl(); // front
77                         translate([0, 0, body_top_h]) // rear
78                                 scale([1, 1, -1])
79                                 mount_cyl();
80         };
81 };
82
83 module mount_cyl() {
84         assign(h = mounthole_h+wall)
85         hull () {
86                 translate([0, -mountcyl_w/2+mounthole_h + wall])
87                         cylinder(r = mountcyl_w/2, h = mountcyl_h);
88                 assign(l = 2*sqrt(h*(mountcyl_w-h)))
89                 translate([-l/2, 0, mountcyl_h + mountcone_h])
90                         cube([l, eps, eps]);
91         };
92 };
93         
94 module case() {
95         difference() {
96                 case_body();
97                 // upper cube-shaped part
98                 // rotate([20, 0, 0])
99                 translate([-batt_len/2, -batt_diam/2, 0])
100                         cube([batt_len, batt_diam, batt_diam]);
101
102                 // battery cylinder for the lower part
103                 translate([-batt_len/2, 0, 0])
104                         rotate([0, 90, 0])
105                         cylinder(r=batt_diam/2, h = batt_len);
106
107                 // hole for PCB
108                 translate([-pcb_len/2-pcb_xoff,
109                         batt_diam/2-pcb_width,
110                         -batt_diam/2-pcb_thick - pcb_comp_h])
111                         cube([pcb_len, pcb_width,
112                                 batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
113                 // hole above the PCB for the outgoing cable
114                 translate([-pcb_len/2-pcb_xoff-2*wall-outcable_w,
115                         batt_diam/2-pcb_width,
116                         -batt_diam/2-pcb_comp_h])
117                         cube([pcb_len, pcb_width,
118                                 batt_diam/2 + pcb_comp_h + eps]);
119                 // cable outlet
120                 translate([-pcb_xoff-pcb_len/2-wall-outcable_w,
121                         -pcb_width+batt_diam/2,
122                         -batt_diam/2-outcable_h])
123                         cube([outcable_w, infty, outcable_h]);
124                 // hole under the PCB
125                 translate([-pcb_len/2+pcb_groove-pcb_xoff,
126                         batt_diam/2-pcb_width + pcb_groove,
127                         -batt_diam/2-pcb_thick - 2*pcb_comp_h])
128                         cube([pcb_len-2*pcb_groove, pcb_width-2*pcb_groove,
129                                 batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
130                 // hole for prog connector
131                 translate([pcb_len/2-pcb_xoff-pcb_groove-eps,
132                         batt_diam/2-pcb_width/2-prg_width/2,
133                         -batt_diam/2-pcb_thick - 2*pcb_comp_h])
134                         difference() {
135                                 cube([prg_len+pcb_groove+eps, prg_width,
136                                         batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
137                                 translate([prg_len/2+pcb_groove, -eps, pcb_comp_h])
138                                         cube([prg_len/2+eps, prg_width+2*eps, pcb_thick]);
139                         };
140                 // LED hole
141                 translate([0, batt_diam/2-pcb_width/2, -infty/2]) {
142                         cylinder(r=led_diam/2, h=infty, $fn=6);
143                         translate([sw_xoff, 0, 0])
144                                 cylinder(r=sw_diam/2, h=infty, $fn=6);
145                         translate([-sw_xoff, 0, 0])
146                                 cylinder(r=sw_diam/2, h=infty, $fn=6);
147                 };
148                 // space under the wire holes for battery contacts
149                 translate([-batt_len/2-2*wall-cable_sep-eps, 0, 0])
150                         difference() {
151                                 rotate([0, 90, 0])
152                                         cylinder(r = batt_diam/2-wall, h = batt_len + 4*wall + 2*cable_sep + 2*eps);
153                                 translate([-infty/2, -infty/2, -batt_end_h])
154                                         cube(infty);
155                         };
156                 // space above the wire holes for battery contacts
157                 translate([-batt_len/2-2*wall-cable_sep-eps, -batt_diam/2, batt_end_h])
158                         cube([batt_len + 4*wall + 2*cable_sep + 2*eps, 
159                                 batt_diam,
160                                 batt_end_h]);
161                 // wire holes for battery contacts
162                 for (x = [-1, 1])
163                 for (y = [-1, 1])
164                         translate([-batt_len/2-wall-eps, x*wire_sep/2, y*wire_sep/2])
165                         rotate([0, 90, 0])
166                                 cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
167                 // wire hole from PCB to battery contacts
168                 // translate([-batt_len/2-wall-eps, 0, -batt_diam/2-pcb_comp_h + wire_thick/2])
169                 rotate([40, 0, 0])
170                 translate([-batt_len/2-wall-eps, 0, -batt_diam/2 - wall/2 - wire_thick/2])
171                         rotate([0, 90, 0])
172                                 cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
173                 // hole behind the battery contacts
174                 for(x=[1, -1])
175                 scale([x, 1, 1]) translate([batt_len/2+wall+cable_sep, 0, 0]) hull() {
176                         translate([0, -batt_diam/2, 0])
177                                 cube([wall + eps, batt_diam, infty]);
178                         rotate([0, 90, 0])
179                                 cylinder(r = batt_diam/2, h = wall+eps);
180                         translate([0, batt_diam/2 - pcb_width,
181                                 -batt_diam/2-pcb_comp_h-pcb_thick])
182                                 cube([wall + eps, pcb_width, eps]);
183                         translate([0, batt_diam/2 - pcb_width + 0.5*wall,
184                                 -batt_diam/2-2*pcb_comp_h-pcb_thick])
185                                 cube([wall + eps, pcb_width-0.5*wall, eps]);
186                 };
187                 // inner hole behind the battery contacts
188                 for(x=[1, -1])
189                 scale([x, 1, 1]) translate([batt_len/2+wall, 0, 0]) hull() {
190                         translate([0, -batt_diam/2+wall, 0])
191                                 cube([cable_sep + eps, batt_diam-2*wall, infty]);
192                         rotate([0, 90, 0])
193                                 cylinder(r = batt_diam/2-wall, h = cable_sep+eps);
194                 };
195                 // cable lead to battery contacts
196                 for (x=[1, -1]) scale([x, 1, 1])
197                         rotate([-140, 0, 0])
198                         translate([batt_len/2-eps, -wire_thick/2, batt_diam/2-2.7])
199                                 cube([wall+cable_sep+2*eps, wire_thick, 5.4]);
200                 
201                 // mounting holes
202                 for(x=[-1,1]) scale([x, 1, 1])
203                 translate([batt_len/2-mounthole_w/2, batt_diam/2+wall+mounthole_h/2, -infty/2])
204                         scale([1, mounthole_h/mounthole_w, 1])
205                         cylinder(r = mounthole_w/2, h = infty);
206                 // grabbing gap
207                 for(x=[-1,1]) scale([x, 1, 1])
208                 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])
209                         cylinder(r1 = 10, r2 = 10 - wall, h = wall + 2*eps);
210                 // plus sign - vertical line
211                 translate([batt_len/2 - 1.5*wall-plus_width/2, -plus_width/2, -batt_diam/2-wall])
212                         cube([wall, plus_width, infty]);
213                 // plus and minus signs - horizontal line
214                 for(x=[-1,1]) scale([x, 1, 1])
215                 translate([batt_len/2 - wall - plus_width, -wall/2, -batt_diam/2-wall])
216                         cube([plus_width, wall, infty]);
217         };
218         // clip barrier
219         for (x = [-1, 1]) scale([x, 1, 1]) hull () {
220                 translate([batt_len/2+wall+cable_sep-eps, batt_diam/2-pcb_width+wall/2+lid_sep,
221                         -batt_diam/2-pcb_thick-pcb_comp_h + wall + lid_sep])
222                         cube([wall+eps, pcb_width-2*wall-2*lid_sep, wall]);
223                 translate([batt_len/2+wall+cable_sep-eps, batt_diam/2-pcb_width+3*wall/2+lid_sep,
224                         -batt_diam/2-pcb_thick-pcb_comp_h + 3*wall + lid_sep])
225                         cube([eps, pcb_width-4*wall-2*lid_sep, eps]);
226         };
227 };
228
229 module lid_body() {
230         translate([-batt_len/2 - wall - cable_sep - lid_sep, -batt_diam/2+lid_sep, -batt_diam/2 -wall])
231                 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]);
232         hull () {
233                 translate([-batt_len/2 - 2*wall - cable_sep,
234                         -batt_diam/2, -batt_diam/2-wall])
235                         cube([batt_len + 4*wall + 2*cable_sep,
236                                 batt_diam, eps]);
237                 translate([-batt_len/2 - 3*wall - cable_sep,
238                         -batt_diam/2 - wall, -body_top_h-wall/2-lid_sep])
239                         cube([batt_len + 6*wall + 2*cable_sep,
240                                 batt_diam + 2*wall, wall/2]);
241         };
242         // clip behind the battery contacts
243         for(x=[1, -1])
244                 scale([x, 1, 1]) translate([batt_len/2+wall+cable_sep+lid_sep, 0, 0]) hull() {
245                         translate([0, -batt_diam/2+lid_sep, -batt_diam/2])
246                                 cube([wall-lid_sep, batt_diam-2*lid_sep, eps]);
247                         rotate([0, 90, 0])
248                                 cylinder(r = batt_diam/2-lid_sep, h = wall-lid_sep);
249                         translate([-clip_pretension, batt_diam/2 - pcb_width + 0.5*wall + lid_sep,
250                                 batt_diam/2+2*pcb_comp_h+pcb_thick-lid_sep])
251                                 cube([wall+clip_pretension, pcb_width-0.5*wall-1.5*lid_sep, eps]);
252                 };
253         // outer part of the clip behind the battery contacts
254         for (x=[1, -1]) scale([x, 1, 1]) translate([batt_len/2+2*wall+cable_sep+lid_sep, 0, 0]) hull() {
255                 translate([0, -batt_diam/2 - wall, -body_top_h-wall/2-lid_sep])
256                         cube([wall-lid_sep, batt_diam + 2*wall, wall/2]);
257                 difference() {
258                         scale([0.3, 1, 1])
259                                 sphere(batt_diam/2+wall);
260                         translate([-infty/2, -infty/2, -infty-body_top_h-lid_sep+2*wall])
261                                 cube(infty);
262                         translate([-infty-clip_pretension, -infty/2, -infty/2])
263                                 cube(infty);
264                 };
265                 translate([-clip_pretension,
266                         batt_diam/2 - pcb_width,
267                         batt_diam/2+2*pcb_comp_h+pcb_thick+wall])
268                         cube([wall-lid_sep, pcb_width+wall, eps]);
269         };
270 };
271
272 module lid() {
273         difference() {
274                 lid_body();
275                 translate([-batt_len/2+eps, 0, 0]) rotate([0, 90, 0])
276                         cylinder(r=batt_diam/2, h=batt_len-2*eps);
277         // clip barrier
278         for (x = [-1, 1]) scale([x, 1, 1]) hull () {
279                 translate([batt_len/2+wall+cable_sep-clip_pretension, batt_diam/2-pcb_width+wall/2,
280                         batt_diam/2+pcb_thick+pcb_comp_h-2*wall])
281                         cube([wall+clip_pretension+eps, pcb_width-2*wall, wall]);
282                 translate([batt_len/2+wall+cable_sep-eps, batt_diam/2-pcb_width+wall/2,
283                         batt_diam/2+pcb_thick+pcb_comp_h-4*wall + lid_sep])
284                         cube([eps, pcb_width-2*wall, eps]);
285         };
286 /*
287                 hull() {
288                         difference() {
289                                 translate([-batt_len/2-cable_sep-wall, 0, 0]) rotate([0, 90, 0])
290                                         cylinder(r=batt_diam/2-wall-lid_sep, h=batt_len+2*wall+2*cable_sep);
291                                 translate([-infty/2, -batt_diam/2, -infty-wire_sep/2-wire_thick/2])
292                                         cube([infty, batt_diam, infty]);
293                         };
294                         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])
295                         cube([batt_len + 2*wall + 2* cable_sep, pcb_width-1.5*wall-1.5*lid_sep, eps]);
296                 };
297 */
298         };
299 };
300
301 if (lowres) {
302         translate([0, 15, 0]) case();
303         translate([0, -15, 0]) rotate([180, 0, 0]) lid();
304 } else {
305         translate([0, 15, batt_diam/2+pcb_thick+2*pcb_comp_h+wall])
306                 case($fn=128);
307         translate([0, -15, batt_diam/2+wall])
308                 lid($fn=128);
309 }
310