Skip to content

Planetary Gear Reducer (25:1) ​

Planetary Gear Reducer (25:1), rendered in the brepjs playground
Mechanical · 265 lines▶ Run it in the playground

A two-stage 25:1 planetary gearbox for a NEMA 23 motor, in cutaway: each stage has a 12-tooth sun, three 18-tooth planets and a 48-tooth ring. The 60 mm frame, the lengths of the one-stage and two-stage units, the keyed 14 mm output shaft, the motor interface, the M5 threads and the bearing sizes are published figures. The input angle turns every gear by its tooth ratio, and the kernel measures the volume that the meshing teeth share (zero). The tapped holes and the clamp screw of the hub have true helical threads. The tooth counts and the parts inside the housing are a display model.

Code ​

This is the full program. The playground runs it in your browser without a change.

ts
import { box, compound, cone, cutAll, cylinder, extrude, fuseAll, intersect, makeExternalGear, line, loft, makeInternalGear, measureVolume, polygon, revolve, rotate, sphere, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';

// Planetary gearbox for a NEMA 23 motor, 60 mm frame, in cutaway. Built on the Z axis in millimetres, then laid down.
// The frame, the two shaft ends, the key and the bearing sizes are published figures. The tooth counts and
// all parts inside the housing are a display model. Each stage is 1 + 48/12 = 5:1.
interface GearboxParams {
  input?: number; // degrees of the motor shaft. All gears move by their tooth ratios.
  stages?: 1 | 2; // 5:1 or 25:1, the two lengths of the series
  cutaway?: number; // degrees of the housing to cut away (0 = closed gearbox)
}

type P2 = [number, number]; // [r, z]
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 (60 mm planetary gearbox series, NEMA 23 input)
const FRAME = 60; // body diameter and flange square
const LENGTH = { 1: 106, 2: 118.5 }; // motor face to the shaft end, for each stage count
const OUTPUT = { shaft: 14, length: 35, shoulder: 17, shoulderLength: 5, pilot: 40, pilotHeight: 2.5, corner: 80 };
const OUTPUT_HOLES = { circle: 52, thread: 5, depth: 8 }; // 4 x M5
const KEY = { width: 5, height: 5, length: 25, seat: 3 }; // DIN 6885 form A, seat depth in the shaft
const CENTRE_BORE = { thread: 5, depth: 12 };
const MOTOR = { shaft: 6.35, pilot: 38.1, pilotDepth: 3.3, circle: 66.7, thread: 5, depth: 10 };
const BEARING_OUT = { d: 17, D: 35, B: 10 }; // 6003
const BEARING_IN = { d: 20, D: 32, B: 7 }; // 61804
const SEAL = { d: 17, D: 35, B: 7 }; // radial shaft seal
const M5 = { major: 5, minor: 4.134, pitch: 0.8 }; // ISO metric coarse thread of the tapped holes, right-hand
const M3 = { major: 3, minor: 2.459, pitch: 0.5 }; // clamp screw of the hub

// ---- display model
const TEETH = { sun: 12, planet: 18, ring: 48 }; // ring = sun + 2 x planet
const MODULE = 1;
const PLANETS = 3;
const STAGE = LENGTH[2] - LENGTH[1]; // one more stage adds this length
const FACE = 8; // face width of the gears
const FLANGE = 18; // length of the motor flange
const HEAD = 37.5; // length of the output housing
const PIN = 2.5; // planet pin radius
const HOME = 60; // orbit angle of the first planet at input 0
const TAU = 2 * Math.PI;
const PLAY = 0.06; // radial clearance between the clamp screw and its thread

const turned = (s: Shape, deg: number): Shape => own(rotate(s, deg, { axis: [0, 0, 1] }) as Shape);
const at = (s: Shape, v: P3): Shape => own(translate(s, v) as Shape);
const volume = (s: Shape): number => unwrap(measureVolume(s));
const prism = (pts: P3[], by: number | P3): Shape => own(unwrap(extrude(own(unwrap(polygon(pts))), by))) as Shape;

// 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 count === 1 ? pieces[0]! : (compound(pieces.map(own)) as Shape);
};

function gearbox({ input = 40, stages = 2, cutaway = 150 }: GearboxParams = {}) {
  const gap = (Math.min(Math.max(cutaway, 0), 300) * Math.PI) / 180;

  // A closed profile in the (r, z) half-plane, revolved about the axis. An open part leaves the cutaway free.
  const lathe = (pts: P2[], open = false): Shape => {
    const profile = own(unwrap(polygon(pts.map(([r, z]): P3 => [r, 0, z]))));
    if (!open || gap === 0) return own(unwrap(revolve(profile, { axis: [0, 0, 1] }))) as Shape;
    return turned(own(unwrap(revolve(profile, { axis: [0, 0, 1], angle: TAU - gap }))) as Shape, cutaway / 2);
  };
  const wedge = gap > 0 ? [turned(own(unwrap(revolve(own(unwrap(polygon([[0, 0, -5], [60, 0, -5], [60, 0, 130], [0, 0, 130]]))), { axis: [0, 0, 1], angle: gap }))) as Shape, -cutaway / 2)] : [];
  const around = (s: Shape, n: number, offset = 0): Shape[] => Array.from({ length: n }, (_, i) => turned(s, offset + (360 * i) / n));

  const top = FLANGE + 3 + STAGE * stages; // the output housing starts here
  const face = top + HEAD; // mounting face of the output
  const end = face + OUTPUT.length;
  const orbit = (MODULE * (TEETH.sun + TEETH.planet)) / 2;

  // ---- housing: motor flange, ring gear, output housing
  const h = FRAME / 2;
  const square = (z: number, trim: number): P3[] => {
    const e = Math.sqrt(trim * trim - h * h); // the corner circle meets the side here
    const d = trim / Math.SQRT2;
    return [[1, 1], [-1, 1], [-1, -1], [1, -1]].flatMap(([sx, sy]): P3[] => {
      const corner: P3[] = [[h * sx!, e * sy!, z], [d * sx!, d * sy!, z], [e * sx!, h * sy!, z]];
      return sx! * sy! > 0 ? corner : corner.reverse();
    });
  };
  const holes = (circle: number, r: number, z: number, depth: number): Shape[] =>
    around(own(cylinder(r, depth, { at: [circle / 2, 0, z] })), 4, 45);
  // The M5 thread of the four tapped holes on a circle. Only a whole hole shows its thread.
  const tapped = (circle: number, z: number, depth: number): Shape[] => {
    const tooth = at(own(helixTooth(M5.major / 2, M5.minor / 2, M5.pitch, z + 0.4, z + depth - 0.4, 0)), [circle / 2, 0, 0]);
    const whole = (a: number): boolean => gap === 0 || Math.min(a, 360 - a) - cutaway / 2 > 6; // degrees clear of the cutaway
    return [45, 135, 225, 315].filter(whole).map((a) => turned(tooth, a));
  };

  const mp = MOTOR.pilot / 2;
  const flange = unwrap(cutAll(prism(square(0, 41), FLANGE), [
    lathe([[0, -1], [mp, -1], [mp, MOTOR.pilotDepth], [14, MOTOR.pilotDepth], [14, 11], [BEARING_IN.D / 2, 11], [BEARING_IN.D / 2, FLANGE + 1], [0, FLANGE + 1]]),
    ...holes(MOTOR.circle, MOTOR.thread / 2, -1, MOTOR.depth + 1),
    ...wedge,
  ])) as Shape;

  const ringBlank = own(unwrap(makeInternalGear({ teeth: TEETH.ring, moduleSize: MODULE, thickness: top - FLANGE, ringWallThickness: h - (MODULE * TEETH.ring) / 2, flankThinning: 0.04, samples: 5 })).solid);
  const ringTurned = turned(ringBlank, 180 / TEETH.ring); // a ring tooth in the planet space
  const ring = gap > 0 ? (unwrap(cutAll(at(ringTurned, [0, 0, FLANGE]), wedge)) as Shape) : (translate(ringTurned, [0, 0, FLANGE]) as Shape);

  const bo = BEARING_OUT.D / 2;
  const b1 = top + 1; // lower output bearing
  const b2 = b1 + BEARING_OUT.B + 6; // upper output bearing
  const clip = b2 + BEARING_OUT.B; // retaining ring
  const sealZ = clip + 1.5;
  const head = unwrap(cutAll(prism(square(top, OUTPUT.corner / 2), HEAD + OUTPUT.pilotHeight), [
    lathe([[h, top - 1], [50, top - 1], [50, face - 10], [h, face - 10]]),
    lathe([[OUTPUT.pilot / 2, face], [50, face], [50, face + 5], [OUTPUT.pilot / 2, face + 5]]),
    lathe([[0, top - 1], [bo, top - 1], [bo, b1 + BEARING_OUT.B], [bo - 2.5, b1 + BEARING_OUT.B], [bo - 2.5, b2], [bo, b2], [bo, clip], [bo + 1.1, clip], [bo + 1.1, clip + 1.2], [bo, clip + 1.2], [bo, face + 5], [0, face + 5]]),
    ...holes(OUTPUT_HOLES.circle, OUTPUT_HOLES.thread / 2, face - OUTPUT_HOLES.depth, OUTPUT_HOLES.depth + 1),
    ...wedge,
  ])) as Shape;

  // ---- bearings: the outer ring is open, the inner ring and the balls are whole
  const rings: Shape[] = [];
  const balls: Shape[] = [];
  const bearing = ({ d, D, B }: { d: number; D: number; B: number }, z: number, count: number): void => {
    const rp = (d + D) / 4;
    const rb = 0.27 * (D - d) / 2;
    const zc = z + B / 2;
    const land = 0.45 * rb;
    const span = Math.acos(land / (rb + 0.05));
    const groove = (side: number): P2[] => Array.from({ length: 13 }, (_, i): P2 => {
      const a = -span + (2 * span * i) / 12;
      return [rp + side * (rb + 0.05) * Math.cos(a), zc + side * (rb + 0.05) * Math.sin(a)];
    });
    rings.push(lathe([[d / 2, z + B], [d / 2, z], [rp - land, z], ...groove(-1).reverse(), [rp - land, z + B]]));
    rings.push(lathe([[D / 2, z], [D / 2, z + B], [rp + land, z + B], ...groove(1).reverse(), [rp + land, z]], true));
    balls.push(...around(own(sphere(rb, { at: [rp, 0, zc] })), count));
  };
  bearing(BEARING_IN, FLANGE - BEARING_IN.B, 14);
  bearing(BEARING_OUT, b1, 10);
  bearing(BEARING_OUT, b2, 10);
  const steel: Shape[] = [
    lathe([[BEARING_OUT.d / 2, b1 + BEARING_OUT.B], [10.5, b1 + BEARING_OUT.B], [10.5, b2], [BEARING_OUT.d / 2, b2]]), // spacer between the inner rings
    lathe([[bo - 2.2, clip], [bo + 1.1, clip], [bo + 1.1, clip + 1.2], [bo - 2.2, clip + 1.2]], true), // retaining ring
  ];
  const sd = SEAL.d / 2;
  const seal = lathe([[sd, sealZ + 1], [sd + 0.7, sealZ], [bo, sealZ], [bo, sealZ + SEAL.B], [bo - 1.3, sealZ + SEAL.B], [bo - 1.3, sealZ + 1.4], [sd + 2.1, sealZ + 1.4], [sd + 1.1, sealZ + SEAL.B - 0.8], [sd, sealZ + SEAL.B - 1.6]], true);

  // ---- gears. A sun has a tooth on +X at 0 degrees. A planet at orbit angle 0 has a space there.
  const gear = (teeth: number, bore = 0): Shape => own(unwrap(makeExternalGear({ teeth, moduleSize: MODULE, thickness: FACE, bore, flankThinning: 0.04, samples: 5 })).solid) as Shape;
  const sunGear = gear(TEETH.sun);
  const planetGear = gear(TEETH.planet, 2 * PIN);
  // A carrier: a plate with one lobe for each planet, and headed pins that hold the planets.
  const spider = (z: number, plate: number): Shape[] => [
    prism(Array.from({ length: 60 }, (_, i): P3 => {
      const a = (TAU * i) / 60;
      const r = 15 + 6 * Math.cos(PLANETS * (a - HOME * (Math.PI / 180)));
      return [r * Math.cos(a), r * Math.sin(a), plate];
    }), 3),
    ...around(own(cylinder(PIN, plate + 1 - z, { at: [orbit, 0, z + 0.2] })), PLANETS, HOME),
    ...around(own(cylinder(4.2, 0.8, { at: [orbit, 0, z + 0.2] })), PLANETS, HOME),
  ];
  const suns: Shape[] = [];
  const planets: Shape[] = [];
  const carriers: Shape[] = [];
  const ratio = 1 + TEETH.ring / TEETH.sun;
  let angle = input; // degrees of the sun of this stage
  let clash = 0;
  for (let k = 0; k < stages; k++) {
    const z = FLANGE + STAGE * k;
    const carrier = angle / ratio;
    const sun = at(turned(sunGear, angle), [0, 0, z]);
    if (k === 0) {
      // The first sun is one part with the clamp hub of the motor shaft.
      const ms = MOTOR.shaft / 2;
      const hub = lathe([[ms, 4], [12, 4], [12, 11], [BEARING_IN.d / 2, 11], [BEARING_IN.d / 2, FLANGE], [0, FLANGE], [0, FLANGE - 1], [ms, FLANGE - 1]]);
      const slit = own(box(14, 1, 7.5, { at: [7, 0, 7.25] }));
      // The clamp screw crosses the slit: a clearance hole on the head side, the M3 thread on the far side.
      const bolt = [own(cylinder(1.7, 6, { at: [8, -5.5, 7.5], axis: [0, 1, 0] })), own(cylinder(M3.major / 2 + PLAY, 10, { at: [8, 0.5, 7.5], axis: [0, 1, 0] })), own(cylinder(2.8, 6, { at: [8, -11.5, 7.5], axis: [0, 1, 0] }))];
      const blank = own(unwrap(fuseAll([hub, own(translate(sunGear, [0, 0, FLANGE]) as Shape)]))) as Shape;
      suns.push(turned(own(unwrap(cutAll(blank, [slit, ...bolt]))) as Shape, angle));
      // The screw is built on Z with the seat of its head at z = 0. The hub thread is in the same frame, half a pitch away.
      const socket = prism(Array.from({ length: 6 }, (_, i): P3 => [1.45 * Math.cos((i * Math.PI) / 3), 1.45 * Math.sin((i * Math.PI) / 3), 1.5]), 2);
      const screwBody = own(unwrap(cutAll(own(unwrap(fuseAll([own(cylinder(2.75, 3)), own(cylinder(M3.minor / 2, 11.5, { at: [0, 0, -11] }))]))) as Shape, [socket]))) as Shape;
      const inHub = (s: Shape): Shape => turned(at(own(rotate(s, 90, { axis: [1, 0, 0] }) as Shape), [8, -5.5, 7.5]), angle);
      steel.push(inHub(screwBody), inHub(own(helixTooth(M3.minor / 2, M3.major / 2, M3.pitch, -10.75, -0.3, 0))));
      suns.push(inHub(own(helixTooth(M3.major / 2 + PLAY, M3.minor / 2 + PLAY, M3.pitch, -12.5, -6.3, M3.pitch / 2))));
    } else {
      suns.push(sun);
    }
    // The planet turns about its pin by the ring ratio while the carrier takes it around.
    const spin = (psi: number): number => psi * (1 + TEETH.sun / TEETH.planet) + 180 / TEETH.planet + carrier - (angle - carrier) * (TEETH.sun / TEETH.planet);
    for (let i = 0; i < PLANETS; i++) {
      const psi = HOME + (360 * i) / PLANETS;
      planets.push(turned(at(turned(planetGear, spin(psi) - carrier - psi), [orbit, 0, z + 1]), psi + carrier));
    }
    if (k === 0) clash = volume(own(unwrap(intersect(sun, planets[0]!))) as Shape);
    const plate = z + FACE + 1.5;
    if (k < stages - 1) {
      carriers.push(turned(own(unwrap(fuseAll(spider(z, plate)))) as Shape, carrier));
    } else {
      // The last carrier is the output shaft.
      const os = OUTPUT.shaft / 2;
      const body = lathe([[0, plate + 2], [11, plate + 2], [11, b1], [sd, b1], [sd, face + OUTPUT.shoulderLength], [os, face + OUTPUT.shoulderLength], [os, end - 1], [os - 1, end], [0, end]]);
      const keyZ = end - 3 - KEY.length;
      const r = KEY.width / 2;
      const seatX = os - KEY.seat;
      const slot: P3[] = Array.from({ length: 18 }, (_, i): P3 => {
        const a = (Math.PI * (i < 9 ? i : i - 1)) / 8;
        return i < 9 ? [seatX, r * Math.cos(a), keyZ + KEY.length - r + r * Math.sin(a)] : [seatX, r * Math.cos(a), keyZ + r + r * Math.sin(a)];
      });
      const centre = [own(cylinder(CENTRE_BORE.thread / 2, CENTRE_BORE.depth, { at: [0, 0, end - CENTRE_BORE.depth] })), own(cone(1, 3.2, 2.2, { at: [0, 0, end - 2.1] }))];
      const shaft = own(unwrap(cutAll(own(unwrap(fuseAll([body, ...spider(z, plate)]))) as Shape, [prism(slot, [KEY.height + 3, 0, 0]), ...centre]))) as Shape;
      carriers.push(turned(shaft, carrier), turned(own(helixTooth(M5.major / 2, M5.minor / 2, M5.pitch, end - CENTRE_BORE.depth + 0.4, end - 1, 0)), carrier)); // with the M5 thread of the centre bore
      steel.push(turned(prism(slot, [KEY.height, 0, 0]), carrier));
    }
    angle = carrier;
  }

  // Lay the gearbox down: the shaft points to +X and the cutaway is on top.
  const lay = (parts: Shape[]): Shape => rotate(turned(own(compound(parts)) as Shape, 180), 90, { axis: [0, 1, 0] }) as Shape;
  return {
    flange: lay([own(flange), ...tapped(MOTOR.circle, 0, MOTOR.depth)]), ring: lay([own(ring)]), head: lay([own(head), ...tapped(OUTPUT_HOLES.circle, face - OUTPUT_HOLES.depth, OUTPUT_HOLES.depth)]), seal: lay([seal]),
    rings: lay(rings), balls: lay(balls), steel: lay(steel), suns: lay(suns), planets: lay(planets), carriers: lay(carriers),
    ratio: Math.pow(ratio, stages), input, output: angle, clash, length: end,
  };
}

const part = freeing(() => gearbox());
console.log('Ratio: ' + part.ratio + ':1 from the tooth counts. Input ' + part.input + ' deg turns the output ' + part.output.toFixed(2) + ' deg.');
console.log('Length: ' + part.length.toFixed(1) + ' mm. Volume that the first sun and a planet share, from the kernel: ' + part.clash.toFixed(3) + ' mm3.');

export default [
  color(part.flange, '#f5f2ea'),
  color(part.ring, '#c3c9d1'),
  color(part.head, '#f5f2ea'),
  color(part.suns, '#12b5b0'),
  color(part.planets, '#d3a956'),
  color(part.carriers, '#ff5a1f'),
  color(part.rings, '#c3c9d1'),
  color(part.balls, '#48515c'),
  color(part.steel, '#8f98a3'),
  color(part.seal, '#22262b'),
];

Functions used ​

box compound cone cutAll cylinder extrude fuseAll intersect makeExternalGear line loft makeInternalGear measureVolume polygon revolve rotate sphere translate unwrap wire color

▶ Run Planetary Gear Reducer (25:1) in the playground

Released under the Apache 2.0 License.