Merge branch 'master' of /home/kas/html/git/heater
[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.38 * batt_diam; // cube-shaped part of the body
26
27 wire_thick = 2.5;
28 wire_sep = 3.5;
29
30 lid_sep = 0.2; // the lid is made this much smaller to separate from the body
31
32 // sw_diam = 2.5 + 0.5;
33 sw_diam = 3.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 batt_contact_w = 12;
56 clip_cyl_r = 1;
57 batt_end_h = body_top_h - 4*clip_cyl_r;;
58
59
60 module case_body() {
61         hull() {
62                 translate([-batt_len/2-2*wall-cable_sep, -batt_diam/2-wall, 0])
63                         cube([batt_len + 4*wall + 2*cable_sep,
64                                 batt_diam+2*wall, body_top_h]);
65                 difference() {
66                         translate([-batt_len/2-2*wall-cable_sep, 0, 0])
67                                 rotate([0, 90, 0])
68                                 cylinder(r=batt_diam/2+wall,
69                                         h = batt_len + 4*wall + 2*cable_sep);
70                         translate([-infty/2, -infty/2, eps]) cube(infty);
71                 };
72                 translate([-front_flat_len/2,
73                         batt_diam/2 - pcb_width,
74                         -batt_diam/2-pcb_comp_h-pcb_comp_h2-pcb_thick-wall])
75                         cube([front_flat_len, pcb_width+wall, eps]);
76         };
77         // mounting cylinders
78         for (x = [-1, 1]) translate([x*(batt_len/2-mounthole_w/2),
79                 batt_diam/2+wall, 0]) {
80                         translate([0, 0, -batt_diam/2-wall-pcb_comp_h-pcb_comp_h2-pcb_thick])
81                                 mount_cyl(); // front
82                         translate([0, 0, body_top_h]) // rear
83                                 scale([1, 1, -1])
84                                 mount_cyl();
85         };
86 };
87
88 module mount_cyl() {
89         assign(h = mounthole_h+wall)
90         hull () {
91                 translate([0, -mountcyl_w/2+mounthole_h + wall])
92                         cylinder(r = mountcyl_w/2, h = mountcyl_h);
93                 assign(l = 2*sqrt(h*(mountcyl_w-h)))
94                 translate([-l/2, 0, mountcyl_h + mountcone_h])
95                         cube([l, eps, eps]);
96         };
97 };
98         
99 module case() {
100         difference() {
101                 case_body();
102                 // upper cube-shaped part
103                 // rotate([20, 0, 0])
104                 translate([-batt_len/2, -batt_diam/2, 0])
105                         cube([batt_len, batt_diam, batt_diam]);
106                 // upper longer cube-shaped part
107                 difference() {
108                         translate([-batt_len/2-cable_sep-wall, -batt_diam/2, batt_end_h])
109                                 cube([batt_len+2*cable_sep+2*wall, batt_diam, batt_diam]);
110                         for (x = [-1,1]) scale([x, 1, 1])
111                                 translate([batt_len/2 + wall + cable_sep, -infty/2, batt_end_h + 3*clip_cyl_r])
112                                 rotate([-90, 0, 0])
113                                 cylinder(r = clip_cyl_r, h = infty, $fn=4);
114                 }
115                 // grabbing holes
116                 for (x=[-1,1]) scale([x,1,1])
117                 translate([batt_len/2 + 2*wall + cable_sep+10-wall, 0, 0])
118                         cylinder(r1 = 7, r2 = 10-wall/4, h = body_top_h + eps);
119                 // battery cylinder for the lower part
120                 translate([-batt_len/2, 0, 0])
121                         rotate([0, 90, 0])
122                         cylinder(r=batt_diam/2, h = batt_len);
123
124                 // hole for PCB
125                 translate([-pcb_len/2-pcb_xoff,
126                         batt_diam/2-pcb_width,
127                         -batt_diam/2-pcb_thick - pcb_comp_h])
128                         cube([pcb_len, pcb_width,
129                                 batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
130                 // hole above the PCB for the outgoing cable
131                 translate([-pcb_len/2-pcb_xoff-2*wall-outcable_w,
132                         batt_diam/2-pcb_width,
133                         -batt_diam/2-pcb_comp_h])
134                         cube([pcb_len, pcb_width,
135                                 batt_diam/2 + pcb_comp_h + eps]);
136                 // cable outlet
137                 translate([-pcb_xoff-pcb_len/2-wall-outcable_w,
138                         -pcb_width+batt_diam/2,
139                         -batt_diam/2-outcable_h])
140                         cube([outcable_w, infty, outcable_h]);
141                 // hole under the PCB (groove)
142                 translate([-pcb_len/2+pcb_groove-pcb_xoff,
143                         batt_diam/2-pcb_width + pcb_groove,
144                         -batt_diam/2-pcb_thick - pcb_comp_h - pcb_comp_h2])
145                         cube([pcb_len-2*pcb_groove, pcb_width-2*pcb_groove,
146                                 batt_diam/2 + pcb_thick + pcb_comp_h2 + eps]);
147                 // hole under the PCB (pcb-width)
148                 translate([-pcb_len/2+2*pcb_groove-pcb_xoff,
149                         batt_diam/2-pcb_width,
150                         -batt_diam/2-pcb_thick - pcb_comp_h - pcb_comp_h2])
151                         cube([pcb_len-4*pcb_groove, pcb_width,
152                                 batt_diam/2 + pcb_thick + pcb_comp_h2 + eps]);
153                 // hole for prog connector
154                 translate([pcb_len/2-pcb_xoff-pcb_groove-eps,
155                         batt_diam/2-pcb_width/2-prg_width/2,
156                         -batt_diam/2-pcb_thick - pcb_comp_h - pcb_comp_h2])
157                         difference() {
158                                 cube([prg_len+pcb_groove+eps, prg_width,
159                                         batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
160                                 translate([prg_len/2+pcb_groove, -eps, pcb_comp_h2])
161                                         cube([prg_len/2+eps, prg_width+2*eps, pcb_thick]);
162                         };
163                 // LED and button holes
164                 translate([0, batt_diam/2-pcb_width/2, -infty/2]) {
165                         cylinder(r=led_diam/2, h=infty, $fn=6);
166                         translate([sw_xoff, 0, 0])
167                                 cylinder(r=sw_diam/2, h=infty, $fn=6);
168                         translate([-sw_xoff, 0, 0])
169                                 cylinder(r=sw_diam/2, h=infty, $fn=6);
170                 };
171                 // wire hole from PCB to battery contacts
172                 rotate([-48, 0, 0])
173                 translate([-batt_len/2-wall-cable_sep, 0, -wire_thick/2-wall/2])
174                         cube([batt_len + 2*wall + 2* cable_sep, batt_diam/2 + wire_thick + wall, wire_thick]);
175                 // mounting holes
176                 for(x=[-1,1]) scale([x, 1, 1])
177                 translate([batt_len/2-mounthole_w/2, batt_diam/2+wall+mounthole_h/2, -infty/2])
178                         scale([1, mounthole_h/mounthole_w, 1])
179                         cylinder(r = mounthole_w/2, h = infty);
180                 // holes in front of battery contacts
181                 for(x=[-1,1]) scale([x, 1, 1])
182                 translate([batt_len/2-eps, wall/2-batt_contact_w/2,
183                         wall/2-batt_contact_w/2])
184                         cube([wall+2*eps, batt_contact_w-wall, infty]);
185                 // holes for battery contacts
186                 for(x=[-1,1]) scale([x, 1, 1])
187                 translate([batt_len/2+wall-eps, -batt_contact_w/2,
188                         -batt_contact_w/2])
189                         cube([cable_sep+2*eps, batt_contact_w, infty]);
190                 // internal plus sign - vertical line
191                 translate([-batt_len/2 + 0.5*wall+plus_width/2, -plus_width/2, -batt_diam/2-wall])
192                         cube([wall, plus_width, infty]);
193                 // internal plus and minus signs - horizontal line
194                 for(x=[-1,1]) scale([x, 1, 1])
195                 translate([batt_len/2 - wall - plus_width, -wall/2, -batt_diam/2-wall])
196                         cube([plus_width, wall, infty]);
197                 // button + label
198                 scale([-1, 1, 1])
199                 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])
200                         cube([wall, plus_width, wall/2]);
201                 // button +/- label - horizontal line
202                 for (x=[-1, 1]) scale([x, 1, 1])
203                 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])
204                         cube([plus_width, wall, wall/2]);
205                 // rounded top
206                 for (x=[-1, 1]) scale([x, 1, 1])
207                 translate([batt_len/2 + wall + cable_sep, -infty/2, body_top_h - 2*wall])
208                 rotate([-90, 0, 0])
209                         scale([1, -2, 1])
210                         difference() {
211                                 cube([wall+eps, wall+eps, infty]);
212                                 translate([0, 0, -eps])
213                                 cylinder(r=wall, h=infty+2*eps);
214                         }
215         };
216 };
217
218 module lid_body() {
219         // outer part
220         hull() {
221                 // smaller outermost part
222                 translate([-batt_len/2 - wall - cable_sep, -batt_diam/2, -batt_diam/2 - wall])
223                         cube([batt_len + 2*wall + 2*cable_sep, batt_diam, eps]);
224                 // this part goes above the main body
225                 translate([-batt_len/2 - 2*wall - cable_sep, -batt_diam/2-wall, -body_top_h - lid_sep])
226                         cube([batt_len + 4*wall + 2*cable_sep, batt_diam+2*wall, eps]);
227         };
228         // the part which goes inside the main body
229         translate([-batt_len/2 - wall - cable_sep + lid_sep, -batt_diam/2+lid_sep, -batt_diam/2 -wall])
230                 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]);
231         // clips
232         for (x = [-1, 1]) scale([x, 1, 1])
233         translate([batt_len/2 + wall + cable_sep - lid_sep, batt_diam/2 - lid_sep, -batt_end_h-lid_sep-clip_cyl_r])
234                 rotate([90, 0, 0])
235                 cylinder(r = clip_cyl_r, h = batt_diam-2*lid_sep, $fn = 4);
236 }
237
238 module lid() {
239         difference() {
240                 lid_body();
241                 translate([-batt_len/2-lid_sep, 0, 0]) rotate([0, 90, 0])
242                         cylinder(r=batt_diam/2 + lid_sep, h=batt_len+2*lid_sep);
243         };
244 };
245
246 if (lowres) {
247         translate([0, 15, 0]) case();
248         translate([0, -15, 0]) rotate([180, 0, 0]) lid();
249 } else {
250         translate([0, 15, batt_diam/2+pcb_thick+pcb_comp_h+pcb_comp_h2+wall])
251                 case($fn=128);
252         translate([0, -15, batt_diam/2+wall])
253                 lid($fn=128);
254 }
255