1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-01-17 21:48:43 +01:00
NopSCADlib/vitamins/battery.scad
Chris Palmer 2d091b9d16 Added a constructor function for PCBs.
PCB text can now specify a colour.
Added SOT23_6, TSOT23_8 and CAP1210 SMD packages.
Added ESP-201 Wifi Module PCB.
Added ESP12F Wifi module.
Added tiny_buck converter PCB.
Made 2p54joiner a bit longer.
Fixed SOIC gullwing shape.
Added Wifi antennas.
Added Yunpen filtered IEC mains inlet.
Added power jack socket.
Added right angle option for LEDs.
Added gear_motors.
Added 686ZZ and 696ZZ ball bearings.
Added two larger box section tubes.
Added right angle option to square_buttons. Doesn't draw the frame yet.
Added multiwatt11 package for L6203.
Added ONS9143A 13A mains socket.
Added radial electrolytic capacitors.
Added LDE10_20B PSU module.
Added screw_tearsink() to make horizontal countersunk holes.
Can now have solid tracks on veroboard.
Added veroboard_base() module to make an STL for a base with spacers.
Corrected M6 spring washer thickness.
Can now specify the height of a solder meniscus.
slot() now has a center option.
Added button_6mm_7 with a taller button.
Added default fa, fs and fn constants used for drawing vitamins.
These can be set via $default_fa and $default_fs that can also be set
by environment variables: NOPSCADLIB_DEFAULT_FA and NOPSCADLIB_DEFAULT_FS.
2023-10-29 21:56:08 +00:00

164 lines
6.0 KiB
OpenSCAD

//
// 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;
$fa = fa; $fs = fs;
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(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(l)
difference() {
offset(t) D();
D();
}
translate_z(l - 1)
linear_extrude(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);
translate([0, -h / 2, t])
rotate([90, 0, 0])
linear_extrude(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);
}
}
}