@rulecad/motors 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/diagram.d.mts +18 -0
- package/diagram.mjs +36 -0
- package/motors.d.mts +17 -2
- package/motors.mjs +28 -12
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -98,5 +98,7 @@ motor's limit is a `motor.speed` failure.
|
|
|
98
98
|
| Brushless | T = K_t I, K_t = 60 / (2π KV) | The motor constant in SI units: K_t = K_e |
|
|
99
99
|
| Through gears | T_out = T ratio η, n_out = n / ratio | |
|
|
100
100
|
|
|
101
|
+
`curve(model, { ratio, efficiency, at: { speed, load } })` from `@rulecad/motors/diagram` draws the torque against speed, as an SVG, with a working point and its load marked.
|
|
102
|
+
|
|
101
103
|
A stepper's real curve is on its datasheet when the maker gives one; the kit doesn't have one for any motor yet, says so
|
|
102
104
|
in `how`, and the straight model is on the cautious side of most motors but not all of them. Measure yours.
|
package/diagram.d.mts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Torque against speed, as an SVG: the curve performance() gives, with the working point marked and what it rests on.
|
|
3
|
+
* @param {import('./motors.mjs').Motor} m a motorModel
|
|
4
|
+
* @param {{ supply?: number, ratio?: number, efficiency?: number, at?: { speed: number, load?: number }, width?: number, height?: number }} [o]
|
|
5
|
+
* ratio and efficiency: of the gears after it (the curve is the output's); at: an output speed (rpm) and load (N m) to mark
|
|
6
|
+
* @returns {string} an SVG
|
|
7
|
+
*/
|
|
8
|
+
export function curve(m: import("./motors.mjs").Motor, o?: {
|
|
9
|
+
supply?: number;
|
|
10
|
+
ratio?: number;
|
|
11
|
+
efficiency?: number;
|
|
12
|
+
at?: {
|
|
13
|
+
speed: number;
|
|
14
|
+
load?: number;
|
|
15
|
+
};
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
}): string;
|
package/diagram.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// A motor's curve as a drawing: torque against speed, what it does at each speed, and where an assembly works it.
|
|
2
|
+
import { performance } from './motors.mjs';
|
|
3
|
+
|
|
4
|
+
const esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<');
|
|
5
|
+
const fig = (x) => String(+Number(x).toFixed(2));
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Torque against speed, as an SVG: the curve performance() gives, with the working point marked and what it rests on.
|
|
9
|
+
* @param {import('./motors.mjs').Motor} m a motorModel
|
|
10
|
+
* @param {{ supply?: number, ratio?: number, efficiency?: number, at?: { speed: number, load?: number }, width?: number, height?: number }} [o]
|
|
11
|
+
* ratio and efficiency: of the gears after it (the curve is the output's); at: an output speed (rpm) and load (N m) to mark
|
|
12
|
+
* @returns {string} an SVG
|
|
13
|
+
*/
|
|
14
|
+
export function curve(m, o = {}) {
|
|
15
|
+
const { supply, ratio = 1, efficiency = 1, at, width = 640, height = 380 } = o;
|
|
16
|
+
const ask = (speed) => performance(m, { speed, ratio, efficiency, ...(supply != null ? { supply } : {}) });
|
|
17
|
+
const first = ask(0), limit = first.limit, N = 120, pts = [];
|
|
18
|
+
for (let i = 0; i <= N; i++) { const s = (limit * i) / N; pts.push([s, ask(s).output.torque]); }
|
|
19
|
+
const yMax = Math.max(first.output.torque, ...pts.map((p) => p[1]), at?.load ?? 0) * 1.1, L = 76, B = height - 56, R = width - 24, T = 40;
|
|
20
|
+
const X = (s) => L + ((R - L) * s) / limit, Y = (t) => B - ((B - T) * t) / yMax, out = [];
|
|
21
|
+
out.push(`<rect width="100%" height="100%" fill="#fff"/><text x="${L}" y="24" font-size="15" font-family="system-ui, sans-serif" fill="#1a1a1a">${esc(m.name)}${ratio !== 1 ? `, through ${fig(ratio)}:1` : ''}: torque against speed</text>`);
|
|
22
|
+
for (let i = 0; i <= 4; i++) {
|
|
23
|
+
const t = (yMax * i) / 4, s = (limit * i) / 4;
|
|
24
|
+
out.push(`<line x1="${L}" x2="${R}" y1="${fig(Y(t))}" y2="${fig(Y(t))}" stroke="#e4e4e4"/><text x="${L - 8}" y="${fig(Y(t) + 4)}" text-anchor="end" font-size="11" font-family="system-ui, sans-serif" fill="#555">${fig(t)}</text>`);
|
|
25
|
+
out.push(`<line x1="${fig(X(s))}" x2="${fig(X(s))}" y1="${T}" y2="${B}" stroke="#e4e4e4"/><text x="${fig(X(s))}" y="${B + 16}" text-anchor="middle" font-size="11" font-family="system-ui, sans-serif" fill="#555">${fig(s)}</text>`);
|
|
26
|
+
}
|
|
27
|
+
out.push(`<polyline fill="none" stroke="#2266cc" stroke-width="2.2" points="${pts.map(([s, t]) => `${fig(X(s))},${fig(Y(t))}`).join(' ')}"/>`);
|
|
28
|
+
out.push(`<text x="${(L + R) / 2}" y="${height - 22}" text-anchor="middle" font-size="12" font-family="system-ui, sans-serif" fill="#333">output speed, rpm</text><text transform="translate(18 ${(T + B) / 2}) rotate(-90)" text-anchor="middle" font-size="12" font-family="system-ui, sans-serif" fill="#333">output torque, N m</text>`);
|
|
29
|
+
if (at) {
|
|
30
|
+
const here = ask(at.speed).output.torque, x = X(at.speed);
|
|
31
|
+
out.push(`<circle cx="${fig(x)}" cy="${fig(Y(here))}" r="5" fill="#2266cc"/><text x="${fig(x + 9)}" y="${fig(Y(here) - 8)}" font-size="12" font-family="system-ui, sans-serif" fill="#1a1a1a">${fig(here)} N m at ${fig(at.speed)} rpm</text>`);
|
|
32
|
+
if (at.load != null) out.push(`<line x1="${L}" x2="${R}" y1="${fig(Y(at.load))}" y2="${fig(Y(at.load))}" stroke="#cc3322" stroke-dasharray="6 4" stroke-width="1.4"/><text x="${R}" y="${fig(Y(at.load) - 6)}" text-anchor="end" font-size="12" font-family="system-ui, sans-serif" fill="#cc3322">the load, ${fig(at.load)} N m</text>`);
|
|
33
|
+
}
|
|
34
|
+
out.push(`<text x="${R}" y="24" text-anchor="end" font-size="11" font-family="system-ui, sans-serif" fill="#888">rests on ${esc(first.rests.join(', '))} figures</text>`);
|
|
35
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}">${out.join('')}</svg>\n`;
|
|
36
|
+
}
|
package/motors.d.mts
CHANGED
|
@@ -29,6 +29,18 @@ export function motor(m: Motor, ops?: {
|
|
|
29
29
|
union: Function;
|
|
30
30
|
subtract: Function;
|
|
31
31
|
}): object;
|
|
32
|
+
/**
|
|
33
|
+
* The motor's body and its shaft as two solids (null where the bell is the output), so an assembly can let the shaft
|
|
34
|
+
* turn in what it drives while the body stays checked against everything else.
|
|
35
|
+
* @param {Motor} m @param {{ union: Function, subtract: Function }} [ops] @returns {{ body: object, shaft: object | null }}
|
|
36
|
+
*/
|
|
37
|
+
export function motorParts(m: Motor, ops?: {
|
|
38
|
+
union: Function;
|
|
39
|
+
subtract: Function;
|
|
40
|
+
}): {
|
|
41
|
+
body: object;
|
|
42
|
+
shaft: object | null;
|
|
43
|
+
};
|
|
32
44
|
/**
|
|
33
45
|
* What a part needs to hold a motor, as numbers: the pocket, the holes, the screws. mount() cuts it.
|
|
34
46
|
* @param {Motor} m
|
|
@@ -81,12 +93,14 @@ export function mount(m: Motor, p: {
|
|
|
81
93
|
}): object;
|
|
82
94
|
/**
|
|
83
95
|
* A bore for the motor's shaft, as numbers, with what's wrong with it.
|
|
84
|
-
* @param {Motor} m @param {{ depth: number, fit?: 'slide' | 'press', printer?: object }} p depth:
|
|
96
|
+
* @param {Motor} m @param {{ depth: number, tip?: number, fit?: 'slide' | 'press', printer?: object }} p depth: the bore's
|
|
97
|
+
* length; tip: how far from the bore's mouth the shaft's tip sits (default depth; more, if the tip comes out the far side)
|
|
85
98
|
* @returns {{ depth: number, diameter: number, across: number, flats: number, flatFrom: number, grip: number, findings: object[] }}
|
|
86
99
|
* flatFrom: the height in the bore where the flat starts (the shaft's tip end is at depth); below it the bore is round, so the round root of the shaft can pass
|
|
87
100
|
*/
|
|
88
101
|
export function boreModel(m: Motor, p: {
|
|
89
102
|
depth: number;
|
|
103
|
+
tip?: number;
|
|
90
104
|
fit?: "slide" | "press";
|
|
91
105
|
printer?: object;
|
|
92
106
|
}): {
|
|
@@ -101,11 +115,12 @@ export function boreModel(m: Motor, p: {
|
|
|
101
115
|
/**
|
|
102
116
|
* The bore a gear or hub takes for the motor's shaft, to subtract: round where the round of the shaft passes, with
|
|
103
117
|
* the flat where the flat is. The shaft goes in from z = 0, its tip going to z = depth.
|
|
104
|
-
* @param {Motor} m @param {{ depth: number, fit?: 'slide' | 'press', printer?: object }} p as boreModel
|
|
118
|
+
* @param {Motor} m @param {{ depth: number, tip?: number, fit?: 'slide' | 'press', printer?: object }} p as boreModel
|
|
105
119
|
* @param {{ union: Function, subtract: Function }} [ops] @returns {object} a JSCAD solid to subtract
|
|
106
120
|
*/
|
|
107
121
|
export function bore(m: Motor, p: {
|
|
108
122
|
depth: number;
|
|
123
|
+
tip?: number;
|
|
109
124
|
fit?: "slide" | "press";
|
|
110
125
|
printer?: object;
|
|
111
126
|
}, ops?: {
|
package/motors.mjs
CHANGED
|
@@ -39,7 +39,7 @@ export const DEFAULTS = {
|
|
|
39
39
|
running: { value: Math.SQRT1_2, unit: '× holding torque', rule: 'A stepper moving, against holding torque: holding has both phases at full current, and a driver moving it keeps the vector the size of one phase, 1/√2 of that', kind: 'spec' },
|
|
40
40
|
supply: { value: 24, unit: 'V', rule: 'The stepper driver\'s supply, if you don\'t say: above the motor\'s rated volts, as a chopper drive needs, and what a printer\'s board runs at', kind: 'default' },
|
|
41
41
|
fit: { value: 0.1, unit: 'mm', rule: 'Gap each side of a shaft in its bore, with the printed hole\'s shrinkage allowed for, so it slides on and no more', kind: 'estimate' },
|
|
42
|
-
press: { value: -0.
|
|
42
|
+
press: { value: -0.02, unit: 'mm', rule: 'Each side of a shaft in a press-fit bore as printed: a hair tight, 0.8% strain on a 5 mm shaft, well inside what PLA stretches to before it cracks. A D flat does the driving', kind: 'estimate' },
|
|
43
43
|
grip: { value: 1.5, unit: '× shaft diameter', rule: 'The shortest length of bore worth trusting to drive a gear', kind: 'community' }
|
|
44
44
|
};
|
|
45
45
|
const D = (k) => DEFAULTS[k].value;
|
|
@@ -151,6 +151,17 @@ function dSection(d, flats, across) {
|
|
|
151
151
|
* @returns {object} a JSCAD solid
|
|
152
152
|
*/
|
|
153
153
|
export function motor(m, ops = booleans) {
|
|
154
|
+
isModel('motor', m);
|
|
155
|
+
const { body, shaft } = motorParts(m, ops);
|
|
156
|
+
return shaft ? ops.union(body, shaft) : body;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The motor's body and its shaft as two solids (null where the bell is the output), so an assembly can let the shaft
|
|
161
|
+
* turn in what it drives while the body stays checked against everything else.
|
|
162
|
+
* @param {Motor} m @param {{ union: Function, subtract: Function }} [ops] @returns {{ body: object, shaft: object | null }}
|
|
163
|
+
*/
|
|
164
|
+
export function motorParts(m, ops = booleans) {
|
|
154
165
|
isModel('motor', m);
|
|
155
166
|
const { body, boss, shaft, mount: h } = m, [cx, cy] = body.centre, parts = [];
|
|
156
167
|
const low = -body.length, high = body.top;
|
|
@@ -163,14 +174,16 @@ export function motor(m, ops = booleans) {
|
|
|
163
174
|
if (h.ear) parts.push(box(h.holes[0][0], h.holes[1][0], cy - h.ear, cy + h.ear, -h.earThickness, 0));
|
|
164
175
|
if (h.tab) parts.push(box(cx - h.tab / 2, cx + h.tab / 2, cy - body.depth / 2, cy + body.depth / 2, 0, h.tabThickness));
|
|
165
176
|
if (boss.height) parts.push(disc(boss.diameter, high, high + boss.height));
|
|
166
|
-
let solid = ops.union(parts);
|
|
177
|
+
let solid = ops.union(parts), rod = null;
|
|
167
178
|
if (m.type === 'brushless') solid = ops.subtract(solid, disc(shaft.diameter, low - 1, high + 1));
|
|
168
179
|
else if (shaft.length) {
|
|
169
|
-
const flatFrom = shaft.flats ? shaft.tip - shaft.flatLength : shaft.tip;
|
|
170
|
-
|
|
180
|
+
const flatFrom = shaft.flats ? shaft.tip - shaft.flatLength : shaft.tip, rods = [];
|
|
181
|
+
if (flatFrom > shaft.base) rods.push(disc(shaft.diameter, shaft.base, flatFrom));
|
|
182
|
+
if (shaft.flats) rods.push(translate([0, 0, Math.max(flatFrom, shaft.base)], extrude(shaft.tip - Math.max(flatFrom, shaft.base), dSection(shaft.diameter, shaft.flats, shaft.across))));
|
|
183
|
+
rod = rods.length > 1 ? ops.union(rods) : rods[0];
|
|
171
184
|
}
|
|
172
|
-
if (h.holes.length &&
|
|
173
|
-
return solid;
|
|
185
|
+
if (h.holes.length && h.ear) solid = ops.subtract(solid, h.holes.map((p) => disc(h.diameter, -h.earThickness - 1, 1, p)));
|
|
186
|
+
return { body: solid, shaft: rod };
|
|
174
187
|
}
|
|
175
188
|
|
|
176
189
|
// The printer's clearances, from its rule set, with a design's own printer laid over them
|
|
@@ -244,7 +257,8 @@ export function mount(m, p, ops = booleans) {
|
|
|
244
257
|
|
|
245
258
|
/**
|
|
246
259
|
* A bore for the motor's shaft, as numbers, with what's wrong with it.
|
|
247
|
-
* @param {Motor} m @param {{ depth: number, fit?: 'slide' | 'press', printer?: object }} p depth:
|
|
260
|
+
* @param {Motor} m @param {{ depth: number, tip?: number, fit?: 'slide' | 'press', printer?: object }} p depth: the bore's
|
|
261
|
+
* length; tip: how far from the bore's mouth the shaft's tip sits (default depth; more, if the tip comes out the far side)
|
|
248
262
|
* @returns {{ depth: number, diameter: number, across: number, flats: number, flatFrom: number, grip: number, findings: object[] }}
|
|
249
263
|
* flatFrom: the height in the bore where the flat starts (the shaft's tip end is at depth); below it the bore is round, so the round root of the shaft can pass
|
|
250
264
|
*/
|
|
@@ -254,20 +268,22 @@ export function boreModel(m, p) {
|
|
|
254
268
|
const depth = positive(what, 'depth', p.depth), fit = p.fit ?? 'slide';
|
|
255
269
|
if (!['slide', 'press'].includes(fit)) throw new Error(`${what}: fit is slide or press (got ${shown(fit)})`);
|
|
256
270
|
if (m.type === 'servo' || m.type === 'brushless') throw new Error(`${what}: a ${m.type}'s output is ${m.type === 'servo' ? 'a spline finer than a printer draws: drive it through its horn' : 'its bell: bolt to that'}, not a bore`);
|
|
257
|
-
const
|
|
271
|
+
const tip = p.tip ?? depth;
|
|
272
|
+
if (!(isNum(tip) && tip > 0)) throw new Error(`${what}: tip is how far from the bore's mouth the shaft's tip sits, above 0 (got ${shown(p.tip)})`);
|
|
273
|
+
const pr = printerOf(p.printer), { shaft } = m, each = fit === 'slide' ? D('fit') : D('press'), diameter = shaft.diameter + 2 * each + pr.holeComp, flatFrom = Math.max(0, tip - shaft.flatLength), flat = Math.max(0, Math.min(depth, tip) - flatFrom);
|
|
258
274
|
const out = [], f = (level, text, code) => out.push({ level, text, code });
|
|
259
275
|
if (depth > shaft.length) f('warn', `the bore is ${depth} mm deep and the shaft only ${shaft.length} mm long: the last ${+(depth - shaft.length).toFixed(2)} mm holds nothing`, 'bore.depth');
|
|
260
|
-
const grip = Math.min(depth, shaft.length), want = D('grip') * shaft.diameter;
|
|
261
|
-
if (grip < want) f('warn', `only ${+grip.toFixed(2)} mm of the shaft is in the bore: ${want} mm or more, or the part rocks on it`, 'bore.grip');
|
|
276
|
+
const grip = Math.min(depth, shaft.length), want = shaft.flats ? Math.min(D('grip') * shaft.diameter, 0.8 * shaft.flatLength) : D('grip') * shaft.diameter;
|
|
277
|
+
if (grip < want) f('warn', `only ${+grip.toFixed(2)} mm of the shaft is in the bore: ${r3(want)} mm or more, or the part rocks on it`, 'bore.grip');
|
|
262
278
|
if (shaft.flats && flat < 0.5 * want) f('warn', `only ${+flat.toFixed(2)} mm of bore meets the flat: it's the flat that turns the part`, 'bore.flat');
|
|
263
279
|
if (!shaft.flats) f('warn', 'this shaft has no flat: only friction or a grub screw turns the part', 'bore.flat');
|
|
264
|
-
return { depth, diameter: r3(diameter), across: r3(shaft.across + 2 * each + pr.holeComp), flats: shaft.flats, flatFrom
|
|
280
|
+
return { depth, diameter: r3(diameter), across: r3(shaft.across + 2 * each + pr.holeComp), flats: shaft.flats, flatFrom, grip, fit, findings: out };
|
|
265
281
|
}
|
|
266
282
|
|
|
267
283
|
/**
|
|
268
284
|
* The bore a gear or hub takes for the motor's shaft, to subtract: round where the round of the shaft passes, with
|
|
269
285
|
* the flat where the flat is. The shaft goes in from z = 0, its tip going to z = depth.
|
|
270
|
-
* @param {Motor} m @param {{ depth: number, fit?: 'slide' | 'press', printer?: object }} p as boreModel
|
|
286
|
+
* @param {Motor} m @param {{ depth: number, tip?: number, fit?: 'slide' | 'press', printer?: object }} p as boreModel
|
|
271
287
|
* @param {{ union: Function, subtract: Function }} [ops] @returns {object} a JSCAD solid to subtract
|
|
272
288
|
*/
|
|
273
289
|
export function bore(m, p, ops = booleans) {
|
package/package.json
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/motors",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Motors for printed machines: steppers, DC gear motors, servos and brushless motors from their datasheets, as models with sourced figures, solids to place in an assembly, the mounts and D-bores a part takes for them, and what torque and speed reach the output.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./motors.d.mts",
|
|
9
9
|
"default": "./motors.mjs"
|
|
10
|
+
},
|
|
11
|
+
"./diagram": {
|
|
12
|
+
"types": "./diagram.d.mts",
|
|
13
|
+
"default": "./diagram.mjs"
|
|
10
14
|
}
|
|
11
15
|
},
|
|
12
16
|
"types": "./motors.d.mts",
|
|
13
17
|
"files": [
|
|
14
18
|
"motors.mjs",
|
|
19
|
+
"diagram.mjs",
|
|
15
20
|
"motors.d.mts",
|
|
21
|
+
"diagram.d.mts",
|
|
16
22
|
"README.md",
|
|
17
23
|
"LICENSE"
|
|
18
24
|
],
|