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