Rack & Pinion

A module 2 rack and pinion drive: an 18-tooth involute pinion in fixed bearings moves a rack on a linear guide by the pitch radius times the pinion angle, 113.1 mm for each turn. The gear, the rack section and its bolt holes, the size 15 guide, the 6201 bearings and the screw threads are catalogue sizes. The cap screws and the set screw have true helical threads in tapped holes. The kernel measures the pinion at 184 g against 190 g in the catalogue, and the full 80-tooth rack at 1.76 kg against 1.78 kg. The slide, the bearing stand and the motor are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
import { box, compound, cutAll, cylinder, extrude, fuseAll, line, loft, makeExternalGear, measureVolume, polygon, revolve, rotate, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Rack and pinion drive, module 2. The pinion turns in fixed bearings and moves a slide that carries the rack.
// The pinion axis is X, the rack moves along Y, units are millimetres. Z = 0 is the bottom of the rack.
// The gear, the rack section, the guide, the bearings and the screw threads are catalogue sizes. The frame and the motor are a display model.
interface DriveParams {
angle?: number; // pinion angle in degrees. The rack moves by the pitch radius times this angle.
rackTeeth?: number; // teeth of the cut length of rack, an even count from 28 to 36. The catalogue rack has 80.
}
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 MODULE = 2;
const PRESSURE = 20; // degrees
const PINION = { teeth: 18, bore: 12, hub: 30, face: 20, hubWidth: 10, grams: 190 }; // steel spur gear with a hub
const RACK = { teeth: 80, face: 20, height: 25, pitchLine: 23, holeAt: 26.33, holePitch: 150, holeZ: 10, hole: 7, cbore: 11, cboreDepth: 7, kg: 1.78 }; // steel rack with bolt holes
const CAP_M6 = { d: 6, minor: 4.917, pitch: 1, head: 10, k: 6, hex: 5, clear: 6.6 }; // socket head cap screw, metric coarse thread, right hand
const GRUB_M5 = { d: 5, minor: 4.134, pitch: 0.8, hex: 2.5, length: 8 }; // socket set screw with a flat point
const BEARING = { bore: 12, od: 32, width: 10 }; // 6201 deep-groove ball bearing
const GUIDE = { rail: 15, railH: 15, block: 34, blockL: 61.4, bodyL: 39.4, height: 28, gap: 4.3, holePitch: 60, cbore: 7.5, cboreDepth: 5.3 }; // size 15 linear guide
const STEEL = 7.85e-3; // grams per cubic millimetre
// ---- display model
const PITCH = Math.PI * MODULE;
const R = (MODULE * PINION.teeth) / 2; // pitch radius
const AXIS = RACK.pitchLine + R; // height of the pinion axis
const BACKLASH = 0.05; // each flank of the rack is thinner by this
const BEAM = { x0: -30, z0: -8, z1: 20 }; // the slide that carries the rack
const FLOOR = BEAM.z0 - GUIDE.height; // top of the base plate
const STAND = { x0: -78, x1: -38, half: 24 };
const MOTOR = { size: 56, length: 58 };
const PLAY = 0.08; // radial play between a screw thread and its tapped hole
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 (y, z) profile, extruded from x0 to x1.
const prism = (pts: P2[], x0: number, x1: number): Shape =>
own(unwrap(extrude(own(unwrap(polygon(pts.map(([y, z]): P3 => [x0, y, z])))), [x1 - x0, 0, 0]))) as Shape;
// A ring about the pinion axis.
const ring = (r0: number, r1: number, x0: number, x1: number): Shape =>
own(translate(own(unwrap(revolve(own(unwrap(polygon([[x0, r0, 0], [x1, r0, 0], [x1, r1, 0], [x0, r1, 0]]))), { axis: [1, 0, 0] }))), [0, 0, AXIS]) as Shape);
const alongX = (r: number, x0: number, x1: number, y = 0, z = AXIS): Shape => own(cylinder(r, x1 - x0, { at: [x0, y, z], axis: [1, 0, 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 group = (parts: Shape[]): Shape => compound(parts) as Shape;
const volume = (s: Shape): number => unwrap(measureVolume(s));
// One helical thread tooth about +Z, with its crest from z = from to z = to. Its crest passes the +X side at z = ref.
// The tooth is a row of smooth lofts of 4 turns or less, end to end on one helix: a long loft is slow to mesh.
// tip > core is the thread of a screw on a core of that radius. tip < core is the thread in a bore.
const SECTIONS = 12; // loft sections in each turn
const SLACK = 0.998; // keeps the tooth a hair clear of its core or its bore
const helixTooth = (core: number, tip: number, pitch: number, from: number, to: number, ref: number): Shape => {
const root = tip > core ? core / SLACK : core * SLACK;
const crest = tip > core ? tip : tip / SLACK;
const half = 0.42 * pitch;
const start = from, span = to - from, pieces = Math.ceil(span / (4 * pitch));
const n = Math.max(2, Math.round((span / pieces / pitch) * SECTIONS)); // sections in each piece
const section = (z: number) => {
const a = (2 * Math.PI * (z - ref)) / pitch;
const pts = [[root, -half], [crest, 0], [root, half]].map(([r, dz]): P3 => [r! * Math.cos(a), r! * Math.sin(a), z + dz!]);
return own(unwrap(wire(pts.map((q, i) => own(line(q, pts[(i + 1) % 3]!))))));
};
const lofts = Array.from({ length: pieces }, (_, k) => own(unwrap(loft(Array.from({ length: n + 1 }, (_, j) => section(start + (span * (k + j / n)) / pieces)), { ruled: false }))));
return own(compound(lofts)) as Shape;
};
// The thread of a screw between two heights, and the mating thread of its tapped hole, half a pitch out of phase.
type Thread = { d: number; minor: number; pitch: number };
const screwTooth = (m: Thread, z0: number, z1: number): Shape => helixTooth(m.minor / 2, m.d / 2, m.pitch, z0 + 0.42 * m.pitch, z1 - 0.42 * m.pitch, 0);
const holeTooth = (m: Thread, z0: number, z1: number): Shape => helixTooth(m.d / 2 + PLAY, m.minor / 2 + PLAY, m.pitch, z0 + 0.42 * m.pitch, z1 - 0.42 * m.pitch, m.pitch / 2);
const hexPrism = (flats: number, z0: number, height: number): Shape => {
const r = flats / 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), z0]))));
return own(unwrap(extrude(hex, height))) as Shape;
};
// A socket head cap screw along -Z, with the bottom of the head at z = 0. It has thread on its full length.
const capScrew = (s: typeof CAP_M6, length: number): Shape => {
const body = minus(fused([own(cylinder(s.head / 2, s.k)), own(cylinder(s.minor / 2, length, { at: [0, 0, -length] }))]), [hexPrism(s.hex, s.k * 0.45, s.k)]);
return own(group([body, screwTooth(s, -length, 0)]));
};
// The basic rack: straight flanks at the pressure angle, a tooth space at y = 0, and the bolt holes.
const rackBar = (teeth: number): { bar: Shape; holes: number[] } => {
const slope = Math.tan((PRESSURE * Math.PI) / 180);
const tip = PITCH / 4 - BACKLASH - (RACK.height - RACK.pitchLine) * slope;
const root = PITCH / 4 - BACKLASH + 1.25 * MODULE * slope;
const zRoot = RACK.pitchLine - 1.25 * MODULE;
const end = (teeth * PITCH) / 2;
const pts: P2[] = [[-end, 0], [-end, zRoot]];
for (let k = 0; k < teeth; k++) {
const c = -end + (k + 0.5) * PITCH;
pts.push([c - root, zRoot], [c - tip, RACK.height], [c + tip, RACK.height], [c + root, zRoot]);
}
const holes: number[] = [];
for (let h = -end + RACK.holeAt; h < end - 20; h += RACK.holePitch) holes.push(h);
const bar = minus(prism([...pts, [end, zRoot], [end, 0]], 0, RACK.face), holes.flatMap((h) => [
alongX(RACK.hole / 2, -1, RACK.face + 1, h, RACK.holeZ),
alongX(RACK.cbore / 2, RACK.face - RACK.cboreDepth, RACK.face + 1, h, RACK.holeZ),
]));
return { bar, holes };
};
function drive({ angle = 35, rackTeeth = 32 }: DriveParams = {}) {
const teeth = 2 * Math.round(Math.min(Math.max(rackTeeth, 28), 36) / 2); // even, so a gap is at the middle of the rack
const half = (teeth * PITCH) / 2;
const limit = (half - 47) / R; // radians of pinion angle to the end of the travel
const theta = Math.min(Math.max((angle * Math.PI) / 180, -limit), limit);
const travel = R * theta; // the law of the drive
const moved = (s: Shape): Shape => own(translate(s, [0, travel, 0]) as Shape);
// Pinion: an involute gear with a hub. The catalogue mass is for this shape.
const gear = own(unwrap(makeExternalGear({ teeth: PINION.teeth, moduleSize: MODULE, thickness: PINION.face, pressureAngleDeg: PRESSURE, bore: PINION.bore })).solid);
const blank = fused([own(translate(own(rotate(gear, 90, { axis: [0, 1, 0] })), [0, 0, AXIS]) as Shape), ring(PINION.bore / 2, PINION.hub / 2, PINION.face - 0.5, PINION.face + PINION.hubWidth)]);
const grams = volume(blank) * STEEL;
const grubX = PINION.face + PINION.hubWidth / 2;
const turn = (s: Shape): Shape => rotate(s, (theta * 180) / Math.PI, { at: [0, 0, AXIS], axis: [1, 0, 0] }) as Shape;
// The set screw: M5 x 8 in a tapped hole of the hub, with its flat point on the shaft.
const g0 = AXIS + PINION.bore / 2;
const g1 = g0 + GRUB_M5.length;
const inHub = (s: Shape): Shape => turn(own(translate(s, [grubX, 0, 0]) as Shape));
const pinion = group([own(turn(minus(blank, [up(GRUB_M5.d / 2 + PLAY + 0.02, AXIS, AXIS + 20, grubX, 0)]))), own(inHub(holeTooth(GRUB_M5, g0, AXIS + PINION.hub / 2 - 0.3)))]);
const grub = inHub(own(group([minus(up(GRUB_M5.minor / 2, g0, g1, 0, 0), [hexPrism(GRUB_M5.hex, g1 - 2.5, 4)]), screwTooth(GRUB_M5, g0, g1)])));
const shaft = turn(alongX(PINION.bore / 2, STAND.x0 - 7, PINION.face + PINION.hubWidth + 3));
// Rack: the kernel measures the full catalogue length, and the model shows a cut length.
const full = rackBar(RACK.teeth);
const rackKg = (volume(full.bar) * STEEL) / 1000;
const cut = rackBar(teeth);
const rack = translate(cut.bar, [0, travel, 0]) as Shape;
// M6 x 20 screws hold the rack on the beam. The beam has the mating thread, 7 mm engaged.
const seatX = RACK.face - RACK.cboreDepth;
const inRack = (s: Shape, h: number): Shape => moved(own(translate(own(rotate(s, 90, { axis: [0, 1, 0] })), [seatX, h, RACK.holeZ]) as Shape)); // head toward +X
const rackScrew = capScrew(CAP_M6, 20);
const rackScrews = cut.holes.map((h) => inRack(rackScrew, h));
const beamTooth = holeTooth(CAP_M6, -seatX - 9.5, -seatX);
// Slide: a beam on two guide blocks. The blocks run on a fixed rail.
const beam = group([moved(minus(bx(BEAM.x0, 0, -half, half, BEAM.z0, BEAM.z1), cut.holes.map((h) => alongX(CAP_M6.d / 2 + PLAY, -10, 1, h, RACK.holeZ)))), ...cut.holes.map((h) => inRack(beamTooth, h))]);
const mid = BEAM.x0 / 2;
const w = GUIDE.block / 2;
const top = BEAM.z0;
const low = top - GUIDE.height + GUIDE.gap;
const railTop = FLOOR + GUIDE.railH;
const section: P3[] = [[-w, 0, low], [-w, 0, top], [w, 0, top], [w, 0, low], [GUIDE.rail / 2, 0, low], [GUIDE.rail / 2, 0, railTop], [-GUIDE.rail / 2, 0, railTop], [-GUIDE.rail / 2, 0, low]];
const block = (y0: number, y1: number): Shape => own(unwrap(extrude(own(unwrap(polygon(section.map(([x, , z]): P3 => [x + mid, y0, z])))), [0, y1 - y0, 0]))) as Shape;
const bodies = [-45, 45].map((c) => moved(block(c - GUIDE.bodyL / 2, c + GUIDE.bodyL / 2)));
const caps = [-45, 45].flatMap((c) => [moved(block(c - GUIDE.blockL / 2, c - GUIDE.bodyL / 2)), moved(block(c + GUIDE.bodyL / 2, c + GUIDE.blockL / 2))]);
const railHoles: Shape[] = [];
for (let h = -120; h <= 120; h += GUIDE.holePitch) railHoles.push(up(GUIDE.cbore / 2, railTop - GUIDE.cboreDepth, railTop + 1, mid, h));
const rail = minus(bx(mid - GUIDE.rail / 2, mid + GUIDE.rail / 2, -144, 144, FLOOR, railTop), railHoles);
// Bearing stand with two 6201 bearings, and the motor on its back face.
const feet: P2[] = [[-58, -34], [-58, 34]];
const stand = minus(fused([bx(STAND.x0, STAND.x1, -STAND.half, STAND.half, FLOOR, AXIS), alongX(STAND.half, STAND.x0, STAND.x1), bx(STAND.x0, STAND.x1, -42, 42, FLOOR, FLOOR + 10)]), [
alongX(BEARING.od / 2, STAND.x0 - 1, STAND.x0 + BEARING.width),
alongX(BEARING.od / 2, STAND.x1 - BEARING.width, STAND.x1 + 1),
alongX(BEARING.od / 2 - 3, STAND.x0, STAND.x1),
...feet.map(([x, y]) => up(CAP_M6.clear / 2, FLOOR - 1, FLOOR + 11, x, y)),
]);
const seats = [STAND.x0, STAND.x1 - BEARING.width];
const races = seats.flatMap((x0) => [ring(BEARING.od / 2 - 3, BEARING.od / 2, x0, x0 + BEARING.width), ring(BEARING.bore / 2, BEARING.bore / 2 + 3, x0, x0 + BEARING.width)]);
const seals = seats.map((x0) => ring(BEARING.bore / 2 + 3, BEARING.od / 2 - 3, x0 + 1, x0 + BEARING.width - 1));
// M6 x 16 screws hold the stand: 10 mm of foot, 6 mm in the tapped base.
const footScrew = capScrew(CAP_M6, 16);
const baseTooth = holeTooth(CAP_M6, -18.5, -10);
const atFoot = (s: Shape, [x, y]: P2): Shape => own(translate(s, [x, y, FLOOR + 10]) as Shape);
const footScrews = feet.map((f) => atFoot(footScrew, f));
const m = MOTOR.size / 2;
const motorX = STAND.x0 - 2;
const motor = fused([bx(motorX - MOTOR.length, motorX - 5, -m, m, AXIS - m, AXIS + m), alongX(m - 4, motorX - MOTOR.length - 12, motorX - MOTOR.length + 1)]);
const flange = minus(bx(motorX - 5, motorX, -m, m, AXIS - m, AXIS + m), [alongX(PINION.bore / 2, motorX - 6, motorX + 1)]);
const spacer = ring(BEARING.od / 2 - 3, 19, motorX, STAND.x0);
const base = group([minus(bx(-150, 30, -152, 152, FLOOR - 12, FLOOR), feet.map(([x, y]) => up(CAP_M6.d / 2 + PLAY, FLOOR - 9, FLOOR + 1, x, y))), ...feet.map((f) => atFoot(baseTooth, f))]);
return {
pinion, grub, shaft, rack, beam, base, stand: translate(stand, [0, 0, 0]) as Shape, rail: translate(rail, [0, 0, 0]) as Shape,
screws: group([...rackScrews, ...footScrews]), bodies: group(bodies), caps: group(caps), races: group([...races, spacer]), seals: group(seals),
motor: translate(motor, [0, 0, 0]) as Shape, flange: translate(flange, [0, 0, 0]) as Shape, travel, grams, rackKg,
};
}
const part = freeing(() => drive());
console.log('Travel: ' + part.travel.toFixed(2) + ' mm. One turn of the pinion moves the rack ' + (2 * Math.PI * R).toFixed(2) + ' mm.');
console.log('Pinion: ' + part.grams.toFixed(0) + ' g from the kernel volume. The catalogue has ' + PINION.grams + ' g.');
console.log('Rack with ' + RACK.teeth + ' teeth: ' + part.rackKg.toFixed(2) + ' kg from the kernel volume. The catalogue has ' + RACK.kg + ' kg.');
export default [
color(part.base, '#48515c'),
color(part.rail, '#c3c9d1'),
color(part.bodies, '#c3c9d1'),
color(part.caps, '#12b5b0'),
color(part.beam, '#f5f2ea'),
color(part.rack, '#c3c9d1'),
color(part.pinion, '#ff5a1f'),
color(part.grub, '#22262c'),
color(part.shaft, '#c3c9d1'),
color(part.stand, '#12b5b0'),
color(part.races, '#c3c9d1'),
color(part.seals, '#22262c'),
color(part.motor, '#22262c'),
color(part.flange, '#c3c9d1'),
color(part.screws, '#22262c'),
];Functions used
box compound cutAll cylinder extrude fuseAll line loft makeExternalGear measureVolume polygon revolve rotate translate unwrap wire color