PinePhoneBoy/strap_link.scad

356 lines
11 KiB
OpenSCAD
Raw Normal View History

2021-01-19 13:47:16 +00:00
links_count=3; // [1..20]
2021-01-18 18:03:27 +00:00
include_terminal=true; // [true,false]
2021-01-19 13:47:16 +00:00
export=0; // [0:6]
2021-01-18 18:03:27 +00:00
MODEL_DEMO=0;
MODEL_LINKS=1;
2021-01-19 10:51:51 +00:00
MODEL_CLIP_A=2;
MODEL_CLIP_B=3;
MODEL_CLIP_RATCHETING=4;
MODEL_CLIP_RATCHETING_A=5;
MODEL_CLIP_RATCHETING_B=6;
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-19 13:47:16 +00:00
function get_link_socket_roundgap() = 2;
2021-01-18 18:03:27 +00:00
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-19 13:47:16 +00:00
module pin() {
2021-01-17 15:21:13 +00:00
segment_size=get_link_segment_size();
2021-01-19 13:47:16 +00:00
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() {
segment_size=get_link_segment_size();
h=segment_size.y-get_link_socket_slack().y;
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();
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
}
2021-01-19 13:47:16 +00:00
}
module arm() {
arm_size=get_link_joiner_arm_size();
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);
}
module armFront() {
arm();
}
module armBack() {
scale([1, -1, 1]) arm();
}
module armJoiner() {
gap=get_link_socket_roundgap();
arm_size=get_link_joiner_arm_size();
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);
}
module link_arms() {
armFront();
armBack();
armJoiner();
}
module link_connector_pin() {
pin();
link_arms();
}
module link_connector_socket() {
pin_socket();
}
module link(terminal=false) {
module link_joiner() {
gap=get_link_socket_roundgap();
2021-01-17 21:33:57 +00:00
arm_size=get_link_joiner_arm_size();
2021-01-19 13:47:16 +00:00
module pin_to_socket_joiner() {
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-19 13:47:16 +00:00
pin_to_socket_joiner();
2021-01-17 15:21:13 +00:00
}
2021-01-19 13:47:16 +00:00
link_connector_pin();
if (terminal) {
right(segment_size.x + 2) zrot(180) link_connector_pin();
} else {
link_joiner();
right(segment_size.x) link_connector_socket();
2021-01-17 21:33:57 +00:00
}
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];
2021-01-19 10:51:51 +00:00
entry_size=[slot_size.x, clip_size.y+1, clip_size.z];
entry_pos=[0, 0, 1.5];
module socket_area() {
$fn=$preview? 10 : 20;
xrot(90) down(size.y/2) cylinder(d=size.z, h=size.y);
}
module socket_cutout() {
$fn=$preview? 10 : 20;
xrot(90) down(slot_size.y/2) cylinder(d=slot_size.z, h=slot_size.y);
}
module cover() {
translate(entry_pos) cube(entry_size, center=true);
}
module joiner(groove) {
slack=groove?0.5:0;
joiner_size=[entry_size.x-6+slack, entry_size.y-6+slack, entry_size.z-4+slack];
2021-01-19 13:47:16 +00:00
joiner_pos=[entry_pos.x, entry_pos.y, entry_pos.z - entry_size.z/2 + joiner_size.z/2];
2021-01-19 10:51:51 +00:00
translate(joiner_pos) cube(joiner_size, center=true);
}
module model() {
difference() {
union() {
right(clip_size.x/2) socket_area();
left(clip_size.x/2) socket_area();
cube(clip_size, center=true);
}
right(clip_size.x/2) socket_cutout();
left(clip_size.x/2) socket_cutout();
}
}
2021-01-18 18:03:27 +00:00
right(clip_size.x/2)
2021-01-19 10:51:51 +00:00
if (is_model(MODEL_CLIP_A)) {
difference() {
model();
cover();
}
joiner(groove=false);
} else if (is_model(MODEL_CLIP_B)) {
difference() {
intersection() {
model();
cover();
}
joiner(groove=true);
}
2021-01-18 18:03:27 +00:00
}
}
2021-01-19 13:47:16 +00:00
module clip_ratcheting(ratchet_length=28) {
2021-01-18 18:03:27 +00:00
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];
2021-01-18 20:04:14 +00:00
slot_size=[clip_size.x+slot_slack.x + 0.2, size.y+1, pin_diam+slot_slack.z];
2021-01-18 18:03:27 +00:00
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() {
2021-01-19 13:47:16 +00:00
right(12.5) zrot(180) link_connector_pin();
2021-01-18 18:03:27 +00:00
}
module hookLeft() {
2021-01-19 13:47:16 +00:00
left(12.5) link_connector_pin();
2021-01-18 18:03:27 +00:00
}
wall=2;
2021-01-19 10:51:51 +00:00
tooth_size=[4, 3, 3];
2021-01-18 18:03:27 +00:00
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);
2021-01-18 20:04:14 +00:00
right(ratchet_length/2+1) {
slideRailGuide(groove=true);
scale([1,-1,1]) slideRailGuide(groove=true);
}
2021-01-18 18:03:27 +00:00
}
teethFwd();
teethBack();
}
}
2021-01-19 10:51:51 +00:00
ratchet_tooth_count=2;
ratchet_wall=2.5;
2021-01-18 20:04:14 +00:00
ratchet_slack=0.3;
rail_slack=0.2;
2021-01-19 10:51:51 +00:00
ratchet_tooth_scale_z=0.8;
2021-01-18 18:03:27 +00:00
module ratchetTeethFront() {
module ratchetButton() {
2021-01-18 20:04:14 +00:00
size=[8,wall*4,4];
up(size.z+1) fwd(wall*2 - ratchet_wall) cuboid(size, fillet=1, edges=EDGES_FRONT);
2021-01-19 10:51:51 +00:00
up(2) back(ratchet_wall/2) cube([size.x, ratchet_wall, tooth_size.z*ratchet_tooth_scale_z + size.z], center=true);
2021-01-18 18:03:27 +00:00
}
2021-01-18 20:04:14 +00:00
fwd((clip_size.y-wall*2)/2 - tooth_size.y - ratchet_slack)
2021-01-18 18:03:27 +00:00
left(ratchet_length) {
for (i=[0:ratchet_tooth_count-1]) {
2021-01-19 10:51:51 +00:00
right(i*tooth_size.x) scale([-1,-1*(1-i/5),ratchet_tooth_scale_z]) tooth();
2021-01-18 18:03:27 +00:00
}
ratchetButton();
}
module ratchetWall() {
2021-01-18 20:04:14 +00:00
up(tooth_size.z/2) left(ratchet_length/2 + wall - wall/2) fwd(clip_size.y/2-wall-tooth_size.y-ratchet_wall/2 - ratchet_slack)
2021-01-19 10:51:51 +00:00
down(wall/2+0.5) cube([ratchet_length + wall, ratchet_wall, tooth_size.z*ratchet_tooth_scale_z], center=true);
2021-01-18 18:03:27 +00:00
}
ratchetWall();
}
module ratchetTeethBack() {
scale([1,-1,1]) ratchetTeethFront();
}
module ratchetRight() {
2021-01-18 20:04:14 +00:00
left(wall) cube([wall*2, clip_size.y + rail_slack*2, clip_size.z], center=true);
2021-01-18 18:03:27 +00:00
ratchetTeethFront();
ratchetTeethBack();
}
2021-01-18 20:04:14 +00:00
module slideRailGuide(groove) {
size=[ratchet_length, wall, wall];
fwd(clip_size.y/2 + rail_slack)
left(size.x/2) scale(groove?1.5:1) cuboid(size, fillet=0.5);
}
module slideRailLeft() {
2021-01-19 10:51:51 +00:00
size=[ratchet_length, clip_size.y/2 - ratchet_wall*2 - wall/2 - ratchet_slack - tooth_size.y, clip_size.z];
2021-01-18 20:04:14 +00:00
right(size.x/2) cube(size, center=true);
}
module slideRailRight() {
size=[ratchet_length + 3, wall*1.5, clip_size.z];
module railFront() {
fwd(clip_size.y/2 + size.y/2 + rail_slack) left(size.x/2)
cuboid(size, fillet=1, edges=EDGES_FRONT);
slideRailGuide(groove=false);
}
module railBack() {
scale([1, -1, 1]) railFront();
}
railFront();
railBack();
}
2021-01-18 18:03:27 +00:00
2021-01-19 13:47:16 +00:00
left(2) if (is_model(MODEL_CLIP_RATCHETING_A) || is_model(MODEL_CLIP_RATCHETING)) {
2021-01-18 18:03:27 +00:00
left(ratchet_length + wall + 1) {
hookLeft();
2021-01-18 20:04:14 +00:00
left(0.1) {
ratchetLeft();
slideRailLeft();
}
2021-01-18 18:03:27 +00:00
}
}
if (is_model(MODEL_CLIP_RATCHETING_B) || is_model(MODEL_CLIP_RATCHETING)) {
ratchetRight();
hookRight();
2021-01-18 20:04:14 +00:00
slideRailRight();
2021-01-18 18:03:27 +00:00
}
}
// 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();
}
}
} else {
2021-01-18 20:04:14 +00:00
intersection () {
if (!is_undef(xray)) {
down(50) cube([100, 100, 100], center=true);
}
union() {
2021-01-19 10:51:51 +00:00
if (is_model(MODEL_CLIP_A) || is_model(MODEL_CLIP_B)) {
2021-01-18 20:04:14 +00:00
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)) {
2021-01-19 13:47:16 +00:00
left(get_link_clip_size().x * 2 + 3) clip_ratcheting();
2021-01-18 20:04:14 +00:00
}
if (is_model(MODEL_LINKS)) for (i = [0:links_count-1]) {
terminal=(i==links_count-1) && include_terminal;
right(i*segment_size.x) link(terminal=terminal);
}
}
2021-01-17 15:21:13 +00:00
}
}