Hobby RC Servo (cutaway)

A standard-size hobby RC servo with half of its case cut away: the four-stage involute gear train, motor, feedback potentiometer, control board, leads and horn. The body size and the tooth counts (10, 60/11, 49/11, 35/13, 42) are published figures, and the gears turn by their true ratios when the horn angle changes. The ratio from the tooth counts is compared with the stated 274.75 to 1. The horn screw is an M3 x 6 pan head screw with a helical thread in the tapped output shaft. The gear modules, the shaft positions, the motor, the board and the horn 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, polygon, revolve, rotate, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Standard-size hobby RC servo with half of its case cut away. The output shaft is along Z, units are millimetres.
// The body size and the tooth counts of the gear train are published figures (a teardown gives the counts).
// The gear modules, the shaft positions, the motor, the potentiometer, the board and the horn are a display model.
interface ServoParams {
horn?: number; // horn angle in degrees, -60 to 60. The gears and the motor turn by their true ratios
cutaway?: boolean; // false closes the case
arms?: 1 | 2 | 4; // arms of the horn
}
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 (standard-size analog servo)
const BODY = { length: 42, width: 20.5, height: 39.5 };
const TRAVEL = 120; // degrees of output travel
// Gear train: motor pinion, three compound gears, output gear. [wheel teeth, pinion teeth]
const TRAIN = { motor: 10, first: [60, 11], second: [49, 11], third: [35, 13], output: 42 } as const;
const STATED_RATIO = 274.75;
// ---- display model
const WALL = 1.4;
const SEAM = { low: 3.7, high: 27, gasket: 0.5 }; // the case is three housings with a rubber ring at each seam
const TOP = 38.4; // top of the gear cover. The boss around the shaft goes up to the body height
const DECK = 1.5; // plate of the middle housing that carries the motor and the gears
const AXIS = { output: -10.5, pin: -0.5, motor: 9.3 }; // Y position of each shaft. The module of each stage follows from these
const LEVEL = { first: 27.9, pitch: 2.4, wheel: 1.9 }; // four gear levels above the deck
const EAR = { length: 6.5, thick: 2.5, top: 25.5, hole: 2.25, across: 10 };
const MOTOR = { radius: 7.5, bottom: 7 };
const POT = { radius: 5, height: 5 };
const BOARD = 1.2;
const LEAD = { radius: 0.6, length: 14 };
const HORN = { hub: 4.2, reach: 19, thick: 1.8 };
const M3 = { major: 3, minor: 2.459, pitch: 0.5, head: 5.6, headHeight: 2.4, length: 6, hole: 3.4 }; // horn screw: ISO 7045 pan head, M3 x 6
const PLAY = 0.08; // radial play between the screw thread and the thread in the output shaft
const turn = (s: Shape, deg: number): Shape => rotate(s, deg, { axis: [0, 0, 1] }) as Shape;
const lathe = (pts: P2[]): Shape => unwrap(revolve(own(unwrap(polygon(pts.map(([r, z]): P3 => [r, 0, z])))), { axis: [0, 0, 1] })) as Shape;
const rod = (r: number, y: number, z0: number, z1: number, x = 0): Shape => own(cylinder(r, z1 - z0, { at: [x, y, z0] }));
// 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 of a screw on a core of that radius. tip < core is the thread in a bore.
// The loft is smooth: each flank is one helical face.
const FACETS = 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 root = tip > core ? core / SLACK : core * SLACK;
const crest = tip > core ? tip : tip / SLACK;
const half = 0.42 * pitch;
const n = Math.max(2, Math.round(((to - from) / pitch) * FACETS));
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;
};
// The thread of a screw between two heights, and the mating thread of a nut or a tapped hole. The two are half a pitch apart.
const screwTooth = (m: { major: number; minor: number; pitch: number }, z0: number, z1: number): Shape =>
helixTooth(m.minor / 2, m.major / 2, m.pitch, z0 + 0.42 * m.pitch, z1 - 0.42 * m.pitch, 0);
const nutTooth = (m: { major: number; minor: number; pitch: number }, z0: number, z1: number): Shape =>
helixTooth(m.major / 2 + PLAY, m.minor / 2 + PLAY, m.pitch, z0 + 0.42 * m.pitch, z1 - 0.42 * m.pitch, m.pitch / 2);
// A block of the case outline between two heights. inset makes it smaller on every side.
const block = (z0: number, z1: number, inset = 0): Shape => own(box(BODY.width - 2 * inset, BODY.length - 2 * inset, z1 - z0, { at: [0, 0, (z0 + z1) / 2] }));
// An involute gear on the shaft at y, from z0 to z1, turned by angle (radians).
const gear = (teeth: number, module: number, y: number, z0: number, z1: number, angle: number, shift: number, bore: number): Shape => {
const g = unwrap(makeExternalGear({ teeth, moduleSize: module, thickness: z1 - z0, shift, bore, flankThinning: module * 0.06, samples: 5 }));
return own(translate(own(turn(own(g.solid), (angle * 180) / Math.PI)), [0, y, z0]) as Shape);
};
// The angle of a driven gear that puts a tooth space on the tooth of its driver, on the line of centres.
const meshAngle = (yDriver: number, driverAngle: number, zDriver: number, yDriven: number, zDriven: number): number => {
const phi = yDriven > yDriver ? Math.PI / 2 : -Math.PI / 2;
const phase = (phi - driverAngle) / ((2 * Math.PI) / zDriver);
return phi + Math.PI - ((2 * Math.PI) / zDriven) * (0.5 - phase);
};
function servo({ horn = 25, cutaway = true, arms = 1 }: ServoParams = {}) {
const T = TRAIN;
const ratio = (T.first[0] / T.motor) * (T.second[0] / T.first[1]) * (T.third[0] / T.second[1]) * (T.output / T.third[1]);
const angle = Math.max(-TRAVEL / 2, Math.min(TRAVEL / 2, horn));
const half = cutaway ? [own(box(BODY.width, BODY.length + 40, 80, { at: [BODY.width / 2, 0, 20] }))] : [];
// Case: bottom cover, middle housing with the deck and the mounting ears, gear cover with the shaft boss.
const bottom = unwrap(cutAll(block(0, SEAM.low), [block(BOARD, SEAM.low + 1, 2), ...half])) as Shape;
const z1 = SEAM.low + SEAM.gasket;
const ear = (side: number): Shape => own(box(BODY.width, EAR.length, EAR.thick, { at: [0, side * (BODY.length + EAR.length) / 2, EAR.top - EAR.thick / 2] }));
const earHoles = ([[1, 1], [-1, 1], [-1, -1], [1, -1]] as P2[]).map(([x, y]) => rod(EAR.hole, (y * (BODY.length + EAR.length)) / 2, 20, 30, (x * EAR.across) / 2));
const leadSlot = own(box(3 * 2 * LEAD.radius + 0.6, 4, 2.2, { at: [0, BODY.length / 2, z1 + 1.1] }));
const middle = unwrap(cutAll(own(unwrap(fuseAll([block(z1, SEAM.high), ear(1), ear(-1)])) as Shape), [
block(z1 - 1, SEAM.high - DECK, WALL), rod(2.2, AXIS.motor, 20, 30), rod(1.25, AXIS.output, 20, 30), leadSlot, ...earHoles, ...half,
])) as Shape;
const z2 = SEAM.high + SEAM.gasket;
const cover = unwrap(cutAll(own(unwrap(fuseAll([block(z2, TOP), rod(5.5, AXIS.output, TOP, BODY.height)])) as Shape), [
block(z2 - 1, TOP - 1.2, WALL), rod(3, AXIS.output, TOP - 2, BODY.height + 1), ...half,
])) as Shape;
const gasket = own(unwrap(cutAll(own(box(BODY.width + 0.4, BODY.length + 0.4, SEAM.gasket, { at: [0, 0, SEAM.low + SEAM.gasket / 2] })), [block(0, 10, WALL), ...half])) as Shape);
const gaskets = [gasket, own(translate(gasket, [0, 0, SEAM.high - SEAM.low]) as Shape)];
// Gear train. Each stage has its own module, so that the stages share two shafts.
const reach = AXIS.pin - AXIS.output;
const m = [(2 * (AXIS.motor - AXIS.pin)) / (T.motor + T.first[0]), (2 * reach) / (T.first[1] + T.second[0]), (2 * reach) / (T.second[1] + T.third[0]), (2 * reach) / (T.third[1] + T.output)];
const z = (level: number): number => LEVEL.first + level * LEVEL.pitch;
const chain = (deg: number): number[] => {
const a0 = (deg * ratio * Math.PI) / 180;
const a1 = meshAngle(AXIS.motor, a0, T.motor, AXIS.pin, T.first[0]);
const a2 = meshAngle(AXIS.pin, a1, T.first[1], AXIS.output, T.second[0]);
const a3 = meshAngle(AXIS.output, a2, T.second[1], AXIS.pin, T.third[0]);
return [a0, a1, a2, a3, meshAngle(AXIS.pin, a3, T.third[1], AXIS.output, T.output)];
};
const a = chain(angle);
const hornTurn = ((a[4]! - chain(0)[4]!) * 180) / Math.PI;
const s = 0.3; // profile shift: plus on a pinion, minus on its wheel
const pinion = gear(T.motor, m[0]!, AXIS.motor, SEAM.high, z(0) + LEVEL.wheel, a[0]!, s, 0);
const gears = [
gear(T.first[0], m[0]!, AXIS.pin, z(0), z(0) + LEVEL.wheel, a[1]!, -s, 1.5), gear(T.first[1], m[1]!, AXIS.pin, z(0) + LEVEL.wheel, z(2), a[1]!, s, 1.5),
gear(T.second[0], m[1]!, AXIS.output, z(1), z(1) + LEVEL.wheel, a[2]!, -s, 2), gear(T.second[1], m[2]!, AXIS.output, z(1) + LEVEL.wheel, z(3), a[2]!, s, 2),
gear(T.third[0], m[2]!, AXIS.pin, z(2), z(2) + LEVEL.wheel, a[3]!, -s, 1.5), gear(T.third[1], m[3]!, AXIS.pin, z(2) + LEVEL.wheel, z(3) + LEVEL.wheel, a[3]!, s, 1.5),
];
const zOut = z(3) + LEVEL.wheel;
const shaftTop = BODY.height + 2;
const shaft = own(unwrap(cutAll(rod(3, AXIS.output, zOut, shaftTop), [rod(M3.major / 2 + PLAY, AXIS.output, zOut - 1, shaftTop + 1)])) as Shape); // tapped for the horn screw
const output = [gear(T.output, m[3]!, AXIS.output, z(3), zOut, a[4]!, -s, 2), shaft];
// Shafts: a fixed pin for the first and the third gear, and the potentiometer shaft under the output gear.
const potTop = SEAM.high - DECK;
const pin = [rod(0.75, AXIS.pin, SEAM.high, TOP - 1.2), own(translate(own(lathe([[0.75, SEAM.high], [2, SEAM.high], [2, z(0)], [0.75, z(0)]])), [0, AXIS.pin, 0]) as Shape)];
const potShaft = own(translate(own(lathe([[0, potTop], [1.25, potTop], [1.25, z(1)], [1, z(1)], [1, zOut], [0, zOut]])), [0, AXIS.output, 0]) as Shape);
// Motor under the deck, potentiometer under the output shaft, control board on the bottom cover.
const zb = SEAM.low + BOARD;
const can = own(translate(own(lathe([[0, MOTOR.bottom], [MOTOR.radius, MOTOR.bottom], [MOTOR.radius, potTop], [2.2, potTop], [2.2, SEAM.high], [0, SEAM.high]])), [0, AXIS.motor, 0]) as Shape);
const endBell = rod(MOTOR.radius - 0.6, AXIS.motor, MOTOR.bottom - 1, MOTOR.bottom);
const tabs = [-1, 1].map((side) => own(box(0.4, 2, MOTOR.bottom - 1 - zb, { at: [0, AXIS.motor + side * 4, (MOTOR.bottom - 1 + zb) / 2] })));
const pot = rod(POT.radius, AXIS.output, potTop - POT.height, potTop);
const legs = [-2.5, 0, 2.5].map((x) => rod(0.35, AXIS.output - 3.2, zb, potTop - POT.height, x));
const board = own(box(BODY.width - 2 * WALL, BODY.length - 2 * WALL, BOARD, { at: [0, 0, SEAM.low + BOARD / 2] }));
const chips = [own(box(4, 6, 1.4, { at: [-3.5, -2, zb + 0.7] })), ...[-17, -8, 13, 17].map((y) => own(box(2.4, 1.6, 1.1, { at: [3.5, y, zb + 0.55] })))];
const leads = [-1, 0, 1].map((i) => cylinder(LEAD.radius, LEAD.length + 5, { at: [i * 2 * LEAD.radius, BODY.length / 2 - 5, zb + LEAD.radius], axis: [0, 1, 0] }));
// Horn on the output shaft. Its screw goes through the horn into the thread of the shaft.
const zh = BODY.height + 0.3;
const arm = (deg: number): Shape => {
const plan: P2[] = [[0, -3], [HORN.reach, -1.8], [HORN.reach + 1.2, 0], [HORN.reach, 1.8], [0, 3]];
const flat = own(unwrap(extrude(own(unwrap(polygon(plan.map(([x, y]): P3 => [x, y, zh + 1.7])))), [0, 0, HORN.thick])) as Shape);
return own(turn(flat, deg));
};
const armAngles = Array.from({ length: arms }, (_, i) => (360 * i) / arms);
const hornHoles = armAngles.flatMap((deg) => [7, 10.5, 14, 17.5].map((r) => own(turn(rod(0.6, 0, zh, zh + 5, r), deg))));
const hornBlank = own(unwrap(fuseAll([rod(HORN.hub, 0, zh, zh + 1.7 + HORN.thick), ...armAngles.map(arm)])) as Shape);
const hornFlat = own(unwrap(cutAll(hornBlank, [rod(3, 0, zh - 1, shaftTop), rod(M3.hole / 2, 0, zh, zh + 5), ...hornHoles])) as Shape);
const place = (part: Shape): Shape => translate(own(turn(part, hornTurn)), [0, AXIS.output, 0]) as Shape;
const seat = zh + 1.7 + HORN.thick;
const k = M3.headHeight;
const head = own(lathe([[0, seat], [M3.head / 2, seat], [M3.head / 2, seat + k - 0.9], [M3.head / 2 - 0.9, seat + k], [0, seat + k]]));
const recess = [0, 90].map((deg) => own(turn(own(box(3.4, 0.7, 1.4, { at: [0, 0, seat + k - 0.5] })), deg)));
const hornScrew = place(own(compound([
own(unwrap(cutAll(head, recess)) as Shape),
rod(M3.minor / 2, 0, seat - M3.length, seat),
own(screwTooth(M3, seat - M3.length, seat)),
]) as Shape));
// The thread in the shaft turns with the horn, so the two threads stay in mesh.
const shaftTooth = own(place(own(nutTooth(M3, zOut + 0.1, shaftTop))));
return {
case: compound([own(bottom), own(middle), own(cover)]) as Shape, gaskets: compound(gaskets) as Shape, gears: compound(gears) as Shape,
brass: compound([pinion, ...output, shaftTooth, ...tabs, ...legs]) as Shape, steel: compound([...pin, potShaft, can, own(hornScrew)]) as Shape,
dark: compound([endBell, pot, ...chips]) as Shape, board: compound([board]) as Shape, horn: place(hornFlat), leads, ratio, angle,
};
}
const part = freeing(() => servo());
console.log('Gear ratio from the tooth counts: ' + part.ratio.toFixed(2) + ' to 1. The teardown states ' + STATED_RATIO + ' to 1.');
console.log('Horn at ' + part.angle + ' degrees: the motor made ' + ((part.angle * part.ratio) / 360).toFixed(1) + ' turns from the centre position.');
export default [
color(part.case, '#12b5b0'),
color(part.gaskets, '#ff5a1f'),
color(part.gears, '#f5f2ea'),
color(part.brass, '#d3a956'),
color(part.steel, '#c3c9d1'),
color(part.dark, '#48515c'),
color(part.board, '#2f7d5b'),
color(part.horn, '#f5f2ea'),
color(part.leads[0]!, '#f2a71b'),
color(part.leads[1]!, '#d8322a'),
color(part.leads[2]!, '#5a3a22'),
];Functions used
box compound cutAll cylinder extrude fuseAll line loft makeExternalGear polygon revolve rotate translate unwrap wire color