]> www.fi.muni.cz Git - things.git/blob - battery-1.scad
switch holder.scad
[things.git] / battery-1.scad
1 eps = 0.01;
2 infty = 200;
3
4 // 2x 10180
5 // batt_d_real = 10;
6 // batt_l = 36 + 0.5;
7
8 // 2x 18650 side by side
9 batt_d_real = 18;
10 batt_l = 65 + 1.5;
11
12 batt_sep = 0.65;
13
14 wall = 1;
15
16 batt_d = batt_d_real + batt_sep;
17
18 wire_sep = 1.5;
19 wire_w = 3;
20 wire_h = 1.5;
21
22 body_h = 0.8*batt_d_real;
23 cyl_center_h = batt_l/3;
24
25 // z-offset from the widest point of the battery to the widest
26 // point of the clip
27 top_clip_h = 0.25*batt_d;
28
29 spring_sep = 0.7;
30 // outer part of the spring
31 d_out = batt_d/2-spring_sep/2;
32 // inner part of the spring
33 d_in = d_out/2-wall/2-spring_sep/2; // batt_d/4-3*wall/4;
34 // straight part length
35 straight_l = batt_l + 3*wall/2 + d_out/2;
36
37 module cyl_arc(d, h, beg, end) {
38         difference() {
39                 cylinder(r = d/2+wall/2, h = h, $fn = 64);
40                 translate([0, 0, -eps])
41                         cylinder(r = d/2-wall/2, h=h+2*eps, $fn = 64);
42                 if (end-beg > 180) {
43                         intersection() {
44                                 rotate([0, 0, beg])
45                                         scale([1, -1, 1])
46                                         translate([-infty/2, 0, -eps])
47                                         cube(infty);
48                                 rotate([0, 0, end])
49                                         translate([-infty/2, 0, -eps])
50                                         cube(infty);
51                         }
52                 } else {
53                         union() {
54                                 rotate([0, 0, beg])
55                                         scale([1, -1, 1])
56                                         translate([-infty/2, 0, -eps])
57                                         cube(infty);
58                                 rotate([0, 0, end-180])
59                                         scale([1, -1, 1])
60                                         translate([-infty/2, 0, -eps])
61                                         cube(infty);
62                         }
63                 }
64         }
65 }
66
67
68 // main box
69 module main_box() {
70         difference() {
71                 translate([-batt_d/2-wall, 0, 0])
72                         cube([batt_d + 2*wall, straight_l, body_h]);
73                 // upper part at the - pole
74                 translate([-batt_d/2, wall, batt_d/2])
75                         cube([batt_d, (batt_l-cyl_center_h)/2, batt_d + 2*eps]);
76                 // the battery itself
77                 translate([0, wall, batt_d_real/2])
78                 rotate([-90, 0, 0])
79                         cylinder(r = batt_d/2, h = straight_l, $fn = 64);
80                 // upper part of the clip
81                 translate([0, wall, batt_d_real/2+2*top_clip_h])
82                 rotate([-90, 0, 0])
83                         cylinder(r = batt_d/2, h = straight_l, $fn = 64);
84                 // upper part at the + pole
85                 translate([-batt_d/2, wall+(batt_l-cyl_center_h)/2+cyl_center_h, batt_d/2])
86                         cube([batt_d, (batt_l-cyl_center_h)/2, batt_d + 2*eps]);
87                 // at the clip - sides only
88                 translate([-batt_d/2, batt_l, -eps])
89                         cube([batt_d, straight_l-batt_l+eps, batt_d + 2*eps]);
90
91         }
92 }
93
94 // spring, x-axis cenered, to be connected by y-minus axis
95 module spring() {
96         for (x = [-1, 1]) scale([x, 1, 1]) {
97                 // outmost d_out arc
98                 translate([d_out/2+wall/2+spring_sep/2, 0, 0])
99                         cyl_arc(d_out, body_h, 0-eps, 180+eps);
100                 // inner center d_in arc
101                 translate([spring_sep/2+wall/2+d_in/2, 0, 0])
102                         cyl_arc(d_in, body_h, 180, 360+eps);
103                 // outer center d_in arc
104                 translate([spring_sep/2+wall/2+3*d_in/2, 0, 0])
105                         cyl_arc(d_in, body_h, -eps, 180+eps);
106                 // innermost d_out arc
107                 translate([2*d_in+wall/2+spring_sep/2-d_out/2, 0, 0])
108                         cyl_arc(d_out, body_h, 270-eps, 360+eps);
109         }
110         // center beam
111         translate([-2*d_in-spring_sep/2-wall/2+d_out/2, -d_out/2-wall/2, 0])
112                 cube([4*d_in+spring_sep+wall-d_out, wall, body_h]);
113 }
114
115 module holder()
116 {
117         difference() {
118                 union() {
119                         main_box();
120                         translate([0, straight_l, 0])
121                                 spring();
122                 }
123
124                 for (z = [batt_d_real/2-wire_h-wire_sep/2,
125                         batt_d_real/2+wire_sep/2]) {
126                         translate([-wire_w/2, -eps, z])
127                                 cube([wire_w, batt_l+2*wall+2*eps, wire_h]);
128                 }
129         }
130 }
131
132 holder();
133 translate([batt_d+wall, straight_l + d_out/2, 0])
134 scale([1, -1, 1])
135         holder();
136