forked from nophead/NopSCADlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattery.scad
161 lines (137 loc) · 5.99 KB
/
battery.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//
// NopSCADlib Copyright Chris Palmer 2018
// nop.head@gmail.com
// hydraraptor.blogspot.com
//
// This file is part of NopSCADlib.
//
// NopSCADlib is free software: you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// NopSCADlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with NopSCADlib.
// If not, see <https://www.gnu.org/licenses/>.
//
//
//! Actually just single cells at the moment, shown here with mating contacts in place.
//!
//! Note that the [Lumintop LM34](http://www.lumintop.com/lm34c-usb-rechargeable-18650-li-ion-battery.html) has a built in charger with a USB socket and two LEDs.
//!
//! The battery length includes its contacts and the origin is the centre of that length. As well as drawing the battery and contacts there are functions
//! exposing enough information to make a battery box.
//
include <../utils/core/core.scad>
use <spring.scad>
use <../utils/rounded_cylinder.scad>
function battery_length(type) = type[2]; //! Total length including terminals
function battery_diameter(type) = type[3]; //! Casing diameter
function battery_neg_dia(type) = type[4]; //! Negative terminal diameter
function battery_pos_dia(type) = type[5]; //! Positive terminal diameter
function battery_pos_height(type) = type[6]; //! Positive terminal height above the casing
function battery_colour(type) = type[7]; //! Casing colour
function battery_led_positions(type) = type[8]; //! LED positions for Lumintop
function battery_usb_offset(type) = type[9]; //! USB connector offset from the top
function battery_contact(type) = type[10]; //! Contact type
module battery_led_positions(type) { //! Position of the LEDs on a Lumintop
posns = battery_led_positions(type);
for($i = [0 : 1 : len(posns) - 1])
translate([posns[$i].x, posns[$i].y, battery_length(type) / 2 - battery_pos_height(type)])
children();
}
module battery(type) { //! Draw a battery
vitamin(str("battery(", type[0], "): ", type[1]));
len = battery_length(type);
l = 6;
iw1 = 7;
iw2 = 5.7;
ih1 = 1;
ih2 = 1.85;
h = 2.65;
t = 0.4;
module D() {
hull() {
translate([-iw1 / 2, h - t - ih1])
square([iw1, ih1]);
translate([-iw2 / 2, h - t - ih2])
square([iw2, ih2]);
}
}
color(battery_colour(type)) render() difference() {
translate_z(-battery_pos_height(type) / 2)
cylinder(d = battery_diameter(type), h = len - battery_pos_height(type), center = true);
if(battery_usb_offset(type))
translate([battery_diameter(type) / 2, 0, len / 2 - battery_usb_offset(type) + h / 2])
rotate([-90, 0, 90])
linear_extrude(height = l + 1)
offset(delta = t)
D();
}
color("gold")
translate_z(len / 2 - battery_pos_height(type))
rounded_cylinder(r = battery_pos_dia(type) / 2, h = battery_pos_height(type) + eps, r2 = 0.5);
color("silver") {
if(battery_usb_offset(type))
translate([battery_diameter(type) / 2 - 1, 0, len / 2 - battery_usb_offset(type) + h / 2])
rotate([-90, 0, 90]) {
linear_extrude(height = l)
difference() {
offset(t) D();
D();
}
translate_z(l - 1)
linear_extrude(height = 1)
D();
}
translate_z(-len / 2)
vflip()
cylinder(d = battery_neg_dia(type), h = eps);
}
battery_led_positions(type)
color(["red","green","blue"][$i])
cylinder(d = 1.5, h = eps);
}
function contact_width(type) = type[1]; //! Width of the flat part
function contact_height(type) = type[2]; //! Height of the flat part
function contact_thickness(type) = type[3]; //! Thickness of the metal
function contact_tab_width(type) = type[4]; //! Width of the tab
function contact_tab_length(type) = type[5]; //! Length of the tab
function contact_pos(type) = type[6]; //! Positive contact dimple height and top and bottom internal diameter
function contact_neg(type) = type[7]; //! Negative spring height above the plate when compressed and the spring type
module battery_contact(type, pos = true) { //! Draw a positive or negative battery contact for specified battery
vitamin(str("battery_contact(", type[0], ", ", pos, "): Battery ", pos ? "positive" : "negative", " contact"));
neg = 9;
tw = contact_tab_width(type);
h = contact_height(type);
hole_y = -contact_tab_length(type) + tw / 2;
t = contact_thickness(type);
color("silver") {
rounded_rectangle([contact_width(type), h, t], r = 1, center = false);
translate([0, -h / 2, t])
rotate([90, 0, 0])
linear_extrude(height = t)
difference() {
hull() {
translate([-tw / 2, -1])
square([tw, 1]);
translate([0, hole_y])
circle(d = tw);
}
translate([0, hole_y])
circle(tw / 4);
}
if(pos) {
p = contact_pos(type);
cylinder(d1 = p.z + 2 * t, d2 = p.y + 2 * t, h = p.x);
}
else {
p = contact_neg(type);
not_on_bom()
translate_z(t)
comp_spring(p.y, p.x - t);
}
}
}