e4acfcb8313a0df44c1b116dc14586a280b7a10e
[heater.git] / case.scad
1 /* TODO
2    - nabeh zaklapavaciho hranolu by mel byt zkoseny
3    - vystup pro kabel leze do vystupu pro snuru pri vetsim wall
4    - diry pro uchyceni jsou mozna prilis male
5 */
6 lowres = 1; // fast rendering or fine printing with print-friendly orientation
7
8 eps = 0.01;
9 infty = 300;
10
11 wall = 2.0; // generic wall thickness
12
13 // 18650 is ~18mm diameter, ~65mm length, 
14 batt_diam = 18 + 0.6;
15 batt_len = 65 + 1.5;
16
17 cable_sep = 2;
18
19 // front flat area
20 front_flat_len = batt_len + 4*wall + 2*cable_sep;
21
22 // PCB-related dimensions
23 pcb_len = 36 + 1;       // length of the board
24 pcb_width = 11 + 0.5;   // width of the board
25 pcb_thick = 1.2 + 0.3;  // thickness of the board
26 pcb_comp_h = 2.2;       // height of the components on board
27 pcb_groove = 1;
28
29 body_top_h = 0.35 * batt_diam; // cube-shaped part of the body
30
31 outwire_thick = 2.2;
32 wire_thick = 2.2;
33 wire_sep = 3.5;
34 cable_out_diam = 5.2;
35
36 batt_end_h = wire_sep/2 + wire_thick/2 + 1.5;;
37
38 lid_sep = 0.1; // the lid is made this much smaller to separate from the body
39
40 sw_diam = 2.5 + 0.5;
41 led_diam = 3 + 0.5;
42 sw_xoff =  250 * 25.4/1000; // x offset of microswitches
43 pcb_xoff = 90 * 25.4/1000; // offset of the LED from the middle of the PCB
44
45 prg_len = 10; // programming connector
46 prg_width = 7;
47
48 rear_clip_hole_dist = 10; // distance between the holes in the rear clip
49 rear_clip_aspect = 0.35; // w/h aspect ratio of the ellipse of the rear clip
50
51 module case_body() {
52         hull() {
53                 translate([-batt_len/2-2*wall-cable_sep, -batt_diam/2-wall, 0])
54                         cube([batt_len + 4*wall + 2*cable_sep,
55                                 batt_diam+2*wall, body_top_h]);
56                 difference() {
57                         translate([-batt_len/2-2*wall-cable_sep, 0, 0])
58                                 rotate([0, 90, 0])
59                                 cylinder(r=batt_diam/2+wall,
60                                         h = batt_len + 4*wall + 2*cable_sep);
61                         translate([-infty/2, -infty/2, eps]) cube(infty);
62                 };
63                 translate([-front_flat_len/2,
64                         batt_diam/2 - pcb_width,
65                         -batt_diam/2-2*pcb_comp_h-pcb_thick-wall])
66                         cube([front_flat_len, pcb_width+wall, eps]);
67         };
68         for (x = [-1, 1]) scale([x, 1, 1]) hull() {
69                 for (x0 = [0-wall, 10+wall])
70                         translate([batt_len/2-wall-wire_thick-x0, batt_diam/2, 0])
71                                 rotate([-90, 0, 0]) scale([rear_clip_aspect, 1, 1])
72                                 cylinder(r=batt_diam/2 + 2*wall + wire_thick, h=wall);
73                 };
74 };
75
76 module case() {
77         difference() {
78                 case_body();
79                 // upper cube-shaped part
80                 // rotate([20, 0, 0])
81                 translate([-batt_len/2, -batt_diam/2, 0])
82                         cube([batt_len, batt_diam, batt_diam]);
83
84                 // battery cylinder for the lower part
85                 translate([-batt_len/2, 0, 0])
86                         rotate([0, 90, 0])
87                         cylinder(r=batt_diam/2, h = batt_len);
88
89                 // hole for PCB
90                 translate([-pcb_len/2-pcb_xoff,
91                         batt_diam/2-pcb_width,
92                         -batt_diam/2-pcb_thick - pcb_comp_h])
93                         cube([pcb_len, pcb_width,
94                                 batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
95                 // hole above the PCB
96                 translate([-pcb_len/2-pcb_xoff-wall-2*outwire_thick,
97                         batt_diam/2-pcb_width,
98                         -batt_diam/2-pcb_comp_h])
99                         cube([pcb_len, pcb_width,
100                                 batt_diam/2 + pcb_comp_h + eps]);
101                 // hole under the PCB
102                 translate([-pcb_len/2+pcb_groove-pcb_xoff,
103                         batt_diam/2-pcb_width + pcb_groove,
104                         -batt_diam/2-pcb_thick - 2*pcb_comp_h])
105                         cube([pcb_len-2*pcb_groove, pcb_width-2*pcb_groove,
106                                 batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
107                 // hole for prog connector
108                 translate([pcb_len/2-pcb_xoff-pcb_groove-eps,
109                         batt_diam/2-pcb_width/2-prg_width/2,
110                         -batt_diam/2-pcb_thick - 2*pcb_comp_h])
111                         difference() {
112                                 cube([prg_len+pcb_groove+eps, prg_width,
113                                         batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
114                                 translate([prg_len/2+pcb_groove, -eps, pcb_comp_h])
115                                         cube([prg_len/2+eps, prg_width+2*eps, pcb_thick]);
116                         };
117                 // LED hole
118                 translate([0, batt_diam/2-pcb_width/2, -infty/2]) {
119                         cylinder(r=led_diam/2, h=infty, $fn=6);
120                         translate([sw_xoff, 0, 0])
121                                 cylinder(r=sw_diam/2, h=infty, $fn=6);
122                         translate([-sw_xoff, 0, 0])
123                                 cylinder(r=sw_diam/2, h=infty, $fn=6);
124                 };
125                 // cable outlet
126                 translate([-pcb_xoff-pcb_len/2-outwire_thick-wall, -6, 0])
127                         rotate([40, 0, 0])
128                         scale([2, 1, -1])
129                         cylinder(r=outwire_thick/2, h = infty, $fn=12);
130                 // space under the wire holes for battery contacts
131                 translate([-batt_len/2-2*wall-cable_sep-eps, 0, 0])
132                         difference() {
133                                 rotate([0, 90, 0])
134                                         cylinder(r = batt_diam/2-wall, h = batt_len + 4*wall + 2*cable_sep + 2*eps);
135                                 translate([-infty/2, -infty/2, -batt_end_h])
136                                         cube(infty);
137                         };
138                 // space above the wire holes for battery contacts
139                 translate([-batt_len/2-2*wall-cable_sep-eps, -batt_diam/2, batt_end_h])
140                         cube([batt_len + 4*wall + 2*cable_sep + 2*eps, 
141                                 batt_diam,
142                                 batt_end_h]);
143                 // wire holes for battery contacts
144                 for (x = [-1, 1])
145                 for (y = [-1, 1])
146                         translate([-batt_len/2-wall-eps, x*wire_sep/2, y*wire_sep/2])
147                         rotate([0, 90, 0])
148                                 cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
149                 // wire hole from PCB to battery contacts
150                 // translate([-batt_len/2-wall-eps, 0, -batt_diam/2-pcb_comp_h + wire_thick/2])
151                 rotate([40, 0, 0])
152                 translate([-batt_len/2-wall-eps, 0, -batt_diam/2 - wall/2 - wire_thick/2])
153                         rotate([0, 90, 0])
154                                 cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
155                 // hole behind the battery contacts
156                 for(x=[1, -1])
157                 scale([x, 1, 1]) translate([batt_len/2+wall, 0, 0]) hull() {
158                         translate([0, -batt_diam/2, 0])
159                                 cube([wall + cable_sep + eps, batt_diam, infty]);
160                         rotate([0, 90, 0])
161                                 cylinder(r = batt_diam/2, h = wall+cable_sep+eps);
162                         translate([0, batt_diam/2 - pcb_width,
163                                 -batt_diam/2-pcb_comp_h-pcb_thick])
164                                 cube([wall + cable_sep + eps, pcb_width, eps]);
165                         translate([cable_sep, batt_diam/2 - pcb_width + wall,
166                                 -batt_diam/2-pcb_comp_h-pcb_thick-wall])
167                                 cube([wall + eps, pcb_width-2*wall, eps]);
168                 };
169                 // cable lead to battery contacts
170                 for (x=[1, -1]) scale([x, 1, 1])
171                         rotate([-140, 0, 0])
172                         translate([batt_len/2+wire_thick/2, 0, batt_diam/2-2.7])
173                                 cylinder(r=wire_thick/2, h = 5.4);
174                 
175                 // mounting holes
176                 for(x=[-1,1]) scale([x, 1, 1])
177                 translate([batt_len/2-wall-wire_thick, batt_diam/2+2*wall, -batt_diam/2-pcb_thick-2*pcb_comp_h-wall])
178                         vert_torus();
179                         
180                 for (x = [-1, 1]) scale([x, 1, 1]) for (x0 = [0, 10])
181                         translate([batt_len/2-wall-wire_thick-x0, 0, batt_diam/2+wire_thick/2+wall])
182                         rotate([-90, 0, 0])
183                         scale([2,1,1]) cylinder (r=wire_thick/2, h=infty, $fn=16);
184         };
185         // clip barrier
186         for (x = [-1, 1]) scale([x, 1, 1])
187                 translate([batt_len/2+wall-eps, batt_diam/2-pcb_width+wall/2+lid_sep,
188                         -batt_diam/2-pcb_thick-pcb_comp_h + wall + lid_sep])
189                         cube([cable_sep+eps, pcb_width-2*wall-2*lid_sep, wall]);
190 };
191
192 module lid_body() {
193         translate([-batt_len/2 - wall - lid_sep, -batt_diam/2+lid_sep, -batt_diam/2 -wall])
194                 cube([batt_len + 2*wall + 2*lid_sep, batt_diam-2*lid_sep, batt_diam/2 - batt_end_h + wall - lid_sep]);
195         translate([-batt_len/2 - 2*wall - cable_sep, -batt_diam/2 - wall,
196                 -batt_diam/2-wall])
197                 cube([batt_len + 4*wall + 2*cable_sep, batt_diam + 2*wall,
198                         wall + batt_diam/2 - body_top_h - lid_sep]);
199         // clip behind the battery contacts
200         for(x=[1, -1])
201                 scale([x, 1, 1]) translate([batt_len/2+wall+lid_sep, 0, 0]) hull() {
202                         translate([0, -batt_diam/2+lid_sep, -batt_diam/2])
203                                 cube([wall+cable_sep-lid_sep, batt_diam-2*lid_sep, eps]);
204                         rotate([0, 90, 0])
205                                 cylinder(r = batt_diam/2-lid_sep, h = wall+cable_sep-lid_sep);
206                         translate([0, batt_diam/2 - pcb_width+lid_sep,
207                                 batt_diam/2+pcb_comp_h+pcb_thick-lid_sep])
208                                 cube([wall+cable_sep-lid_sep, pcb_width-2*lid_sep, eps]);
209                         translate([cable_sep+wall/2, batt_diam/2 - pcb_width + 1.5*wall +lid_sep,
210                                 batt_diam/2+pcb_comp_h+pcb_thick+wall/2-lid_sep])
211                                 cube([wall/2-lid_sep, pcb_width-2*wall-2*lid_sep, eps]);
212                         // rear cone
213                         translate([cable_sep+wall-lid_sep, 0, -batt_diam/2-wall]) difference() {
214                                 scale([0.5, 1, 1])
215                                 cylinder(r = batt_diam/2 - lid_sep,  h = eps);
216                                 translate([-infty, -infty/2, -infty/2]) cube(infty);
217                         };
218                 };
219 };
220
221 module lid() {
222         difference() {
223                 lid_body();
224                 translate([-batt_len/2+eps, 0, 0]) rotate([0, 90, 0])
225                         cylinder(r=batt_diam/2, h=batt_len-2*eps);
226                 hull() {
227                         difference() {
228                                 translate([-batt_len/2-cable_sep-wall, 0, 0]) rotate([0, 90, 0])
229                                         cylinder(r=batt_diam/2-wall-lid_sep, h=batt_len+2*wall+2*cable_sep);
230                                 translate([-infty/2, -batt_diam/2, -infty-wire_sep/2-wire_thick/2])
231                                         cube([infty, batt_diam, infty]);
232                         };
233                         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])
234                         cube([batt_len + 2*wall + 2* cable_sep, pcb_width-1.5*wall-1.5*lid_sep, eps]);
235                 };
236                 // holes for the mounting clips on the body
237                 for (x = [-1, 1]) scale([x, 1, 1]) hull() {
238                 for (x0 = [0-wall, 10+wall])
239                         translate([batt_len/2-wall-wire_thick-x0, batt_diam/2-lid_sep+eps, 0])
240                                 rotate([-90, 0, 0]) scale([rear_clip_aspect, 1, 1])
241                                 cylinder(r=batt_diam/2 + 2*wall + wire_thick+lid_sep/rear_clip_aspect, h=wall+lid_sep+eps);
242                 };
243         };
244 };
245
246 module vert_torus() {
247         rotate([0, 90, 0])
248         scale([1, 1, 2])
249         rotate_extrude() translate([5, 0, 0]) circle(r=wire_thick/2, $fn=16);
250 };
251
252 if (lowres) {
253         translate([0, 15, 0]) case();
254         translate([0, -15, 0]) rotate([180, 0, 0]) lid();
255 } else {
256         translate([0, 15, batt_diam/2+pcb_thick+2*pcb_comp_h+wall])
257                 case($fn=128);
258         translate([0, -15, batt_diam/2+wall])
259                 lid($fn=128);
260 }
261