case.scad: both parts of the case
[heater.git] / case.scad
1 // 18650 is ~18mm diameter, ~65mm length, 
2 batt_diam = 18 + 0.3;
3 batt_len = 65+1;
4 batt_clip_h = 0.75 * batt_diam;
5 wall = 2.2;
6 base_h = 4;
7 cable_sep = 2.5;
8
9 eps = 0.01;
10 infty = 300;
11
12 pcb_len = 36;
13 pcb_thick = 1.3;
14 pcb_groove = 2;
15 pcb_width = 11;
16
17 wire_thick = 2;
18 wire_sep = 3;
19 cable_out_diam = 4;
20
21 side_protrusion_len = 10;
22 side_protrusion_diam = 2;
23
24 base_batt_extend = wall+pcb_thick; // extend the base on the battery side
25
26 cover_sep = 0.2;
27
28 uswitch_diam = 2.5;
29 led_diam = 3.2;
30 s2_xoff = -160 * 25.4/1000;
31 led_xoff = 90 * 25.4/1000;
32 s1_xoff = 340 * 25.4/1000;
33
34 pcb_clip_w = 7;
35 pcb_clip_off = led_xoff + pcb_clip_w/2;
36
37 module base() {
38         translate([0, 0, base_h/2]) {
39                 hull() {
40                         cube([batt_len + 2*wall + 2*cable_sep, batt_diam + 2*wall, base_h], center=true);
41                         // under the PCB
42                         translate([0, -batt_diam/2-wall-pcb_thick/2-wall/2, 0])
43                                 cube([pcb_len + 2*wall, pcb_thick + wall + eps, base_h], center=true);
44                         // battery-side extension
45                         translate([0, batt_diam/2 + wall + base_batt_extend, -base_h/4+side_protrusion_diam/4])
46                                 cube([batt_len + 2*wall, eps, base_h/2+side_protrusion_diam/2], center=true);
47                 };
48         };
49 }
50 module base_protrusions() {
51         // pcb-side side protrusion
52         translate([-side_protrusion_len/2, -batt_diam/2-2*wall-pcb_thick, base_h/2])
53                 rotate([0, 90, 0])
54                 cylinder(r = side_protrusion_diam/2, h = side_protrusion_len, $fn = 6);
55         
56         // battery-side side protrusion
57         translate([-side_protrusion_len/2, batt_diam/2+wall+base_batt_extend, base_h/2])
58                 rotate([0, 90, 0])
59                 cylinder(r = side_protrusion_diam/2, h = side_protrusion_len, $fn = 6);
60 };
61
62 module pcb_clips() {
63         // rear part of the PCB holder (behind S1)
64         translate([pcb_clip_off, -batt_diam/2-wall-pcb_thick+eps, 0])
65                 cube([pcb_clip_w, pcb_thick+wall, pcb_width + wall + base_h - pcb_groove]);
66         // side part of the PCB holder (near the battery wires)
67         translate([-pcb_len/2-wall, -batt_diam/2-pcb_thick-2*wall, 0])
68                 cube([pcb_groove+wall, pcb_thick+2*wall+eps, pcb_width + wall + base_h - pcb_groove]);
69 };
70
71 module batt_clips() {
72         difference() {
73                 union() {
74                         // rear part of the battery clip
75                         translate([-(batt_len/2-pcb_len/2+pcb_groove+wall)/2-pcb_len/2+pcb_groove, 0, batt_clip_h/2+wall/2])
76                                 cube([batt_len/2-pcb_len/2+pcb_groove + wall, batt_diam + 2*wall, batt_clip_h + wall], center=true);
77                         // front (+) part of the battery clip
78                         translate([batt_len/2+wall/2, 0, batt_clip_h/2+wall/2])
79                                 hull() {
80                                         cube([wall, batt_diam + 2*wall, batt_clip_h + wall], center=true); 
81                                         translate([-10/2, 0, -batt_clip_h/2])
82                                         cube([10, batt_diam+2*wall, wall], center=true);
83                                 };
84                         // middle clips
85                         translate([pcb_clip_off+pcb_clip_w/2, 0, batt_clip_h/2+wall/2])
86                                 hull() {
87                                         cube([pcb_clip_w, batt_diam + 2*wall, batt_clip_h + wall], center=true);
88                                         translate([0, 0, -batt_clip_h/2])
89                                         cube([2*pcb_clip_w, batt_diam+2*wall, wall], center=true);
90                                 };
91                 }
92                 // top part rounded
93                 difference() {
94                         translate([0, 0, infty/4 + wall + batt_diam/2])
95                                 cube([infty/2, infty/2, infty/2], center=true);
96                         translate([-infty/2, 0, batt_diam/2+wall])
97                                 rotate([0, 90, 0])
98                                 cylinder(r=batt_diam/2+wall, h = infty);
99                 };
100         };
101 };
102
103 module battery() {
104         // battery
105         translate([-batt_len/2, 0, batt_diam/2+wall])
106                 rotate([0, 90, 0])
107                 cylinder(r=batt_diam/2, h = batt_len);
108 };
109
110 module main() {
111         difference() {
112                 union() {
113                         base();
114                         base_protrusions();
115                         pcb_clips();
116                         batt_clips();
117                 };
118                 // the PCB itself
119                 translate([0, -batt_diam/2-wall-pcb_thick/2, base_h - pcb_groove + pcb_width/2])
120                         cube([pcb_len, pcb_thick, pcb_width], center=true);
121                 // battery
122                 battery();
123                 // 4 wire holes at the battery ends
124                 for (j=[-wire_sep/2, wire_sep/2]) 
125                 for (i=[-wire_sep/2, wire_sep/2]) 
126                 translate([-infty/2, i, batt_diam/2 + wall+j])
127                         rotate([0, 90, 0])
128                         rotate([0, 0, 90])
129                         cylinder(r=wire_thick/2, h = infty, $fn=6);
130
131                 // holes for wire from battery to the PCB
132                 translate([-infty/2, -batt_diam/2, wall + pcb_groove + wire_thick/2])
133                         rotate([0, 90, 0])
134                         rotate([0, 0, 90])
135                         cylinder(r=wire_thick/2, h = infty, $fn=6);
136                 // hole for the cable outlet
137                 translate([-pcb_len/2+pcb_groove+cable_out_diam/2, -batt_diam/2-pcb_thick-2*wall, -infty/2])
138                         cylinder(r=cable_out_diam/2, h = infty, $fn=6);
139                 // holes for binding to the shoe
140                 for (x = [
141                          pcb_len/2 + wall + wire_thick/2 + wire_sep,
142                          pcb_len/2 + wall + wire_thick/2,
143                         -pcb_len/2 - wall - wire_thick/2 - wire_sep,,
144                         -pcb_len/2 - wall - wire_thick/2 ]) {
145                         for (y = [-1,1]) {
146                                 translate([x, y*(batt_diam/2 + wall + wire_thick/2), -infty/2])
147                                         cylinder(r=wire_thick/2, h=infty, $fn=6);
148                         };
149                 };
150         };
151 };
152
153 module cover_internal() {
154         hull() { 
155                 base();
156                 // battery + wall + cable space
157                 translate([-batt_len/2-wall, 0, batt_diam/2+wall])
158                         rotate([0, 90, 0])
159                         cylinder(r=batt_diam/2+wall, h = batt_len + 2*wall);
160                 // space for PCB
161                 translate([-pcb_len/2-wall, -batt_diam/2-2*wall-pcb_thick, base_h-pcb_groove])
162                         cube([pcb_len+2*wall, wall+pcb_thick, pcb_width+wall]);
163         };
164 };
165
166 module cover_hole() {
167         difference() {
168                 cover_internal();
169                 translate([-infty/2, -infty/2, wall + batt_clip_h])
170                         cube(infty);
171         };
172         base_protrusions();
173         // battery();
174         translate([-batt_len/2-cable_sep, 0, batt_diam/2+wall])
175                 rotate([0, 90, 0])
176                 cylinder(r=batt_diam/2, h = batt_len + 2*cable_sep);
177 };
178
179 module cover() {
180         difference() {
181                 minkowski() {
182                         cover_internal();
183                         sphere(wall+cover_sep, $fn=16);
184                 }
185                 minkowski() {
186                         cover_hole();
187                         sphere(cover_sep, $fn=8);
188                 };
189                 // s2 hole
190                 translate([s2_xoff, 0, base_h-pcb_groove + pcb_width/2])
191                         rotate([90, 0, 0])
192                         cylinder(r=uswitch_diam/2, h = infty, $fn=6);
193                 // LED hole
194                 translate([led_xoff, 0, base_h-pcb_groove + pcb_width/2])
195                         rotate([90, 0, 0])
196                         cylinder(r=led_diam/2, h = infty, $fn=6);
197                 // s1 hole
198                 translate([s1_xoff, 0, base_h-pcb_groove + pcb_width/2])
199                         rotate([90, 0, 0])
200                         cylinder(r=uswitch_diam/2, h = infty, $fn=6);
201                 // xy plane
202                 translate([0, 0, -infty/2]) cube(infty, center=true);
203         }
204 };
205
206 translate([0, -19, 0])
207         main($fn=128);
208
209 // translate([0, -40, 0])
210 //      cover_hole();
211
212 // cover($fn=128);
213 // translate([0, 17, batt_diam + 3*wall + cover_sep])
214 // rotate([180, 0, 0])
215 //      cover($fn=128);
216
217 translate([0, 19, 0])
218         cover($fn=128);