Refactor Globals

Refactored Globals. Module and gear width are no longer global.
This commit is contained in:
2021-01-14 08:26:35 -05:00
parent 93e7675ab5
commit be9f91124a

View File

@@ -19,28 +19,11 @@ helix_angle = [ for (x=linspace(-1,1,helix_steps)) exp(-abs(x))*10*sign(x) ];
//helix_angle = [ for (x=linspace(-helix_turns,helix_turns,helix_steps)) exp(-abs(x))*10*sign(x) ]; //helix_angle = [ for (x=linspace(-helix_turns,helix_turns,helix_steps)) exp(-abs(x))*10*sign(x) ];
//helix_angle = constant(axis_angle/2); //width=18; // width of the actual gears.
//width = 10;
width=18; // width of the actual gears.
N = 9; // Number of gear teeth.
// Force same number of teeth
N1=N;
N2=N;
Module=1.45;
ShaftD=4.2;
MeshD=Module*(N1+N2)/2;
SwingAdd = 1; SwingAdd = 1;
Swing = MeshD/2 + Module + SwingAdd;
// RefD = M*N ; Default M=1
tol=.2;
BackW=Swing+Module;
SideW=tol+BackW;
echo("Reference Diameter (MeshD): ", MeshD);
//rot=90*$t; //rot=90*$t;
rot=3; rot=3;
@@ -62,10 +45,11 @@ module plate_full_open(rot=90) {
} }
module plate_print(rot=90-8, door=false) { module plate_print(rot=90-8, door=false) {
gear_hinge(rot=rot, box=false, rounded_case=true, door=door); gear_hinge(width=18,rot=rot, box=false, rounded_case=true, door=door);
} }
module gear_hinge( module gear_hinge(
width = 18,
box=true, box=true,
rounded_case=false, rounded_case=false,
box_top=true, box_top=true,
@@ -73,19 +57,26 @@ module gear_hinge(
left_gear_color="blue", left_gear_color="blue",
right_gear_color="red", right_gear_color="red",
door = false, door = false,
mod = 1.45,
nteeth = 9,
shaftd=4.2,
tol = .2,
rot=0) { rot=0) {
//offex=tol; //offex=tol;
bc = $incolor ? box_color : undef; bc = $incolor ? box_color : undef;
lgc = $incolor ? left_gear_color : undef; lgc = $incolor ? left_gear_color : undef;
rgc = $incolor ? right_gear_color : undef; rgc = $incolor ? right_gear_color : undef;
MeshD=mod*nteeth; // N1 == N2
echo("Reference Diameter (MeshD): ", MeshD);
offex=0; offex=0;
color(lgc) translate([-MeshD/2 - offex,0]) rotate([0,0,rot]) blue_gear(); color(lgc) translate([-MeshD/2 - offex,0]) rotate([0,0,rot]) blue_gear(nteeth, mod, width, shaftd, tol);
color (rgc) translate([offex + MeshD/2,0]) rotate([0,0,-rot]) red_gear(door=door); color (rgc) translate([offex + MeshD/2,0]) rotate([0,0,-rot]) red_gear(nteeth, mod, width, shaftd, tol, door=door);
if (box) { if (box) {
color(bc) box(full = true, top=box_top, tol=tol); color(bc) box(full = true, top=box_top, tol=tol);
} else if (rounded_case) { } else if (rounded_case) {
round_case(full=true, tol=tol); round_case(d=shaftd, mod=mod, nteeth=nteeth, width=width, full=true, tol=tol);
} }
} }
@@ -93,10 +84,10 @@ module gear_hinge(
// extention to ensure that the gears don't pop out. This is only // extention to ensure that the gears don't pop out. This is only
// added to one gear. // added to one gear.
module gear_track_block() { module gear_track_block(meshd, shaftd, width, w1=275, w2=310) {
difference() { difference() {
CyS(r=MeshD/2 +.5, h=width/2, w1=275, w2=310); CyS(r=meshd/2 +.5, h=width/2, w1=w1, w2=w2);
CyS(r=ShaftD+.5, h=width/2, w1=275, w2=310); CyS(r=shaftd+.5, h=width/2, w1=w1, w2=w2);
} }
} }
@@ -110,39 +101,48 @@ module gear_sector(meshd, width) {
} }
// blue_gear - Gear on the left with the track block built into its back side. // blue_gear - Gear on the left with the track block built into its back side.
module blue_gear() { module blue_gear(n, mod, width, shaftd, tol, swingadd = 1, shift=-2) {
meshd=mod*n;
swing = meshd/2 + mod + swingadd;
backw=swing+mod;
sidew=tol+backw;
intersection() { intersection() {
spur_gear(n=N1, w=width, m=Module, chamfer=chamfer, chamfer_shift=-2,helix_angle = helix_angle, add=-tol/4 ); spur_gear(n, w=width, m=mod, chamfer=chamfer, chamfer_shift=shift,helix_angle = helix_angle, add=-tol/4 );
difference() { difference() {
gear_sector(meshd=MeshD, width=width); gear_sector(meshd, width=width);
// Shaft Hole // Shaft Hole
cylinder(d=ShaftD, h=width+2, center=true); cylinder(d=shaftd, h=width+2, center=true);
// Block limit - side // Block limit - side
translate([-BackW+2*tol,-MeshD/2,0]) cube([MeshD,MeshD,width], center=true); translate([-backw+2*tol,-meshd/2,0]) cube([meshd,meshd,width], center=true);
// Block Limit - back // Block Limit - back
translate([-MeshD,-1.5+tol, -(width+1)/2]) translate([-meshd,-1.5+tol, -(width+1)/2])
cube([MeshD,1.5+tol,width+1]); cube([meshd,1.5+tol,width+1]);
// Block limit - front // Block limit - front
translate([0,0,-width/2]) cube([1,MeshD/2,width]); translate([0,0,-width/2]) cube([1,meshd/2,width]);
} }
} }
// leaf arm // leaf arm
translate([2,11.6,0]) rotate([0,0,0]) leaf_arm(left=true, h=width+3.2); translate([2,11.6,0]) rotate([0,0,0]) leaf_arm(left=true, width=width, floord=3.2, tol=tol);
} }
// Red Gear - Gear on the right. // Red Gear - Gear on the right.
module red_gear(door=false) module red_gear(n, mod, width, shaftd, tol, swingadd=1, shift=-2, door=false)
{ {
meshd=mod*n;
swing = meshd/2 + mod + swingadd;
backw=swing+mod;
sidew=tol+backw;
difference() { difference() {
union() { union() {
CyS(r=MeshD/2 - 2, h=width, w1=90, w2=190); CyS(r=meshd/2 - 2, h=width, w1=90, w2=190);
intersection() { intersection() {
spur_gear(n=N2, w=width, m=Module, chamfer=chamfer, chamfer_shift=-2, helix_angle=-helix_angle, add=-tol/4); spur_gear(n=n, w=width, m=mod, chamfer=chamfer, chamfer_shift=shift, helix_angle=-helix_angle, add=-tol/4);
CyS(r=MeshD, h=width, w1=181, w2=-30); CyS(r=meshd, h=width, w1=181, w2=-30);
} }
@@ -163,24 +163,25 @@ module red_gear(door=false)
} }
} }
} }
else leaf_arm(left=false, h=width+3.2); else leaf_arm(left=false, width=width, floord=3.2, tol=tol);
} }
// Rear Block // Rear Block
gear_track_block(); gear_track_block(meshd, shaftd, width);
} }
// Shaft Hole // Shaft Hole
cylinder(d=ShaftD, h=width+2, center=true); cylinder(d=shaftd, h=width+2, center=true);
// Block limit - side // Block limit - side
translate([BackW-2*tol,-MeshD/2,0]) cube([MeshD,MeshD,width+1], center=true); translate([backw-2*tol,-meshd/2,0]) cube([meshd,meshd,width+1], center=true);
// Block limit - front // Block limit - front
translate([0,-1.5+tol, -(width+1)/2]) cube([MeshD,1.5+tol,width+1]); translate([0,-1.5+tol, -(width+1)/2]) cube([meshd,1.5+tol,width+1]);
} }
} }
module leaf_arm(left=true, h, l, angle=false) { module leaf_arm(left=true, width, floord ,l, tol, angle=false) {
dx = 3; dx = 3;
h = width + floord;
difference() { difference() {
//cube([4,20,width+1], center=true); //cube([4,20,width+1], center=true);
translate([0,-9.5+dx/2,0]) cube([4,dx,width], center=true); translate([0,-9.5+dx/2,0]) cube([4,dx,width], center=true);
@@ -215,34 +216,36 @@ module round_case_inner(meshd, shaftd, width, tol) {
// round_case - generates the back shell of the hinge, which includes the axis // round_case - generates the back shell of the hinge, which includes the axis
// posts of the hinges. // posts of the hinges.
module round_case( module round_case(
d=ShaftD, d,
width,
tol=.25, tol=.25,
top=true, top=true,
MeshD=MeshD, nteeth,
Module=Module, mod,
SwingAdd=1, swingadd=1,
WallD=1.2, walld=1.2,
spine=false, spine=false,
full=true) full=true)
{ {
Swing = MeshD/2 + Module + SwingAdd; meshd=mod*nteeth;
BackW=WallD/2 + Swing+Module+1; swing = meshd/2 + mod + swingadd;
SideW=tol + BackW-MeshD/2; backw=walld/2 + swing+mod+1;
SideW=tol + backw-meshd/2;
difference() { difference() {
intersection() { intersection() {
hull() { hull() {
for (x = [-MeshD/2, MeshD/2] ) for (x = [-meshd/2, meshd/2] )
translate([x,0]) translate([x,0])
cylinder(d=18.5, h=width+3.2, center=true); cylinder(d=18.5, h=width+3.2, center=true);
} }
translate([-12,-12,-(width/2 + 3)]) cube([24,12,width+6]); translate([-12,-12,-(width/2 + 3)]) cube([24,12,width+6]);
} }
if (spine) if (spine)
round_case_inner(meshd=MeshD, shaftd=d, width=width, tol=tol); round_case_inner(meshd=meshd, shaftd=d, width=width, tol=tol);
else { else {
hull() round_case_inner(meshd=MeshD, shaftd=d, width=width, tol=tol); hull() round_case_inner(meshd=meshd, shaftd=d, width=width, tol=tol);
} }
if (full) { if (full) {
@@ -255,19 +258,19 @@ module round_case(
} }
for (xi = [-1, 1]) { for (xi = [-1, 1]) {
translate([xi*MeshD/2,0]) { translate([xi*meshd/2,0]) {
// Shaft // Shaft
cylinder(d=d-2*tol, h=width+2, center=true); cylinder(d=d-2*tol, h=width+2, center=true);
// Shaft Bottom/top // Shaft Bottom/top
for (s = [-1,1]) { for (s = [-1,1]) {
translate([0,0,s*(width/2 + WallD/2 + 1.5*tol)]) translate([0,0,s*(width/2 + walld/2 + 1.5*tol)])
cylinder(d=d+4*tol, h=WallD+tol, center=true); cylinder(d=d+4*tol, h=walld+tol, center=true);
} }
translate([xi*2.5,-WallD/2,0]) translate([xi*2.5,-walld/2,0])
cube([3+2*tol+Module+1,WallD,width+3.2], center=true); cube([3+2*tol+mod+1,walld,width+3.2], center=true);
} }
translate([xi*11.5-.5,-MeshD/2,-(width + 3.2)/2]) cube([1,MeshD/2,width+3.2]); translate([xi*11.5-.5,-meshd/2,-(width + 3.2)/2]) cube([1,meshd/2,width+3.2]);
} }
} }