PinePhoneBoy/strap_link.scad

272 lines
9.0 KiB
OpenSCAD
Raw Normal View History

2021-01-18 18:03:27 +00:00
links_count=6; // [1..20]
include_terminal=true; // [true,false]
export=4; // [0:5]
MODEL_DEMO=0;
MODEL_LINKS=1;
MODEL_CLIP=2;
MODEL_CLIP_RATCHETING=3;
MODEL_CLIP_RATCHETING_A=4;
MODEL_CLIP_RATCHETING_B=5;
2021-01-17 15:21:13 +00:00
//validation=1;
VALIDATE_INTERSECTION=1;
2021-01-17 15:49:08 +00:00
//xray=1;
2021-01-17 15:21:13 +00:00
use <BOSL/transforms.scad>
use <BOSL/shapes.scad>
include <BOSL/constants.scad>
2021-01-18 18:03:27 +00:00
function is_not_export() = is_undef(export) || export == 0;
function is_export() = !is_not_export();
function is_model_strict(m) = is_export() && export == m;
function is_model(m) = is_not_export() || export == m;
2021-01-17 15:49:08 +00:00
function get_link_segment_size() = [15, 30, 5];
2021-01-17 15:21:13 +00:00
function get_link_pin_diameter() = 2;
2021-01-17 15:49:08 +00:00
function get_link_socket_slack() = [1, 4, 1];
2021-01-17 21:33:57 +00:00
function get_link_joiner_arm_size() = [get_link_segment_size().x - 2, 3, segment_size.z];
function get_link_socket_size() = [get_link_segment_size().z,
get_link_segment_size().y - get_link_joiner_arm_size().y*2,
get_link_segment_size().z];
2021-01-17 15:49:08 +00:00
2021-01-18 18:03:27 +00:00
function get_link_clip_size() = [get_link_pin_diameter()*5, get_link_segment_size().y - 5, get_link_segment_size().z];
2021-01-17 15:49:08 +00:00
echo("===============================");
echo(str("Strap length: ", (links_count * get_link_segment_size().x), " mm"));
echo("===============================");
assert(get_link_segment_size().x >= 10, "Link segment is too short.");
assert(get_link_segment_size().z >= (get_link_pin_diameter() + get_link_socket_slack().z + 1), "Link segment is too thin.");
2021-01-17 15:21:13 +00:00
2021-01-17 21:33:57 +00:00
module link(terminal=false) {
2021-01-17 15:21:13 +00:00
segment_size=get_link_segment_size();
module pin() {
h=segment_size.y;
d=get_link_pin_diameter();
back(h/2) xrot(90) cylinder(h=h, d=d, $fn=$preview ? 10 : 30);
}
module pin_socket_area() {
2021-01-17 15:49:08 +00:00
h=segment_size.y-get_link_socket_slack().y;
2021-01-17 15:21:13 +00:00
d=segment_size.z;
back(h/2) xrot(90) cylinder(h=h, d=d, $fn=$preview ? 10 : 30);
}
module pin_socket() {
difference() {
pin_socket_area();
2021-01-17 15:49:08 +00:00
scaleup = [
((get_link_pin_diameter() + get_link_socket_slack().x) / get_link_pin_diameter()),
((get_link_pin_diameter() + get_link_socket_slack().y) / get_link_pin_diameter()),
((get_link_pin_diameter() + get_link_socket_slack().z) / get_link_pin_diameter())
];
scale(scaleup) pin();
2021-01-17 15:21:13 +00:00
}
}
module joiner() {
gap=2;
2021-01-17 21:33:57 +00:00
arm_size=get_link_joiner_arm_size();
2021-01-17 15:21:13 +00:00
module arm() {
2021-01-17 15:49:08 +00:00
fwd(segment_size.y/2 + arm_size.y/2 - 1) right(arm_size.x/2 - 1) cuboid(arm_size, fillet=1, edges=EDGES_FRONT + EDGES_Y_ALL);
2021-01-17 15:21:13 +00:00
}
module armFront() {
arm();
}
module armBack() {
scale([1, -1, 1]) arm();
}
module armJoiner() {
2021-01-17 21:33:57 +00:00
joiner_size=[arm_size.x-get_link_socket_size().x, segment_size.y, segment_size.z];
right(joiner_size.x/2 + get_link_socket_size().x/2 + gap) cuboid(joiner_size, fillet=1, edges=EDGES_Z_ALL + EDGES_BOTTOM);
2021-01-17 15:21:13 +00:00
}
module socketJoiner() {
2021-01-17 21:33:57 +00:00
joiner_size=[segment_size.x-get_link_socket_size().x+get_link_socket_size().x*0.2,
2021-01-17 15:21:13 +00:00
segment_size.y-4,
segment_size.z];
difference() {
2021-01-17 15:49:08 +00:00
right(joiner_size.x/2 + 4.5) cuboid(joiner_size, fillet=1, edges=EDGES_Z_ALL + EDGES_BOTTOM);
2021-01-17 15:21:13 +00:00
right(segment_size.x) scale([1, 2, 1]) pin_socket_area();
}
}
2021-01-17 21:33:57 +00:00
module terminalArm() {
left(5) {
shift=arm_size.x - get_link_pin_diameter();
right(segment_size.x + shift + gap/2) pin();
right(segment_size.x + gap/2) {
armFront();
armBack();
}
right(arm_size.x - get_link_socket_size().x + gap) armJoiner();
}
}
2021-01-17 15:21:13 +00:00
armFront();
armBack();
armJoiner();
2021-01-17 21:33:57 +00:00
if (terminal) {
terminalArm();
} else {
socketJoiner();
}
2021-01-17 15:21:13 +00:00
}
pin();
joiner();
2021-01-17 21:33:57 +00:00
if (!terminal) {
right(segment_size.x) pin_socket();
}
2021-01-17 15:21:13 +00:00
}
2021-01-18 18:03:27 +00:00
module clip() {
socket_size=get_link_socket_size();
clip_size=get_link_clip_size();
pin_diam=get_link_pin_diameter();
slot_slack=get_link_socket_slack();
size=[clip_size.x+socket_size.x, clip_size.y, clip_size.z];
slot_size=[clip_size.x+slot_slack.x, size.y+1, pin_diam+slot_slack.z];
entry_size=[slot_size.x-5, clip_size.y+1, clip_size.z];
right(clip_size.x/2)
difference() {
cuboid(size, fillet=1);
cuboid(slot_size, fillet=1);
up(entry_size.z/2) cube(entry_size, center=true);
}
}
module clip_ratcheting(ratchet_length=20) {
socket_size=get_link_socket_size();
clip_size=get_link_clip_size();
pin_diam=get_link_pin_diameter();
slot_slack=get_link_socket_slack();
size=[clip_size.x+socket_size.x, clip_size.y, clip_size.z];
slot_size=[clip_size.x+slot_slack.x, size.y+1, pin_diam+slot_slack.z];
entry_size=[slot_size.x-5, clip_size.y+1, clip_size.z];
//right(clip_size.x/2)
module hook() {
intersection() {
difference() {
cuboid(size, fillet=1);
cuboid(slot_size, fillet=1);
up(entry_size.z/2) cube(entry_size, center=true);
}
translate([0, -50, -50]) cube([100, 100, 100]);
}
}
module hookRight() {
hook();
}
module hookLeft() {
scale([-1, 1, 1]) hook();
}
wall=2;
tooth_size=[2, 2, 3];
module tooth() {
s=[tooth_size.x, tooth_size.z, tooth_size.y];
up(tooth_size.z/2) xrot(-90) right_triangle(s);
}
module teethFwd() {
tooth_count = ratchet_length/tooth_size.x;
fwd((clip_size.y-wall*2)/2)
right(ratchet_length/2) {
for (i=[1:tooth_count]) {
left(i*tooth_size.x) tooth();
}
cap_size=[ratchet_length, tooth_size.y, 1];
up(tooth_size.z/2 + cap_size.z/2) left(cap_size.x/2) back(tooth_size.y/2) {
difference() {
cube(cap_size, center=true);
translate([0.1, 0.1, 0]) back(tooth_size.y/2) right(ratchet_length/2) zrot(180) tooth();
}
}
}
}
module teethBack() {
scale([1, -1, 1]) teethFwd();
}
module ratchetLeft() {
right(ratchet_length/2) {
difference() {
cube([ratchet_length, clip_size.y, clip_size.z], center=true);
up(wall/2) cube([ratchet_length, clip_size.y-wall*2, clip_size.z], center=true);
}
teethFwd();
teethBack();
}
}
ratchet_tooth_count=3;
ratchet_wall=1;
module ratchetTeethFront() {
module ratchetButton() {
size=[3,wall*4,2];
up(4) fwd(wall*2 - ratchet_wall) cuboid(size, fillet=1, edges=EDGES_FRONT);
up(2) back(wall/2) cube([size.x, wall, tooth_size.z + size.z], center=true);
}
fwd((clip_size.y-wall*2)/2 - tooth_size.y - 0.5)
left(ratchet_length) {
for (i=[0:ratchet_tooth_count-1]) {
right(i*tooth_size.x) scale([-1,-1,1]) tooth();
}
ratchetButton();
}
module ratchetWall() {
up(tooth_size.z/2) left(ratchet_length/2 + wall - wall/2) fwd(clip_size.y/2-wall-tooth_size.y-ratchet_wall)
down(wall/2+0.5) cube([ratchet_length + wall, ratchet_wall, tooth_size.z], center=true);
}
ratchetWall();
}
module ratchetTeethBack() {
scale([1,-1,1]) ratchetTeethFront();
}
module ratchetRight() {
left(wall/2) cube([wall, clip_size.y, clip_size.z], center=true);
ratchetTeethFront();
ratchetTeethBack();
}
if (is_model(MODEL_CLIP_RATCHETING_A) || is_model(MODEL_CLIP_RATCHETING)) {
left(ratchet_length + wall + 1) {
hookLeft();
left(0.5) ratchetLeft();
}
}
if (is_model(MODEL_CLIP_RATCHETING_B) || is_model(MODEL_CLIP_RATCHETING)) {
ratchetRight();
hookRight();
}
}
// Export / Demo / Validation:
2021-01-17 15:21:13 +00:00
segment_size=get_link_segment_size();
if (!is_undef(validation)) {
if (validation==VALIDATE_INTERSECTION) {
intersection() {
right(0*segment_size.x) link();
right(1*segment_size.x) link();
}
intersection() {
right(1*segment_size.x) link();
right(2*segment_size.x) link();
}
}
2021-01-17 15:49:08 +00:00
} else if (!is_undef(xray)) {
intersection() {
cube([1000, 1000, 1000]);
for (i = [0:links_count-1]) {
right(i*segment_size.x) link();
}
}
2021-01-17 15:21:13 +00:00
} else {
2021-01-18 18:03:27 +00:00
if (is_model(MODEL_CLIP)) {
left(get_link_clip_size().x) clip();
}
if (is_model(MODEL_CLIP_RATCHETING) || is_model(MODEL_CLIP_RATCHETING_A) || is_model(MODEL_CLIP_RATCHETING_B)) {
left(get_link_clip_size().x) clip_ratcheting();
}
if (is_model(MODEL_LINKS)) for (i = [0:links_count-1]) {
2021-01-17 21:33:57 +00:00
terminal=(i==links_count-1) && include_terminal;
right(i*segment_size.x) link(terminal=terminal);
2021-01-17 15:21:13 +00:00
}
}