a76ae70445eaa57130250c35948053b2fd007fb4
[heater.git] / case.scad
1 /* TODO
2 - vybrani pro otevreni
3 - mozna sirsi misto na baterku?
4 - vetsi vybrani pro baterku ve vicku
5 - kuzelova dira pro tlacitka
6 - jine diry pro uchyceni
7 - zvetsit vybrani na strane tlacitek
8 - mozna prilis velky klip zasunovaciho konce baterky
9 - diry pro neizolovany drat muzou byt mensi
10 - sirsi zakladna
11 - mensi horni cast klipu baterky - pri 0.7 je sirka nahore 16 mm.
12 */
13
14 lowres = 1;
15
16 eps = 0.01;
17 infty = 300;
18
19 wall = 1.5; // generic wall thickness
20
21 // 18650 is ~18mm diameter, ~65mm length, 
22 batt_diam = 18 + 0.6;
23 batt_len = 65 + 1.5;
24
25 cable_sep = 2.5;
26
27 // front flat area
28 front_flat_len = batt_len + 2*wall + 2*cable_sep;
29
30 // PCB-related dimensions
31 pcb_len = 36 + 1;       // length of the board
32 pcb_width = 11 + 0.5;   // width of the board
33 pcb_thick = 1.2 + 0.3;  // thickness of the board
34 pcb_comp_h = 2.2;       // height of the components on board
35 pcb_groove = 0.5;
36
37 body_top_h = 0.30 * batt_diam; // cube-shaped part of the body
38
39 wire_thick = 2.2;
40 wire_sep = 3.5;
41 cable_out_diam = 5.2;
42
43 pcbside_protrusion_len = 20;
44 pcbside_protrusion_diam = 2.5;
45 battside_protrusion_len = 10;
46 battside_protrusion_diam = 2;
47
48 base_batt_extend = wall + pcb_thick; // extend the base on the battery side
49
50 cover_sep = 0.1;
51
52 sw_diam = 2.5 + 0.5;
53 led_diam = 3 + 0.5;
54 sw_xoff =  250 * 25.4/1000; // x offset of microswitches
55
56 pcb_clip_w = 7;
57 pcb_clip_off = led_xoff + pcb_clip_w/2;
58
59
60 module battery() {
61         translate([-batt_len/2, 0, 0])
62                 rotate([0, 90, 0])
63                 cylinder(r=batt_diam/2, h = batt_len);
64 };
65
66 module case_body() {
67         hull() {
68                 translate([-batt_len/2-wall-cable_sep, -batt_diam/2-wall, 0])
69                         cube([batt_len + 2*wall + 2*cable_sep,
70                                 batt_diam+2*wall, body_top_h]);
71                 difference() {
72                         translate([-batt_len/2-wall-cable_sep, 0, 0])
73                                 rotate([0, 90, 0])
74                                 cylinder(r=batt_diam/2+wall,
75                                         h = batt_len + 2*wall + 2*cable_sep);
76                         translate([-infty/2, -infty/2, eps]) cube(infty);
77                 };
78                 translate([-front_flat_len/2,
79                         batt_diam/2 - pcb_width,
80                         -batt_diam/2-2*pcb_comp_h-pcb_thick-wall])
81                         cube([front_flat_len, pcb_width+wall, eps]);
82 /*
83                 translate([-batt_len/2 - 2*wall - cable_sep, 0, 0])
84                         rotate([0, 90, 0])
85                         cylinder(r = 1.414*wire_sep + wire_thick,
86                                 h = batt_len + 4*wall + 2*cable_sep);
87 */
88         };
89 };
90
91 module case() {
92         difference() {
93                 case_body();
94                 // upper cube-shaped part
95                 // rotate([20, 0, 0])
96                 translate([-batt_len/2, -batt_diam/2, 0])
97                         cube([batt_len, batt_diam, batt_diam]);
98
99                 // battery cylinder for the lower part
100                 translate([-batt_len/2, 0, 0])
101                         rotate([0, 90, 0])
102                         cylinder(r=batt_diam/2, h = batt_len);
103
104                 // hole for PCB
105                 translate([-pcb_len/2,
106                         batt_diam/2-pcb_width,
107                         -batt_diam/2-pcb_thick - pcb_comp_h])
108                         cube([pcb_len, pcb_width,
109                                 batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
110                 // hole under the PCB
111                 translate([-pcb_len/2+pcb_groove,
112                         batt_diam/2-pcb_width + pcb_groove,
113                         -batt_diam/2-pcb_thick - 2*pcb_comp_h])
114                         cube([pcb_len-2*pcb_groove, pcb_width-2*pcb_groove,
115                                 batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
116                 // LED hole
117                 translate([0, batt_diam/2-pcb_width/2, -infty/2]) {
118                         cylinder(r=led_diam/2, h=infty, $fn=6);
119                         translate([sw_xoff, 0, 0])
120                                 cylinder(r=sw_diam/2, h=infty, $fn=6);
121                         translate([-sw_xoff, 0, 0])
122                                 cylinder(r=sw_diam/2, h=infty, $fn=6);
123                 };
124                 // space under the wire holes for battery contacts
125                 translate([-batt_len/2-wall-cable_sep-eps, 0, 0])
126                         difference() {
127                                 rotate([0, 90, 0])
128                                         cylinder(r = batt_diam/2-wall, h = batt_len + 2*wall + 2*cable_sep + 2*eps);
129                                 translate([-infty/2, -infty/2, -body_top_h])
130                                         cube(infty);
131                         };
132                 // wire holes for battery contacts
133                 for (x = [-1, 1])
134                 for (y = [-1, 1])
135                         translate([-batt_len/2-wall-eps, x*wire_sep/2, y*wire_sep/2])
136                         rotate([0, 90, 0])
137                                 cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
138                 // wire hole from PCB to battery contacts
139                 // translate([-batt_len/2-wall-eps, 0, -batt_diam/2-pcb_comp_h + wire_thick/2])
140                 rotate([40, 0, 0])
141                 translate([-batt_len/2-wall-eps, 0, -batt_diam/2 - wall/2 - wire_thick/2])
142                         rotate([0, 90, 0])
143                                 cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
144                 // hole behind the battery contacts
145                 for(x=[1, -1])
146                 scale([x, 1, 1]) translate([batt_len/2+wall, 0, 0]) hull() {
147                         translate([0, -batt_diam/2, 0])
148                                 cube([cable_sep + eps, batt_diam, infty]);
149                         rotate([0, 90, 0])
150                                 cylinder(r = batt_diam/2, h = cable_sep+eps);
151                         translate([0, batt_diam/2 - pcb_width,
152                                 -batt_diam/2-pcb_comp_h-pcb_thick])
153                                 cube([cable_sep + eps, pcb_width, eps]);
154                 };
155         };
156 };
157
158 module lid_body() {
159         translate([-batt_len/2 + eps, -batt_diam/2, -batt_diam/2-eps])
160                 cube([batt_len - 2*eps, batt_diam, batt_diam/2 - body_top_h + wall + eps]);
161         translate([-batt_len/2 - wall - cable_sep, -batt_diam/2 - wall,
162                 -batt_diam/2-wall])
163                 cube([batt_len + 2*wall + 2*cable_sep, batt_diam + 2*wall,
164                         wall + batt_diam/2 - body_top_h]);
165         // clip behind the battery contacts
166         for(x=[1, -1])
167                 scale([x, 1, 1]) translate([batt_len/2+cable_sep, 0, 0]) hull() {
168                         translate([0, -batt_diam/2, -batt_diam/2])
169                                 cube([wall, batt_diam, eps]);
170                         rotate([0, 90, 0])
171                                 cylinder(r = batt_diam/2, h = wall);
172                         translate([0, batt_diam/2 - pcb_width,
173                                 batt_diam/2+pcb_comp_h+pcb_thick])
174                                 cube([wall, pcb_width, eps]);
175                 };
176 };
177
178 module lid() {
179         difference() {
180                 lid_body();
181                 translate([-batt_len/2-eps, 0, 0]) rotate([0, 90, 0])
182                         cylinder(r=batt_diam/2, h=batt_len+2*eps);
183         };
184 };
185
186 /*
187 color("lightblue", 0.2)
188         translate([-65/2, 0, 0])
189         rotate([0, 90, 0])
190         cylinder(r=18/2, h=65);
191 */
192 translate([0, 30, 0]) case($fn=128);
193 lid($fn=128);
194
195