Skip to content

Instantly share code, notes, and snippets.

@SharpCoder
Last active March 9, 2020 15:56
Show Gist options
  • Select an option

  • Save SharpCoder/d30ba757354ec78c6ee9d700a76b2f30 to your computer and use it in GitHub Desktop.

Select an option

Save SharpCoder/d30ba757354ec78c6ee9d700a76b2f30 to your computer and use it in GitHub Desktop.
include <openfusion.scad>
include <gears.scad>
//
bolt_bore = 6.2;
bearing_bore = 19.1 + 3.2;
limb_height = 6;
bearing_padding = 0;
final_limb_height = limb_height + bearing_padding;
$fn = 100;
tol = 0.2;
N1 = 24; // 24
NPlanet = N1;
N2 = 72; // 72
P = 20;
dist_c = calc_internal_center_distance(N1, N2, P) +.1;
echo("center distance", dist_c);
dist_c_2 = calc_center_distance(NPlanet, N1, P) + .2;
echo("center distance", dist_c_2);
module interface() {
hex_nut_dia = 9.9 + tol;
hex_nut_depth = 4.65 - 0.2 + tol; // NOTE: the subtraction is a sort of anti-tolerance.
linear_extrude(height=hex_nut_depth)
hexagon(hex_nut_dia/2);
linear_extrude(height=8.2)
circle(d=bolt_bore, $fn=25);
}
module limb() {
difference() {
linear_extrude(final_limb_height)
minkowski() {
square([1, dist_c + 6], center=true);
circle(d=15);
}
translate([0, dist_c/2, 0])
interface();
}
}
difference() {
union() {
circular_mirror(d=dist_c/2, steps=3)
rotate(-360/4)
limb();
linear_extrude(final_limb_height)
circle(d=40);
/*rotate(-360/4)
linear_extrude(final_limb_height)
circular_mirror(d=3, steps=7)
square([32,30], center=true);*/
}
linear_extrude(final_limb_height)
circle(d=bearing_bore);
}
module ring_base(padding) {
union() {
bearing_h = 6;
cap_h = 1;
skirt = 3.5;
total_h = bearing_h + cap_h;
bore = 19.1;
difference() {
cylinder(total_h, d = bore + padding);
cylinder(total_h, d = bore);
}
difference() {
cylinder(cap_h, d = bore + padding + skirt);
cylinder(cap_h, d = bore - 4);
}
}
}
ring_base(2);
include <gears.scad>
bb = 19.1; // bearing bore
bearing_h = 6;
lip_h = 1;
union() {
linear_extrude(bearing_h + lip_h)
difference() {
spur_gear(N=24, P=20, pa=20);
circle(d=bb);
}
difference() {
cylinder(lip_h, d=bb);
cylinder(lip_h, d=bb - 4);
}
}
/**
Constants
**/
in_to_mm = 25.4;
rad_to_deg = 180 / PI;
deg_to_rad = PI / 180;
$fn = 100;
/**
Functions
**/
function parametric_points(fx, fy, t0=0, t1=10, delta=0.01)
= [for(i = [t0:delta:t1]) [fx(i), fy(i)]];
function reverse(vector)
= [for(i = [1:len(vector)]) vector[len(vector) - i]];
// Invert a function
function invert(fx)
= function(t) fx(t) * -1;
// Generate the involute curve X function based on a specific radius
function inv_x1(r)
= function(t) (r * (cos(t*rad_to_deg) + t * sin(t*rad_to_deg)));
// Generate the involute curve Y function based on a specific radius
function inv_y1(r)
= function(t) (r * (sin(t * rad_to_deg) - t * cos(t * rad_to_deg)));
// Generate the mirrored involute curve X function based on a specific radius
function inv_x2(r, beta)
= function(t) r * (cos(-t*rad_to_deg - beta) - t * sin(-t * rad_to_deg - beta));
// Generate the mirrored involute curve Y function based on a specific radius
function inv_y2(r, beta)
= function(t) r * (sin(-t*rad_to_deg - beta) + t * cos(-t * rad_to_deg - beta));
/**
Maths
**/
function calc_module(P) = in_to_mm / P;
function calc_addendum(P) = (1/P) * in_to_mm;
function calc_dedendum(P) = (1.25/P) * in_to_mm;
function calc_dp(N, P, extra_padding=0) = extra_padding + (N/P) * in_to_mm;
function calc_db(N, P, pa, extra_padding=0) = calc_dp(N,P, extra_padding) * cos(pa);
function calc_dr(N, P) = calc_dp(N,P) - 2 * calc_dedendum(P);
function calc_circular_pitch(P) = (PI / P) * in_to_mm;
function calc_thickness(P) = (1.5708 / P) * in_to_mm;
function calc_alpha(dp, db, pa) = ((sqrt(pow(dp,2) - pow(db,2))/db) * rad_to_deg - pa);
function calc_beta(N, alpha) = ((360 / (4*N)) - alpha) * 2;
function calc_clearance(P) = calc_dedendum(P) - calc_addendum(P);
function calc_center_distance(N1, N2, P) = in_to_mm * (N1 + N2) /(2 * P);
function calc_internal_center_distance(N1, N2, P) = in_to_mm * (N2 - N1) / (2 * P);
/**
Modules
**/
/**
Given some parameters, this method will generate a spur gear
with an involute curve. Accepted paramters include:
- N = How many teeth
- P = Diametral pitch (all gears should have the same P)
- pa = pressure angle (recommended to remain at 14.5)
**/
module spur_gear(N, P = 12, pa = 20) {
dp = calc_dp(N, P);
db = calc_db(N, P, pa);
dr = calc_dr(N, P);
a = calc_addendum(P);
b = calc_dedendum(P);
c = calc_clearance(P);
p = calc_circular_pitch(P);
alpha = calc_alpha(dp, db, pa);
beta = calc_beta(N, alpha);
// Calculate radius to begin the involute calculations
// (with undercut adjustment)
r = db * .5;
module involute_tooth() {
involute_1_points = parametric_points(fx=inv_x1(r), fy=inv_y1(r), t1=.68);
involute_2_points = parametric_points(fx=inv_x2(r, beta), fy=inv_y2(r, beta), t1=.68);
difference() {
union() {
polygon(
concat(
[[ 0, 0 ]],
involute_1_points,
reverse(involute_2_points),
[[ 0, 0]]
)
);
}
// Use subtraction to extend the invlute curve towards the base
// circle and then stop it at that point. This will
// add some square-shaped space at the base of the tooth
// NOTE: usage of undercut might be overkill.
circle(d=(dp - 2*b));
}
}
difference() {
circle(d=(dp + 2*a));
rotate(-p) // This rotate doesn't really matter
gear_tooth_mirror(d=0, steps=N) involute_tooth();
}
}
/**
Given some parameters, this method will generate a spur gear
with an involute curve. Accepted paramters include:
- N = How many teeth
- P = Diametral pitch (all gears should have the same P)
- pa = pressure angle (recommended to remain at 14.5)
- rim = amount of additional border to add to the gear
- extra_padding = how much additional space to draw the teeth outwards by
**/
module internal_spur_gear(N, extra_padding=0, undercut=0, rim=10, P=12, pa=20) {
dp = calc_dp(N, P, extra_padding);
db = calc_db(N, P, pa, extra_padding);
dr = calc_dr(N, P);
a = calc_addendum(P);
b = calc_dedendum(P);
c = calc_clearance(P);
p = calc_circular_pitch(P);
alpha = calc_alpha(dp, db, pa);
beta = calc_beta(N, alpha);
// Calculate radius to begin the involute calculations
// (with undercut adjustment)
// r = (dp + b - a) * .5;
r = ((dp + b*2 + a)* cos(pa)) / 2;
module involute_tooth() {
involute_1_points = parametric_points(fx=invert(inv_x1(r)), fy=invert(inv_y1(r)), t1=.68);
involute_2_points = parametric_points(fx=invert(inv_x2(r, beta)), fy=invert(inv_y2(r, beta)), t1=.68);
translate([dp+b,0,0])
difference() {
union() {
polygon(
concat(
[[ 0, 0 ]],
involute_1_points,
reverse(involute_2_points),
[[ 0, 0]]
)
);
}
// Use subtraction to extend the invlute curve towards the base
// circle and then stop it at that point. This will
// add some square-shaped space at the base of the tooth
// NOTE: usage of undercut might be overkill.
circle(d=dp - undercut);
}
}
difference() {
circle(d=(dp + b + a + rim));
gear_tooth_mirror(d=0, steps=N) involute_tooth();
circle(d=dp - a - b);
}
}
/**
Helper modules
**/
module gear_tooth_mirror(x=0, y=0, d, steps) {
aps = 360 / steps;
for (step=[0:steps]) {
current_angle = step * aps;
unit_x = cos(current_angle);
unit_y = sin(current_angle);
translate([x, y, 0]) {
translate([unit_x * d, unit_y * d, 0]) {
rotate(current_angle) children();
}
}
}
}
module ring_base(padding) {
union() {
bearing_h = 6;
cap_h = 1;
skirt = 3.5;
total_h = bearing_h + cap_h;
bore = 19.1 + 2.2;
difference() {
cylinder(total_h, d = bore + padding);
cylinder(total_h, d = bore);
}
difference() {
cylinder(cap_h, d = bore + padding + skirt);
cylinder(cap_h, d = bore - 7);
}
}
}
ring_base(2);
/**
Constants
**/
in_to_mm = 25.4;
rad_to_deg = 180 / PI;
deg_to_rad = PI / 180;
/**
Maths
**/
function rad(degree) = (degree / 180) * 3.14;
function deg(rad) = (rad * 180) / 3.14;
/**
Modules
**/
module circular_mirror(x=0, y=0, d, steps) {
aps = 360 / steps;
for (step=[0:steps]) {
current_angle = step * aps;
unit_x = cos(current_angle);
unit_y = sin(current_angle);
translate([x, y, 0]) {
translate([unit_x * d, unit_y * d, 0]) {
rotate(current_angle) children();
}
}
}
}
// This is a hexagon, but radius is the distance
// from the center point to the middle of a side.
// (rather than to a pointy end) which mimics fusion.
module hexagon(r) {
rotate(90) circle($fn=6, r=r * 1.125);
}
// Mirror in 4 directions
module quadruple_mirror() {
children();
mirror([-1, 0, 0]) children();
mirror([0, -1, 0]) children();
mirror([-1, 0, 0]) mirror([0, -1, 0]) children();
}
// Splat children elements equidistance "count" times along
// a particular vector (x, y, and/or z) over some distance (d)
module splat(d, count, x=false, y=false, z=false) {
step_distance=d / (count - 1);
for (step=[0:count - 1]) {
move = step * step_distance;
translate([x ? move : 0, y ? move : 0, z ? move : 0])
children();
}
}
$fn = 100;
r = 6.1;
buffer = 1.25;
linear_extrude(2.75)
difference() {
od = r + buffer;
circle(d=od);
translate([0,od/2,0])
square([3,od], center=true);
circle(d=r);
}
include <openfusion.scad>
tol = .2;
od = 16;
h = 14;
bore_size = 6.2;
module bore(h) {
linear_extrude(height=h)
circle(d=bore_size);
}
module interface(h) {
// M6 hexnut
hex_nut_dia = 9.9 + tol;
hex_nut_depth = 5.65 + tol;
translate([0,0,0])
linear_extrude(height=hex_nut_depth)
hexagon(hex_nut_dia/2);
bore(h);
}
module spacer(bore_size, h) {
difference() {
linear_extrude(h)
circle(d=7.75);
linear_extrude(h)
circle(d=4);
bore(bore_size);
}
}
union() {
//translate([0, 0, h])
//spacer(bore_size, 1);
difference() {
linear_extrude(h)
circle(d=od);
interface(h);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment