2025-04-17 17:22:19 -07:00
|
|
|
@(lengthUnit = m)
|
|
|
|
import "../../e2e/executor/inputs/2-5-long-m8-chc-screw.stl" as screw
|
|
|
|
|
|
|
|
// Set units
|
|
|
|
@settings(defaultLengthUnit = mm)
|
|
|
|
|
|
|
|
myScrew = screw
|
|
|
|
|
|
|
|
|
|
|
|
surface001 = startSketchOn(XY)
|
|
|
|
|
|
|
|
// Define parameters
|
|
|
|
nTeeth = 21
|
|
|
|
module = 0.5
|
|
|
|
pitchDiameter = module * nTeeth
|
|
|
|
pressureAngle = 20
|
|
|
|
addendum = module
|
|
|
|
deddendum = 1.25 * module
|
2025-04-30 12:40:11 +12:00
|
|
|
baseDiameter = pitchDiameter * math::cos(pressureAngle)
|
2025-04-17 17:22:19 -07:00
|
|
|
tipDiameter = pitchDiameter + 2 * module
|
|
|
|
gearHeight = 3
|
|
|
|
|
|
|
|
// Interpolate points along the involute curve
|
|
|
|
cmo = 101
|
2025-04-25 19:09:03 -05:00
|
|
|
rs = map([0..cmo], f = fn(i) {
|
2025-04-17 17:22:19 -07:00
|
|
|
return baseDiameter / 2 + i / cmo * (tipDiameter - baseDiameter) / 2
|
|
|
|
})
|
|
|
|
|
|
|
|
// Calculate operating pressure angle
|
2025-04-25 19:09:03 -05:00
|
|
|
angles = map(rs, f = fn(r) {
|
2025-04-30 15:59:19 +12:00
|
|
|
return units::toDegrees( math::acos(baseDiameter / 2 / r))
|
2025-04-17 17:22:19 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
// Calculate the involute function
|
2025-04-25 19:09:03 -05:00
|
|
|
invas = map(angles, f = fn(a) {
|
2025-04-30 12:40:11 +12:00
|
|
|
return math::tan(units::toRadians(a)) - units::toRadians(a)
|
2025-04-17 17:22:19 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
// Map the involute curve
|
2025-04-25 19:09:03 -05:00
|
|
|
xs = map([0..cmo], f = fn(i) {
|
2025-04-30 12:40:11 +12:00
|
|
|
return rs[i] * math::cos(invas[i]: number(rad))
|
2025-04-17 17:22:19 -07:00
|
|
|
})
|
|
|
|
|
2025-04-25 19:09:03 -05:00
|
|
|
ys = map([0..cmo], f = fn(i) {
|
2025-04-30 12:40:11 +12:00
|
|
|
return rs[i] * math::sin(invas[i]: number(rad))
|
2025-04-17 17:22:19 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
// Extrude the gear body
|
|
|
|
body = startSketchOn(XY)
|
|
|
|
|> circle(center = [0, 0], radius = baseDiameter / 2)
|
|
|
|
|> extrude(length = gearHeight)
|
|
|
|
|
|
|
|
toothAngle = 360 / nTeeth / 1.5
|
|
|
|
|
|
|
|
// Plot the involute curve
|
|
|
|
fn leftInvolute(i, sg) {
|
|
|
|
j = 100 - i // iterate backwards
|
|
|
|
return line(sg, endAbsolute = [xs[j], ys[j]])
|
|
|
|
}
|
|
|
|
|
|
|
|
fn rightInvolute(i, sg) {
|
2025-04-30 15:59:19 +12:00
|
|
|
x = rs[i] * math::cos(-toothAngle + units::toDegrees(math::atan(ys[i] / xs[i])))
|
|
|
|
y = -rs[i] * math::sin(-toothAngle + units::toDegrees(math::atan(ys[i] / xs[i])))
|
2025-04-17 17:22:19 -07:00
|
|
|
return line(sg, endAbsolute = [x, y])
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw gear teeth
|
|
|
|
start = startSketchOn(XY)
|
2025-04-25 16:01:35 -05:00
|
|
|
|> startProfile(at = [xs[101], ys[101]])
|
2025-04-25 19:09:03 -05:00
|
|
|
teeth = reduce([0..100], initial = start, f = leftInvolute)
|
2025-04-18 17:40:44 -05:00
|
|
|
|> arc(
|
2025-04-17 17:22:19 -07:00
|
|
|
angleStart = 0,
|
|
|
|
angleEnd = toothAngle,
|
2025-04-18 17:40:44 -05:00
|
|
|
radius = baseDiameter / 2,
|
|
|
|
)
|
2025-04-25 19:09:03 -05:00
|
|
|
|> reduce([1..101], initial = %, f = rightInvolute)
|
2025-04-17 17:22:19 -07:00
|
|
|
|> close()
|
|
|
|
|> extrude(length = gearHeight)
|
|
|
|
|> patternCircular3d(
|
|
|
|
axis = [0, 0, 1],
|
|
|
|
center = [0, 0, 0],
|
|
|
|
instances = nTeeth,
|
|
|
|
arcDegrees = 360,
|
|
|
|
rotateDuplicates = true,
|
|
|
|
)
|
|
|
|
|
|
|
|
// Define the constants of the keyway and the bore hole
|
|
|
|
keywayWidth = 0.250
|
|
|
|
keywayDepth = keywayWidth / 2
|
|
|
|
holeDiam = 2
|
|
|
|
holeRadius = 1
|
2025-04-30 15:59:19 +12:00
|
|
|
startAngle = math::asin(keywayWidth / 2 / holeRadius)
|
2025-04-17 17:22:19 -07:00
|
|
|
|
|
|
|
// Sketch the keyway and center hole and extrude
|
|
|
|
keyWay = startSketchOn(body, face = END)
|
2025-04-30 12:40:11 +12:00
|
|
|
|> startProfile(at = [holeRadius * math::cos(startAngle), holeRadius * math::sin(startAngle)])
|
2025-04-17 17:22:19 -07:00
|
|
|
|> xLine(length = keywayDepth)
|
|
|
|
|> yLine(length = -keywayWidth)
|
|
|
|
|> xLine(length = -keywayDepth)
|
2025-04-18 17:40:44 -05:00
|
|
|
|> arc(
|
2025-04-29 08:41:31 +12:00
|
|
|
angleStart = -1 * units::toDegrees(startAngle) + 360,
|
2025-04-18 17:40:44 -05:00
|
|
|
angleEnd = 180,
|
|
|
|
radius = holeRadius,
|
|
|
|
)
|
|
|
|
|> arc(
|
2025-04-17 17:22:19 -07:00
|
|
|
angleStart = 180,
|
2025-04-29 08:41:31 +12:00
|
|
|
angleEnd = units::toDegrees(startAngle),
|
2025-04-18 17:40:44 -05:00
|
|
|
radius = holeRadius,
|
|
|
|
)
|
2025-04-17 17:22:19 -07:00
|
|
|
|> close()
|
|
|
|
|> extrude(length = -gearHeight)
|
|
|
|
|
|
|
|
myScrew
|
|
|
|
|> translate(y=10)
|