NEMA 17 Stepper Motor (cutaway)

A NEMA 17 hybrid stepper motor in cutaway: toothed stator with eight wound poles, two 50-tooth rotor cups half a tooth apart on a disc magnet, ball bearings, end caps, through screws and connector. The mounting dimensions, the tooth and pole counts and the catalogue masses are published figures, and the 1.8 degree step follows from the tooth counts. The kernel measures the mass from the solid volumes. The lamination shape, the coils, the bearings and the end caps are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
ts
import { box, clone, compound, cut, cutAll, cylinder, extrude, fuseAll, line, loft, measureVolume, polygon, revolve, rotate, sphere, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// NEMA 17 hybrid stepper motor, in cutaway. The shaft is the Z axis, the mounting face is up, units are millimetres.
// The mounting dimensions, the tooth and pole counts and the masses are published figures.
// The lamination shape, the coils, the bearings, the end caps and the connector pins are a display model.
interface StepperParams {
cutaway?: number; // degrees of the stator and the end caps to cut away (0 = closed motor)
length?: 25 | 38 | 48; // body length from the catalogue series
steps?: number; // full steps that the rotor turns from its start position
}
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 (NEMA 17, 1.8 degree, 2 phase)
const FACE = 42.3; // square body
const HOLES = { pitch: 31, thread: 3, depth: 4.5 }; // four M3 tapped holes
const M3 = { minor: 2.459, pitch: 0.5 }; // M3 coarse thread, right hand
const PILOT = { diameter: 22, height: 2 };
const SHAFT = { diameter: 5, length: 20 }; // length from the mounting face
const CONNECTOR = { width: 16, out: 6.5, tall: 11 };
const ROTOR_TEETH = 50;
const POLES = 8;
const TEETH_PER_POLE = 5;
const PHASES = 2;
const CATALOGUE_G: Record<number, number> = { 25: 153, 38: 285, 48: 350 }; // mass for each body length
const DENSITY = { steel: 7.85e-3, aluminium: 2.7e-3, copper: 8.96e-3, magnet: 7.5e-3, nylon: 1.14e-3 }; // grams per cubic millimetre
// ---- display model
const CAP = { height: 9, web: 3, pocket: 19.5, boss: 10, chamfer: 4.5 }; // die-cast end caps
const GAP = 0.1; // air gap between rotor and stator teeth
const ROTOR = { radius: 11, root: 10.4 };
const STATOR = { groove: 0.6, shoe: 13, slot: 18.5, neck: 2.8 }; // shoe and slot radius, half width of a pole neck
const COIL = { inner: 13.2, outer: 17.8, half: 4.4, over: 2.5, fill: 0.5 }; // fill is the copper share of a coil
const BEARING = { outer: 8, width: 5, ring: 1.2, balls: 7 };
const SCREW = { head: 2.75, headHeight: 2, plain: 2 }; // plain: the thread starts this far before the front cap
const PLAY = 0.05; // radial play between a screw thread and the thread in the cap
const FRONT_EXTRA = 90; // extra degrees of cutaway on the front cap
const turn = (s: Shape, deg: number): Shape => rotate(s, deg, { axis: [0, 0, 1] }) as Shape;
const polar = (r: number, deg: number): P2 => [r * Math.cos((deg * Math.PI) / 180), r * Math.sin((deg * Math.PI) / 180)];
// A flat outline at height z0, extruded to z1.
const prism = (pts: P2[], z0: number, z1: number): Shape => unwrap(extrude(own(unwrap(polygon(pts.map(([x, y]): P3 => [x, y, z0])))), [0, 0, z1 - z0])) as Shape;
// A closed profile in the (r, z) half-plane, revolved about the axis.
const lathe = (pts: P2[], angle = 2 * Math.PI): Shape => unwrap(revolve(own(unwrap(polygon(pts.map(([r, z]): P3 => [r, 0, z])))), { axis: [0, 0, 1], angle })) as Shape;
const ring = (r0: number, r1: number, z0: number, z1: number, angle?: number): Shape => lathe([[r0, z0], [r1, z0], [r1, z1], [r0, z1]], angle);
// One helical thread tooth about +Z, from z = from to z = to. Its crest passes the +X side at z = ref.
// tip > core is the thread on a core of the radius core. tip < core is the thread in a bore of the radius core.
// The loft is smooth: each flank is one helical face.
const SECTIONS = 12; // sections of the loft 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 outward = tip > core;
const root = outward ? core / SLACK : core * SLACK;
const crest = outward ? tip : tip / SLACK;
const half = 0.42 * pitch; // half width of the tooth at its root
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): [number, number, number] => [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; // loft is ruled by default
};
const volume = (parts: Shape[]): number => parts.reduce((sum, s) => sum + unwrap(measureVolume(s)), 0);
function stepper({ cutaway = 90, length = 38, steps = 0 }: StepperParams = {}) {
const half = FACE / 2;
const pitch = 360 / ROTOR_TEETH; // 7.2 degrees. The stator teeth have the same pitch.
const stepAngle = pitch / (2 * PHASES); // 1.8 degrees
const z0 = CAP.height; // the lamination stack sits between the two caps
const z1 = length - CAP.height;
// Square outline with chamfered corners, and the four screw holes that go through the motor.
const c = CAP.chamfer;
const outline: P2[] = [[half, -half + c], [half, half - c], [half - c, half], [-half + c, half], [-half, half - c], [-half, -half + c], [-half + c, -half], [half - c, -half]];
const corners: P2[] = [[1, 1], [-1, 1], [-1, -1], [1, -1]];
const screwHoles = corners.map(([x, y]) => own(cylinder(HOLES.thread / 2, length + 2, { at: [(x * HOLES.pitch) / 2, (y * HOLES.pitch) / 2, -1] })));
// Stator: eight poles, each with five teeth. The outline of the air inside it is one polygon.
const rb = ROTOR.radius + GAP;
const neckAt = (r: number): number => (Math.asin(STATOR.neck / r) * 180) / Math.PI;
const edge = ((TEETH_PER_POLE - 1) / 2) * pitch + pitch / 4; // half angle of a pole shoe
const air: P2[] = [];
for (let k = 0; k < POLES; k++) {
const at = (360 * k) / POLES;
const add = (r: number, deg: number) => air.push(polar(r, at + deg));
add(STATOR.slot, -15); add(STATOR.slot, -neckAt(STATOR.slot)); add(STATOR.shoe, -neckAt(STATOR.shoe)); add(STATOR.shoe, -edge);
for (let t = 0; t < TEETH_PER_POLE; t++) {
const mid = (t - (TEETH_PER_POLE - 1) / 2) * pitch;
add(rb, mid - pitch / 4); add(rb, mid + pitch / 4);
if (t < TEETH_PER_POLE - 1) { add(rb + STATOR.groove, mid + pitch / 4); add(rb + STATOR.groove, mid + (3 * pitch) / 4); }
}
add(STATOR.shoe, edge); add(STATOR.shoe, neckAt(STATOR.shoe)); add(STATOR.slot, neckAt(STATOR.slot)); add(STATOR.slot, 15); add(STATOR.slot, 22.5);
}
const stack = own(unwrap(cutAll(own(prism(outline, z0, z1)), [own(prism(air, z0 - 1, z1 + 1)), ...screwHoles])) as Shape);
// Coils: one on each pole neck, longer than the stack at both ends.
const neck = own(box(8, 2 * STATOR.neck, z1 - z0, { at: [15, 0, length / 2] }));
const wound = own(box(COIL.outer - COIL.inner, 2 * COIL.half, z1 - z0 + 2 * COIL.over, { at: [(COIL.inner + COIL.outer) / 2, 0, length / 2] }));
const coil = own(unwrap(cut(wound, neck)) as Shape);
const coilAngles = Array.from({ length: POLES }, (_, k) => (360 * k) / POLES);
const coils = coilAngles.map((a) => own(turn(coil, a)));
// End caps: a pocket for the coil ends, a boss for the bearing, and the pilot on the front cap.
const cap = (front: boolean): Shape => {
const at = (z: number): number => (front ? length - z : z); // z is measured from the outside face
const blank = own(prism(outline, front ? z1 : 0, front ? length : z0));
const body = front ? own(unwrap(fuseAll([blank, own(ring(0, PILOT.diameter / 2, length, length + PILOT.height))])) as Shape) : blank;
const pocket = own(ring(CAP.boss, CAP.pocket, Math.min(at(CAP.web), at(CAP.height + 1)), Math.max(at(CAP.web), at(CAP.height + 1))));
const seat = own(ring(0, BEARING.outer, Math.min(at(CAP.web), at(CAP.height + 1)), Math.max(at(CAP.web), at(CAP.height + 1))));
const through = front ? [own(cylinder(SHAFT.diameter / 2 + 0.6, 10, { at: [0, 0, length - CAP.web - 1] }))] : [];
return own(unwrap(cutAll(body, [pocket, seat, ...through, ...(front ? tapHoles : screwHoles)])) as Shape);
};
// The front cap is tapped M3 right through. The long screws use the inner part and the mounting screws the outer part.
const tap = HOLES.thread / 2 + PLAY;
const rm = M3.minor / 2;
const runOut = 0.42 * M3.pitch; // a tooth ends this far from the end of its thread
const at4 = (s: Shape): Shape[] => corners.map(([x, y]) => own(translate(s, [(x * HOLES.pitch) / 2, (y * HOLES.pitch) / 2, 0]) as Shape));
const tapHoles = at4(own(cylinder(tap, CAP.height + 2, { at: [0, 0, z1 - 1] })));
const tapTeeth = at4(own(helixTooth(tap, rm + PLAY, M3.pitch, z1 + runOut, length - runOut, M3.pitch / 2)));
const frontCap = cap(true);
const rearCap = cap(false);
// Rotor: two toothed cups with a disc magnet between them. One cup is half a tooth ahead of the other.
const teeth: P2[] = [];
for (let t = 0; t < ROTOR_TEETH; t++) {
const mid = t * pitch;
teeth.push(polar(ROTOR.radius, mid - pitch / 4), polar(ROTOR.radius, mid + pitch / 4), polar(ROTOR.root, mid + pitch / 4), polar(ROTOR.root, mid + (3 * pitch) / 4));
}
const rs = SHAFT.diameter / 2;
const cupLength = (z1 - z0 - 3) / 2;
const turned = steps * stepAngle;
const cupBlank = own(prism(teeth, z0 + 0.5, z0 + 0.5 + cupLength));
const cup = own(unwrap(cut(cupBlank, own(cylinder(rs, length, { at: [0, 0, 0] })))) as Shape);
const cups = [own(turn(cup, turned)), own(turn(own(translate(cup, [0, 0, cupLength + 2]) as Shape), turned + pitch / 2))];
const magnet = ring(rs, ROTOR.root - 1, z0 + 0.5 + cupLength, z0 + 2.5 + cupLength);
// Shaft with a flat, two ball bearings and two spacers.
const shaftBlank = own(cylinder(rs, length + SHAFT.length - CAP.web, { at: [0, 0, CAP.web] }));
const shaft = own(unwrap(cut(shaftBlank, own(box(4, 6, 15, { at: [rs - 0.5 + 2, 0, length + SHAFT.length - 7.5] })))) as Shape);
const bearing = (z: number): Shape[] => {
const rp = (rs + BEARING.outer) / 2;
const ball = own(sphere((BEARING.outer - rs) / 2 - BEARING.ring, { at: [rp, 0, z + BEARING.width / 2] }));
const balls = Array.from({ length: BEARING.balls }, (_, i) => own(turn(ball, (360 * i) / BEARING.balls)));
return [own(ring(rs, rs + BEARING.ring, z, z + BEARING.width)), own(ring(BEARING.outer - BEARING.ring, BEARING.outer, z, z + BEARING.width)), ...balls];
};
const bearings = [...bearing(CAP.web), ...bearing(length - CAP.web - BEARING.width)];
const spacers = [own(ring(rs, rs + 1.5, CAP.web + BEARING.width, z0 + 0.5)), own(ring(rs, rs + 1.5, z1 - 0.5, length - CAP.web - BEARING.width))];
// Four long screws from the rear cap. The threaded end turns into the front cap and leaves the tapped depth free at the front.
const end = length - HOLES.depth - 0.5;
const zt = z1 - SCREW.plain;
const blank = own(lathe([
[0, -SCREW.headHeight], [SCREW.head - 0.6, -SCREW.headHeight], [SCREW.head, -0.8], [SCREW.head, 0], [HOLES.thread / 2, 0], [HOLES.thread / 2, zt],
[rm, zt], [rm, end - 0.3], [rm - 0.3, end], [0, end],
]));
const recess = [0, 90].map((deg) => own(turn(own(box(3.2, 0.6, 1.4, { at: [0, 0, -SCREW.headHeight] })), deg))); // cross recess
const headed = own(unwrap(cutAll(blank, recess)) as Shape);
const screws = at4(own(compound([headed, own(helixTooth(rm, HOLES.thread / 2, M3.pitch, zt + runOut, end - runOut, 0))]) as Shape));
// Connector on the rear cap: a housing with six pins.
const shellBox = own(box(CONNECTOR.width, CONNECTOR.out, CONNECTOR.tall, { at: [0, half + CONNECTOR.out / 2, CONNECTOR.tall / 2] }));
const housing = unwrap(cut(shellBox, own(box(CONNECTOR.width - 2, CONNECTOR.out, CONNECTOR.tall - 5, { at: [0, half + CONNECTOR.out / 2 + 1.5, CONNECTOR.tall / 2] })))) as Shape;
const pins = Array.from({ length: 6 }, (_, i) => own(box(0.6, CONNECTOR.out - 2.5, 0.6, { at: [(i - 2.5) * 2, half + 1.5 + (CONNECTOR.out - 2.5) / 2, CONNECTOR.tall / 2] })));
// Mass from the kernel volumes of the closed motor.
const grams =
volume([stack, ...cups, shaft, ...bearings, ...spacers, ...screws]) * DENSITY.steel + volume([frontCap, rearCap, ...tapTeeth]) * DENSITY.aluminium +
volume(coils) * COIL.fill * DENSITY.copper + volume([magnet]) * DENSITY.magnet + volume([housing]) * DENSITY.nylon;
// Cutaway: a wedge centred on +X opens the caps, the stack and the coils. The rotor stays whole.
// The front cap opens wider, so the stator teeth and the coil ends show from above.
const slice = (deg: number): Shape => own(turn(own(ring(0, 40, -5, length + 5, (Math.max(deg, 1) * Math.PI) / 180)), -deg / 2));
const wedge = slice(cutaway);
const wide = slice(Math.min(cutaway + FRONT_EXTRA, 300));
const open = (s: Shape, tool = wedge): Shape => (cutaway > 0 ? (unwrap(cut(s, tool)) as Shape) : (unwrap(clone(s)) as Shape));
const span = 19; // half angle that one coil covers
const off = (a: number): number => Math.abs(((a + 180) % 360) - 180);
// The thread in a front cap hole goes with the part of the cap that holds it.
const frontHalf = Math.min(cutaway + FRONT_EXTRA, 300) / 2;
const tapShown = tapTeeth.flatMap((s, k) => {
const angle = off((Math.atan2(corners[k]![1], corners[k]![0]) * 180) / Math.PI + 360);
if (cutaway > 0 && angle + 5 <= frontHalf) return [];
return [cutaway > 0 && angle - 5 < frontHalf ? own(open(s, wide)) : s];
});
const shown = coils.flatMap((s, k) => {
const angle = off(coilAngles[k]!);
if (cutaway > 0 && angle + span <= cutaway / 2) return [];
return [angle - span < cutaway / 2 ? own(open(s)) : s];
});
return {
caps: compound([own(open(frontCap, wide)), own(open(rearCap)), ...tapShown]) as Shape, stack: open(stack), coils: compound(shown) as Shape,
rotor: compound([...cups, shaft, ...spacers]) as Shape, magnet, bearings: compound(bearings) as Shape, screws: compound(screws) as Shape,
housing, pins: compound(pins) as Shape, grams, stepAngle, turned, length,
};
}
const part = freeing(() => stepper());
console.log('Step angle: 360 / (' + ROTOR_TEETH + ' teeth x ' + 2 * PHASES + ' steps for each tooth pitch) = ' + part.stepAngle.toFixed(1) + ' degrees. The rotor is at ' + part.turned.toFixed(1) + ' degrees.');
console.log('Mass: ' + part.grams.toFixed(0) + ' g from the kernel volumes. The catalogue has ' + CATALOGUE_G[part.length] + ' g.');
export default [
color(part.caps, '#c3c9d1'),
color(part.stack, '#6f7a88'),
color(part.coils, '#c9743a'),
color(part.rotor, '#e6e9ee'),
color(part.magnet, '#12b5b0'),
color(part.bearings, '#f2f4f7'),
color(part.screws, '#8d96a0'),
color(part.housing, '#f5f2ea'),
color(part.pins, '#d3a956'),
];Functions used
box clone compound cut cutAll cylinder extrude fuseAll line loft measureVolume polygon revolve rotate sphere translate unwrap wire color