Scotch Yoke

A Scotch yoke that drives a piston in a cutaway cylinder. The crank pin carries a bronze block in the slot of the yoke, so the yoke and the piston move by the sine law: the throw times the cosine of the crank angle. The kernel bounds of the piston agree with that law. The 6202 bearings, the LM12 linear bushings and the M6 screws are published sizes: each screw is a true helix in a tapped hole of the base. The frame, the crank and the pump are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
ts
import { box, cut, cutAll, cylinder, extrude, fuseAll, getBounds, line, loft, polygon, revolve, rotate, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Scotch yoke that drives a piston. The crank axis is X, the yoke slides along Y, units are millimetres.
// The bearings, the linear bushings and the M6 screws with their thread are published sizes. The frame, the crank and the pump are a display model.
interface YokeParams {
angle?: number; // crank angle in degrees. 0 is top dead centre of the piston.
throw?: number; // crank radius, 15 to 25. The stroke is two times the throw.
cutaway?: boolean; // cut the cylinder to show the piston
}
type P2 = [number, number];
type P3 = [number, number, number];
type Shape = ReturnType<typeof cylinder>;
// Kernel shapes live in WASM memory. Every temporary goes through own(). freeing() runs a build and then frees them all.
const owned: { delete(): void }[] = [];
const own = <T extends { delete(): void }>(s: T): T => {
owned.push(s);
return s;
};
const freeing = <T,>(build: () => T): T => { try { return build(); } finally { owned.splice(0).forEach((s) => s.delete()); } }; // also when the build throws
// ---- published figures
const BEARING = { bore: 15, od: 35, width: 11 }; // 6202 deep-groove ball bearing
const BUSHING = { bore: 12, od: 21, length: 30 }; // LM12 linear ball bushing
const CAP_M6 = { d: 6, minor: 4.917, pitch: 1, head: 10, k: 6, hex: 5 }; // socket head cap screw, ISO coarse thread, right-hand
// ---- display model
const H = 70; // height of the crank axis and of the rods
const DISC = { r: 42, x0: -12, x1: -2 };
const PIN = { d: 10, flange: 8 };
const YOKE = { x0: 0, x1: 10, block: 20, wall: 12, left: 90, right: 98 }; // plate, slider block, rod lengths
const GUIDE = { y0: 52, half: 22 };
const HOUSING = { x0: -52, x1: -14, half: 26 };
const PISTON = { r: 16, length: 22, ring: 2 };
const CYLINDER = { y0: 84, y1: 164, wall: 5, head: 8 };
const ROD_X = (YOKE.x0 + YOKE.x1) / 2;
const SCREW = { length: 16, seat: 10, play: 0.08 }; // M6 x 16 on a 10 mm flange: 6 mm in the base. play is the radial thread clearance
const bx = (x0: number, x1: number, y0: number, y1: number, z0: number, z1: number): Shape =>
own(box(x1 - x0, y1 - y0, z1 - z0, { at: [(x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2] }));
// A closed (x, r) profile, revolved about the crank axis.
const latheX = (pts: P2[]): Shape =>
own(translate(own(unwrap(revolve(own(unwrap(polygon(pts.map(([x, r]): P3 => [x, r, 0])))), { axis: [1, 0, 0] }))), [0, 0, H]) as Shape);
// A closed (r, y) profile, revolved about the rod axis.
const latheY = (pts: P2[]): Shape =>
own(translate(own(unwrap(revolve(own(unwrap(polygon(pts.map(([r, y]): P3 => [r, y, 0])))), { axis: [0, 1, 0] }))), [ROD_X, 0, H]) as Shape);
const ringX = (r0: number, r1: number, x0: number, x1: number): Shape => latheX([[x0, r0], [x1, r0], [x1, r1], [x0, r1]]);
const ringY = (r0: number, r1: number, y0: number, y1: number): Shape => latheY([[r0, y0], [r1, y0], [r1, y1], [r0, y1]]);
const alongX = (r: number, x0: number, x1: number, y = 0, z = H): Shape => own(cylinder(r, x1 - x0, { at: [x0, y, z], axis: [1, 0, 0] }));
const alongY = (r: number, y0: number, y1: number): Shape => own(cylinder(r, y1 - y0, { at: [ROD_X, y0, H], axis: [0, 1, 0] }));
const up = (r: number, z0: number, z1: number, x: number, y: number): Shape => own(cylinder(r, z1 - z0, { at: [x, y, z0] }));
const fused = (parts: Shape[]): Shape => own(unwrap(fuseAll(parts))) as Shape;
const minus = (s: Shape, tools: Shape[]): Shape => own(unwrap(cutAll(s, tools))) as Shape;
const keep = (s: Shape): Shape => translate(s, [0, 0, 0]) as Shape; // a copy that the build does not free
// One helical thread tooth about Z, from z0 to z1. Its crest passes the +X side at z = ref.
// tip > core is the thread of a screw on a core. tip < core is the thread in a bore: ref is half a pitch away.
// The loft is smooth, so each flank is one helical face. A long loft drifts off the helix: a long thread is pieces of 4 turns.
const SECTIONS = 12; // sections of the loft in each turn
const SLACK = 0.998; // keeps the tooth of a screw a hair clear of its core
const BORE_SLACK = 0.99; // and the tooth in a bore clear of the wall
const helixTooth = (core: number, tip: number, pitch: number, z0: number, z1: number, ref: number): Shape[] => {
const root = tip > core ? core / SLACK : core * BORE_SLACK;
const crest = tip > core ? tip : tip / SLACK;
const half = 0.42 * pitch;
const piece = (from: number, to: number): Shape => {
const n = Math.max(2, Math.round(((to - from) / pitch) * SECTIONS));
const sections = Array.from({ length: n + 1 }, (_, j) => {
const z = from + ((to - from) * j) / n;
const a = 2 * Math.PI * ((z - ref) / pitch);
const at = (r: number, dz: number): P3 => [r * Math.cos(a), r * Math.sin(a), z + dz];
const pts = [at(root, -half), at(crest, 0), at(root, half)];
return own(unwrap(wire(pts.map((p, i) => own(line(p, pts[(i + 1) % 3]!))))));
});
return unwrap(loft(sections, { ruled: false })) as Shape;
};
const count = Math.max(1, Math.ceil((z1 - z0) / (4 * pitch) - 0.001));
const pieces = Array.from({ length: count }, (_, i) => piece(z0 + ((z1 - z0) * i) / count, z0 + ((z1 - z0) * (i + 1)) / count));
return pieces;
};
// A socket head cap screw along Z, with the bottom of the head at z = 0: the body, then the pieces of its thread.
const capScrew = (length: number): Shape[] => {
const r = CAP_M6.hex / Math.sqrt(3);
const hex = own(unwrap(polygon(Array.from({ length: 6 }, (_, i): P3 => [r * Math.cos((i * Math.PI) / 3), r * Math.sin((i * Math.PI) / 3), CAP_M6.k - 3.3]))));
const body = minus(fused([own(cylinder(CAP_M6.head / 2, CAP_M6.k)), own(cylinder(CAP_M6.minor / 2, length, { at: [0, 0, -length] }))]), [own(unwrap(extrude(hex, 4))) as Shape]);
return [body, ...helixTooth(CAP_M6.minor / 2, CAP_M6.d / 2, CAP_M6.pitch, -length + 0.45, -0.45, 0).map(own)];
};
function scotchYoke({ angle = 55, throw: radius = 20, cutaway = true }: YokeParams = {}) {
const R = Math.min(Math.max(radius, 15), 25);
const a = (angle * Math.PI) / 180;
const y = R * Math.cos(a); // the law of the yoke: a pure sine motion
const z = R * Math.sin(a); // the slider block moves in the slot by the other component
const moved = (s: Shape): Shape => translate(s, [0, y, 0]) as Shape;
const screw = capScrew(SCREW.length);
const screws: Shape[] = [];
const holes = (at: P2[]): Shape[] => at.map(([sx, sy]) => { screws.push(...screw.map((s) => translate(s, [sx, sy, SCREW.seat]) as Shape)); return up(CAP_M6.d / 2 + 0.3, -4, 11, sx, sy); });
// Base plate. Each screw goes 6 mm into a tapped hole. The thread of the hole is half a pitch from the thread of the screw.
const reach = CYLINDER.y1 + CYLINDER.head + 12;
const allScrews: P2[] = [[-33, -35], [-33, 35], ...[-GUIDE.y0 - 15, GUIDE.y0 + 15, 124].flatMap((gy): P2[] => [[ROD_X - 30, gy], [ROD_X + 30, gy]])];
const base = minus(bx(-62, 48, -GUIDE.y0 - BUSHING.length - 10, reach, -12, 0), allScrews.map(([sx, sy]) => up(CAP_M6.d / 2 + SCREW.play, SCREW.seat - SCREW.length - 1, 1, sx, sy)));
const tap = helixTooth(CAP_M6.d / 2 + SCREW.play, CAP_M6.minor / 2 + SCREW.play, CAP_M6.pitch, SCREW.seat - SCREW.length - 0.5, -0.45, CAP_M6.pitch / 2).map(own);
const taps = allScrews.flatMap(([sx, sy]) => tap.map((s) => translate(s, [sx, sy, 0]) as Shape));
// Bearing housing with two 6202 bearings. Each bearing is an outer ring, an inner ring and a seal.
const housing = minus(fused([bx(HOUSING.x0, HOUSING.x1, -HOUSING.half, HOUSING.half, 0, H), alongX(HOUSING.half, HOUSING.x0, HOUSING.x1), bx(HOUSING.x0, HOUSING.x1, -42, 42, 0, 10)]), [
alongX(BEARING.od / 2, HOUSING.x0 - 1, HOUSING.x0 + BEARING.width),
alongX(BEARING.od / 2, HOUSING.x1 - BEARING.width, HOUSING.x1 + 1),
alongX(BEARING.od / 2 - 3, HOUSING.x0, HOUSING.x1),
...holes([[-33, -35], [-33, 35]]),
]);
const bearings = [HOUSING.x0, HOUSING.x1 - BEARING.width].map((x0) => ({
outer: keep(ringX(BEARING.od / 2 - 3, BEARING.od / 2, x0, x0 + BEARING.width)),
inner: keep(ringX(BEARING.bore / 2, BEARING.bore / 2 + 3, x0, x0 + BEARING.width)),
seal: keep(ringX(BEARING.bore / 2 + 3, BEARING.od / 2 - 3, x0 + 1, x0 + BEARING.width - 1)),
}));
// Crank: a shaft, a disc with holes that balance the pin, the pin and a bronze slider block.
const turn = (s: Shape): Shape => rotate(s, angle, { at: [0, 0, H], axis: [1, 0, 0] }) as Shape;
const shaft = turn(latheX([[-84, 0], [-84, 6.5], [-83, 7.5], [DISC.x1, 7.5], [DISC.x1, 0]]));
const lighten = [100, 140, 180, 220, 260].map((d) => alongX(7, DISC.x0 - 1, DISC.x1 + 1, 29 * Math.cos((d * Math.PI) / 180), H + 29 * Math.sin((d * Math.PI) / 180)));
const disc = turn(minus(alongX(DISC.r, DISC.x0, DISC.x1), [alongX(BEARING.bore / 2, DISC.x0 - 1, DISC.x1 + 1), alongX(PIN.d / 2, DISC.x0 - 1, DISC.x1 + 1, R), ...lighten]));
const tipX = YOKE.x1 + 2;
const pin = translate(latheX([[DISC.x0, 0], [DISC.x0, PIN.d / 2], [YOKE.x1, PIN.d / 2], [YOKE.x1, PIN.flange], [tipX, PIN.flange], [tipX, 0]]), [0, y, z]) as Shape;
const b = YOKE.block / 2;
const block = translate(minus(bx(YOKE.x0, YOKE.x1, -b, b, H - b, H + b), [alongX(PIN.d / 2, YOKE.x0 - 1, YOKE.x1 + 1)]), [0, y, z]) as Shape;
// Yoke: a slotted plate and two rods. The right rod ends in the piston.
const w = b + YOKE.wall;
const tall = 25 + b + 4 + YOKE.wall;
const crown = w + YOKE.right + PISTON.length - 8; // from the yoke centre to the piston crown
const yoke = moved(minus(fused([bx(YOKE.x0, YOKE.x1, -w, w, H - tall, H + tall), alongY(BUSHING.bore / 2, -w - YOKE.left, w + YOKE.right)]), [
bx(YOKE.x0 - 1, YOKE.x1 + 1, -b, b, H - 25 - b - 4, H + 25 + b + 4),
]));
const groove = (g: number): P2[] => [[PISTON.r, g], [PISTON.r - 2, g], [PISTON.r - 2, g + PISTON.ring], [PISTON.r, g + PISTON.ring]];
const rings = [crown - 11, crown - 6];
const piston = moved(minus(latheY([[0, crown - PISTON.length], [PISTON.r, crown - PISTON.length], ...rings.flatMap(groove), [PISTON.r, crown], [0, crown]]), [
alongY(BUSHING.bore / 2, crown - PISTON.length - 1, crown - PISTON.length + 8),
]));
const pistonRings = rings.map((g) => moved(ringY(PISTON.r - 2, PISTON.r, g, g + PISTON.ring)));
// Rod guides: a block with a linear bushing on each side of the crank.
const guides = [-GUIDE.y0 - BUSHING.length, GUIDE.y0].map((y0) => {
const mid = y0 + BUSHING.length / 2;
const blank = fused([bx(ROD_X - GUIDE.half, ROD_X + GUIDE.half, y0, y0 + BUSHING.length, 0, H), alongY(GUIDE.half, y0, y0 + BUSHING.length), bx(ROD_X - 40, ROD_X + 40, y0, y0 + BUSHING.length, 0, 10)]);
return {
block: keep(minus(blank, [alongY(BUSHING.od / 2, y0 - 1, y0 + BUSHING.length + 1), ...holes([[ROD_X - 30, mid], [ROD_X + 30, mid]])])),
bushing: keep(ringY(BUSHING.bore / 2, BUSHING.od / 2, y0, y0 + BUSHING.length)),
};
});
// Cylinder: a finned barrel with a head and a port, on a foot.
const { y0, y1, wall, head } = CYLINDER;
const ro = PISTON.r + wall;
const fins: P2[] = [];
for (let f = y0 + 30; f < y1 - 4; f += 8) fins.push([ro, f], [ro + 7, f], [ro + 7, f + 3], [ro, f + 3]);
const barrel = latheY([[PISTON.r, y0], [ro, y0], ...fins, [ro, y1], [ro + 7, y1], [ro + 7, y1 + head], [3, y1 + head], [3, y1], [PISTON.r, y1]]);
const foot = minus(fused([bx(ROD_X - 14, ROD_X + 14, y0 + 30, y1 - 10, 0, H - PISTON.r - 2), bx(ROD_X - 40, ROD_X + 40, 114, 134, 0, 10)]), holes([[ROD_X - 30, 124], [ROD_X + 30, 124]]));
const whole = fused([barrel, foot]);
const cylinderBody = cutaway ? (unwrap(cut(whole, bx(ROD_X, ROD_X + 60, y0 - 1, y1 + head + 1, 10, H + 60))) as Shape) : keep(whole);
const top = getBounds(piston).yMax; // the kernel position of the piston crown
return { base: keep(base), housing: keep(housing), bearings, shaft, disc, pin, block, yoke, piston, pistonRings, guides, cylinderBody, screws, taps, stroke: 2 * R, law: R - y, below: R + crown - top };
}
const part = freeing(() => scotchYoke());
console.log('Stroke: ' + part.stroke.toFixed(0) + ' mm. The sine law puts the piston ' + part.law.toFixed(2) + ' mm below top dead centre.');
console.log('The kernel bounds of the piston give ' + part.below.toFixed(2) + ' mm.');
export default [
color(part.base, '#48515c'),
...part.taps.map((s) => color(s, '#48515c')),
color(part.housing, '#12b5b0'),
...part.guides.map((g) => color(g.block, '#12b5b0')),
color(part.cylinderBody, '#12b5b0'),
...part.bearings.flatMap((g) => [color(g.outer, '#c3c9d1'), color(g.inner, '#c3c9d1'), color(g.seal, '#22262c')]),
...part.guides.map((g) => color(g.bushing, '#c3c9d1')),
color(part.shaft, '#c3c9d1'),
color(part.disc, '#f5f2ea'),
color(part.pin, '#c3c9d1'),
color(part.block, '#d3a956'),
color(part.yoke, '#ff5a1f'),
color(part.piston, '#c3c9d1'),
...part.pistonRings.map((s) => color(s, '#22262c')),
...part.screws.map((s) => color(s, '#22262c')),
];Functions used
box cut cutAll cylinder extrude fuseAll getBounds line loft polygon revolve rotate translate unwrap wire color