@rulecad/motors 0.1.5 → 0.1.7
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/CHANGELOG.md +47 -0
- package/README.md +20 -4
- package/motors.d.mts +24 -9
- package/motors.mjs +67 -32
- package/package.json +3 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Changelog: @rulecad/motors
|
|
2
|
+
|
|
3
|
+
What changed in each release, for someone upgrading a workspace. A **printed size** is a dimension of a part you
|
|
4
|
+
print (a hole's diameter, a seat's depth, a part's outline). Each release says whether any printed size moved, and
|
|
5
|
+
why.
|
|
6
|
+
|
|
7
|
+
## 0.1.7: bores from shapes' shaftBore
|
|
8
|
+
### Changed
|
|
9
|
+
|
|
10
|
+
- `boreModel` and `bore` read their fit from `@rulecad/shapes`' `shaftBore` (#307), the one place every shaft bore in
|
|
11
|
+
the kit reads it. `DEFAULTS.fit` and `DEFAULTS.press` are now the same objects as `SHAFT_FITS.slide` and
|
|
12
|
+
`SHAFT_FITS.press`, with a source and a date. The package depends on `@rulecad/shapes`, which fixings already did, at the release that
|
|
13
|
+
first ships `shaftBore`. A printer's `hole_comp` below 0 is still taken.
|
|
14
|
+
|
|
15
|
+
### Printed sizes
|
|
16
|
+
|
|
17
|
+
- None moved: a NEMA 17's bore is still 5.2 mm (4.7 across its flat) at slide and 5.06 mm (4.56) at press.
|
|
18
|
+
|
|
19
|
+
## 0.1.6: motors mount through fixings (Fixings 3)
|
|
20
|
+
|
|
21
|
+
### What reads fixings now
|
|
22
|
+
|
|
23
|
+
- `mountModel` and `mount()` take their screw from `@rulecad/fixings` (`fixingModel`), and cut fixings' clearance hole
|
|
24
|
+
and counterbore. The package's own private table of thread names is gone, so a motor's screw and a design's screw
|
|
25
|
+
are the same model, with the same sourced figures.
|
|
26
|
+
- `screw` is a fixing's name: a thread (`'M3'`), whose length is worked out from the plate, or a whole screw
|
|
27
|
+
(`'M3x8 cap'`), whose length is checked as it is.
|
|
28
|
+
- New dependency: `@rulecad/fixings`.
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- `mount.engagement`: the screw's length past the plate, held to the motor's `mount_hole_depth`, must be at least one
|
|
33
|
+
diameter (`engagement.steel` in `@rulecad/rules`). So an M3x6 through a 6 mm plate into a NEMA 17 fails: it ends at
|
|
34
|
+
the motor's face.
|
|
35
|
+
- A thread the motor's tapped holes do not take is refused by name, with the thread they do take.
|
|
36
|
+
|
|
37
|
+
### Printed sizes that moved
|
|
38
|
+
|
|
39
|
+
None. The solid `mount()` cuts is the same for every motor in the kit: a test holds each one's volume and bounds to
|
|
40
|
+
the figures recorded before the change.
|
|
41
|
+
|
|
42
|
+
### What a workspace should change
|
|
43
|
+
|
|
44
|
+
- A design that passed a screw name the motor's holes do not take (an M4 screw for an M3-tapped NEMA 17) is now
|
|
45
|
+
refused: name the motor's own thread.
|
|
46
|
+
- A plate too thin or too thick for a sold screw to reach the motor's thread now gets a `mount.engagement` failure,
|
|
47
|
+
where it used to pass. Change the plate's thickness or name a whole screw that reaches.
|
package/README.md
CHANGED
|
@@ -66,9 +66,24 @@ package's `vocabulary.json`), handed in where the name goes.
|
|
|
66
66
|
## Holding a motor
|
|
67
67
|
|
|
68
68
|
`mount(model, { plate, printer?, screw?, counterbore?, recess? }, ops?)` is the negative a part subtracts; `mountModel`
|
|
69
|
-
gives the same as numbers, with what's wrong (a plate too thin for its screws, a boss pocket as deep as the plate
|
|
70
|
-
Clearances come from the printer's rules (`fit`, `hole_comp`)
|
|
71
|
-
|
|
69
|
+
gives the same as numbers, with what's wrong (a plate too thin for its screws, a boss pocket as deep as the plate, a
|
|
70
|
+
screw that does not hold in the motor's thread). Clearances come from the printer's rules (`fit`, `hole_comp`). The
|
|
71
|
+
screws are `@rulecad/fixings` models (`fixingModel`), and their holes and counterbores are its `hole` (a clearance hole)
|
|
72
|
+
and `counterbore`, so a printer of your own or a screw you've measured carries through.
|
|
73
|
+
|
|
74
|
+
`screw` is a fixing's name: a thread (`'M3'`), whose length is worked out from the plate, or a whole screw
|
|
75
|
+
(`'M3x8 cap'`), whose length is checked as it is. Where the motor's holes are tapped, the screw is on their thread
|
|
76
|
+
(`mount_hole_thread`), and a screw of another thread is refused by name. Its engagement is checked as
|
|
77
|
+
`mount.engagement`:
|
|
78
|
+
|
|
79
|
+
| What | Formula | Source |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| Length worked out | L = floor(t + min(d_tap, 2.5 d)), t the plate under the head (less the head's height where it is counterbored) | Into the motor's thread as far as it goes, up to 2.5 diameters |
|
|
82
|
+
| Thread engaged | e = min(L - t, d_tap), d_tap the motor's `mount_hole_depth` | The screw's length past the plate, held to the depth the maker tapped |
|
|
83
|
+
| Fails | e < 1 × d | `engagement.steel` in `@rulecad/rules`: about one diameter is the least any metal is given (Nord-Lock, Bossard); a motor's face is metal, and its maker's depth is all there is |
|
|
84
|
+
|
|
85
|
+
So an M3x6 through a 6 mm plate into a NEMA 17 fails (it ends at the motor's face), and the M3x9 worked out for a
|
|
86
|
+
5 mm plate passes, with 4 mm of the motor's 4.5 mm of thread.
|
|
72
87
|
|
|
73
88
|
Where the part goes: on the shaft's side of the mounting face, z from 0 to `plate`, so the boss enters a pocket and the
|
|
74
89
|
shaft passes through. A servo goes through the part instead: its body down a slot, its tabs on top, z from `-plate` to 0.
|
|
@@ -76,7 +91,8 @@ shaft passes through. A servo goes through the part instead: its body down a slo
|
|
|
76
91
|
`bore(model, { depth, fit?, printer? }, ops?)` is the hole a gear or hub takes, with the shaft's flat in it. The shaft
|
|
77
92
|
goes in from z = 0 with its tip at `depth`: the flat is cut only where the flat is, so a bore deeper than the flat is
|
|
78
93
|
round at its mouth and the shaft's round root can pass. `boreModel` warns of a bore that grips too little of the shaft
|
|
79
|
-
or misses its flat.
|
|
94
|
+
or misses its flat. Its fit, `slide` (the default, measured on the fit bar) or `press`, is `@rulecad/shapes`'
|
|
95
|
+
`shaftBore`'s, the one place every shaft bore in the kit reads it, so a pulley on the same shaft gets the same bore. A servo's spline is finer than a printer draws: drive it through its horn. A brushless motor drives
|
|
80
96
|
through its bell.
|
|
81
97
|
|
|
82
98
|
Anchors for placing a motor in an assembly are on the model: `face`, `shaft` (where the shaft leaves the motor), `tip`,
|
package/motors.d.mts
CHANGED
|
@@ -42,14 +42,19 @@ export function motorParts(m: Motor, ops?: {
|
|
|
42
42
|
shaft: object | null;
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
|
-
* What a part needs to hold a motor, as numbers: the pocket, the holes, the screws. mount() cuts it.
|
|
45
|
+
* What a part needs to hold a motor, as numbers: the pocket, the holes, the screws. mount() cuts it. The screws are
|
|
46
|
+
* @rulecad/fixings' models, their holes and seats its clearance hole and counterbore. Where the motor's holes are
|
|
47
|
+
* tapped, the screw's engagement in them is checked (mount.engagement): the length past the plate, held to the
|
|
48
|
+
* motor's mount_hole_depth, against one screw diameter (engagement.steel, the least any metal is given).
|
|
46
49
|
* @param {Motor} m
|
|
47
50
|
* @param {{ plate: number, printer?: object, screw?: string, counterbore?: boolean, recess?: number }} p
|
|
48
|
-
* plate: the part's thickness at the mount (mm); printer: its fit, hole_comp, layer; screw: the screws
|
|
49
|
-
* a motor's plain holes
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
51
|
+
* plate: the part's thickness at the mount (mm); printer: its fit, hole_comp, layer; screw: the screws, by a fixing's
|
|
52
|
+
* name: a thread ('M3', for a motor's plain holes; the size they take if not said) or a whole screw with its length
|
|
53
|
+
* and head ('M3x8 cap'), whose length is then checked rather than worked out; counterbore: sink the screw heads;
|
|
54
|
+
* recess: let the body into the part this far as well
|
|
55
|
+
* @returns {{ plate: number, side: 1 | -1, pocket: number, pocketDepth: number, shaftHole: number, holes: { at: number[], diameter: number }[], screw: { thread: string, name: string, clearance: number, head: number, headHeight: number, model: object }, screwLength: number, head: number | null, recess: number, engaged: number | null, printer: object, findings: object[] }}
|
|
56
|
+
* side: which side of the mounting face the plate is on, +1 above it (a motor's face against the part), -1 below it
|
|
57
|
+
* (a servo through it); screw.model: the fixing (fixingModel); engaged: the thread engaged in the motor (mm), where its holes are tapped
|
|
53
58
|
*/
|
|
54
59
|
export function mountModel(m: Motor, p: {
|
|
55
60
|
plate: number;
|
|
@@ -67,16 +72,26 @@ export function mountModel(m: Motor, p: {
|
|
|
67
72
|
at: number[];
|
|
68
73
|
diameter: number;
|
|
69
74
|
}[];
|
|
70
|
-
screw:
|
|
71
|
-
|
|
75
|
+
screw: {
|
|
76
|
+
thread: string;
|
|
77
|
+
name: string;
|
|
78
|
+
clearance: number;
|
|
79
|
+
head: number;
|
|
80
|
+
headHeight: number;
|
|
81
|
+
model: object;
|
|
82
|
+
};
|
|
83
|
+
screwLength: number;
|
|
72
84
|
head: number | null;
|
|
73
85
|
recess: number;
|
|
86
|
+
engaged: number | null;
|
|
87
|
+
printer: object;
|
|
74
88
|
findings: object[];
|
|
75
89
|
};
|
|
76
90
|
/**
|
|
77
91
|
* The negative a part subtracts to hold a motor. For most motors the plate sits on the mounting face, on the shaft's
|
|
78
92
|
* side (z from 0 to plate); a servo's plate is under its tabs, with the body through a slot (z from -plate to 0). The
|
|
79
|
-
* part goes where the motor's mounting face is.
|
|
93
|
+
* part goes where the motor's mounting face is. The screws' holes and their counterbores are @rulecad/fixings' hole
|
|
94
|
+
* and counterbore; a servo's pilots are sized from its tabs' own holes.
|
|
80
95
|
* @param {Motor} m @param {{ plate: number, printer?: object, screw?: string, counterbore?: boolean, recess?: number }} p as mountModel
|
|
81
96
|
* @param {{ union: Function, subtract: Function }} [ops] the design's v.ops
|
|
82
97
|
* @returns {object} a JSCAD solid to subtract
|
package/motors.mjs
CHANGED
|
@@ -15,10 +15,9 @@ import sg90 from '@rulecad/rules/sg90.json' with { type: 'json' };
|
|
|
15
15
|
import mg90s from '@rulecad/rules/mg90s.json' with { type: 'json' };
|
|
16
16
|
import bldc2204 from '@rulecad/rules/bldc2204.json' with { type: 'json' };
|
|
17
17
|
import x1c from '@rulecad/rules/x1c.json' with { type: 'json' };
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import m4 from '@rulecad/rules/m4.json' with { type: 'json' };
|
|
18
|
+
import engagementSet from '@rulecad/rules/engagement.json' with { type: 'json' };
|
|
19
|
+
import { fixingModel, threads, holeModel, hole, counterboreModel, counterbore } from '@rulecad/fixings';
|
|
20
|
+
import { shaftBore, SHAFT_FITS } from '@rulecad/shapes';
|
|
22
21
|
|
|
23
22
|
export { driver, setting, powerBudget, DRIVER_EFFICIENCY } from './drivers.mjs';
|
|
24
23
|
|
|
@@ -28,7 +27,6 @@ const { translate } = jscad.transforms;
|
|
|
28
27
|
const booleans = { union: jscad.booleans.union, subtract: jscad.booleans.subtract };
|
|
29
28
|
|
|
30
29
|
const CATALOGUE = Object.fromEntries([nema17, nema14, byj, n20, sg90, mg90s, bldc2204].map((s) => [s.name, s]));
|
|
31
|
-
const SCREWS = { 'M1.6': m1_6, M2: m2, M3: m3, M4: m4 };
|
|
32
30
|
const key = (s) => String(s).toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
33
31
|
const ALIASES = { ...Object.fromEntries(Object.keys(CATALOGUE).map((n) => [key(n), n])), byj48: '28byj48', '28byj': '28byj48', mg90: 'mg90s', '2204': 'bldc2204', gimbal2204: 'bldc2204', n20gearmotor: 'n20' };
|
|
34
32
|
for (const s of Object.values(CATALOGUE)) for (const v of Object.keys(s.variants || {})) ALIASES[key(v)] = s.name;
|
|
@@ -40,8 +38,9 @@ for (const s of Object.values(CATALOGUE)) for (const v of Object.keys(s.variants
|
|
|
40
38
|
export const DEFAULTS = {
|
|
41
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' },
|
|
42
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' },
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
// a shaft's bore fits, from @rulecad/shapes, where every shaft bore in the kit reads them (the same objects)
|
|
42
|
+
fit: SHAFT_FITS.slide,
|
|
43
|
+
press: SHAFT_FITS.press,
|
|
45
44
|
grip: { value: 1.5, unit: '× shaft diameter', rule: 'The shortest length of bore worth trusting to drive a gear', kind: 'community' }
|
|
46
45
|
};
|
|
47
46
|
const D = (k) => DEFAULTS[k].value;
|
|
@@ -190,53 +189,87 @@ export function motorParts(m, ops = booleans) {
|
|
|
190
189
|
|
|
191
190
|
// The printer's clearances, from its rule set, with a design's own printer laid over them
|
|
192
191
|
function printerOf(p) { return { fit: p?.fit ?? x1c.rules.fit.value, holeComp: p?.hole_comp ?? x1c.rules.hole_comp.value, layer: p?.layer ?? x1c.rules.layer.value, line: p?.line ?? x1c.rules.line.value }; }
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
const an = (thread) => `${/^(M|8-)/.test(thread) ? 'an' : 'a'} ${thread}`;
|
|
193
|
+
// The screw that holds a motor, from @rulecad/fixings: on the thread its holes are tapped (a stepper's face), else the
|
|
194
|
+
// one asked for, else the size its plain holes take. A screw asked for by its whole name ('M3x8 cap') brings its length
|
|
195
|
+
// and head; a thread alone ('M3') is a cap screw, its length worked out from the plate
|
|
196
|
+
function screwOf(what, m, said) {
|
|
197
|
+
const h = m.mount, made = (name) => { try { return fixingModel(name, {}, { anyLength: true }); } catch (e) { throw new Error(`${what}: ${String(e.message).replace(/^fixingModel: /, '')}`); } };
|
|
198
|
+
if (said != null && (typeof said !== 'string' || !said.trim())) throw new Error(`${what}: screw is a screw's name ('M3', or 'M3x8 cap' with its length and head), not ${shown(said)}`);
|
|
199
|
+
const asked = said == null ? null : made(said);
|
|
200
|
+
if (asked && asked.item !== 'thread' && asked.item !== 'screw') throw new Error(`${what}: screw is a screw's name ('M3', or 'M3x8 cap' with its length and head), and "${said}" is ${asked.item === 'insert' ? 'an' : 'a'} ${asked.item}`);
|
|
201
|
+
const thread = h.thread ?? asked?.thread ?? (h.diameter >= 4 ? 'M4' : h.diameter >= 3 ? 'M3' : 'M2');
|
|
202
|
+
if (h.thread && asked && asked.thread !== h.thread) throw new Error(`${what}: ${m.name}'s holes are tapped ${h.thread} (${m.name}.mount_hole_thread), so ${an(asked.thread)} screw does not go in them: give ${h.thread}, or leave screw out`);
|
|
203
|
+
if (!threads().includes(thread)) throw new Error(`${what}: no screw "${thread}" (${threads().join(', ')})`);
|
|
204
|
+
return asked?.item === 'screw' ? asked : made(`${thread} cap`);
|
|
196
205
|
}
|
|
206
|
+
// The engagement rule a screw in a motor's tapped hole is held to: the least any metal is given, as the motor's own
|
|
207
|
+
// thread is metal and its depth is the maker's
|
|
208
|
+
const LEAST = engagementSet.rules.steel;
|
|
209
|
+
// fixings' cutters start this far outside the face they enter by (its draw.mjs OUT), so a cut drawn from over the
|
|
210
|
+
// face starts where the motor's own cutters always have
|
|
211
|
+
const LIP = 0.1;
|
|
197
212
|
|
|
198
213
|
/**
|
|
199
|
-
* What a part needs to hold a motor, as numbers: the pocket, the holes, the screws. mount() cuts it.
|
|
214
|
+
* What a part needs to hold a motor, as numbers: the pocket, the holes, the screws. mount() cuts it. The screws are
|
|
215
|
+
* @rulecad/fixings' models, their holes and seats its clearance hole and counterbore. Where the motor's holes are
|
|
216
|
+
* tapped, the screw's engagement in them is checked (mount.engagement): the length past the plate, held to the
|
|
217
|
+
* motor's mount_hole_depth, against one screw diameter (engagement.steel, the least any metal is given).
|
|
200
218
|
* @param {Motor} m
|
|
201
219
|
* @param {{ plate: number, printer?: object, screw?: string, counterbore?: boolean, recess?: number }} p
|
|
202
|
-
* plate: the part's thickness at the mount (mm); printer: its fit, hole_comp, layer; screw: the screws
|
|
203
|
-
* a motor's plain holes
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
220
|
+
* plate: the part's thickness at the mount (mm); printer: its fit, hole_comp, layer; screw: the screws, by a fixing's
|
|
221
|
+
* name: a thread ('M3', for a motor's plain holes; the size they take if not said) or a whole screw with its length
|
|
222
|
+
* and head ('M3x8 cap'), whose length is then checked rather than worked out; counterbore: sink the screw heads;
|
|
223
|
+
* recess: let the body into the part this far as well
|
|
224
|
+
* @returns {{ plate: number, side: 1 | -1, pocket: number, pocketDepth: number, shaftHole: number, holes: { at: number[], diameter: number }[], screw: { thread: string, name: string, clearance: number, head: number, headHeight: number, model: object }, screwLength: number, head: number | null, recess: number, engaged: number | null, printer: object, findings: object[] }}
|
|
225
|
+
* side: which side of the mounting face the plate is on, +1 above it (a motor's face against the part), -1 below it
|
|
226
|
+
* (a servo through it); screw.model: the fixing (fixingModel); engaged: the thread engaged in the motor (mm), where its holes are tapped
|
|
207
227
|
*/
|
|
208
228
|
export function mountModel(m, p) {
|
|
209
229
|
const what = 'mount';
|
|
210
230
|
isModel(what, m);
|
|
211
231
|
if (!p || typeof p !== 'object') throw new Error(`${what}: give the part's { plate } (its thickness at the mount, mm), not ${shown(p)}`);
|
|
212
|
-
const plate = positive(what, 'plate', p.plate), pr = printerOf(p.printer), { mount: h, boss, shaft } = m, out = [], f = (level, text, code) => out.push({ level, text, code });
|
|
213
|
-
const
|
|
214
|
-
|
|
232
|
+
const plate = positive(what, 'plate', p.plate), pr = printerOf(p.printer), { mount: h, boss, shaft } = m, out = [], f = (level, text, code, extra = {}) => out.push({ level, text, code, ...extra });
|
|
233
|
+
const fx = screwOf(what, m, p.screw), thread = fx.thread, d = fx.major, values = { fit: pr.fit, hole_comp: pr.holeComp, layer: pr.layer };
|
|
234
|
+
const clear = holeModel(fx, { kind: 'clearance', printer: values }), seat = p.counterbore ? counterboreModel(fx, { printer: values }) : null;
|
|
235
|
+
const screw = { thread, name: fx.name, clearance: clear.nominal, head: fx.head.across, headHeight: fx.head.height, model: fx };
|
|
215
236
|
const pocket = boss.diameter ? boss.diameter + 2 * pr.fit + pr.holeComp : 0, pocketDepth = boss.height ? boss.height + 2 * pr.layer : 0;
|
|
216
237
|
const shaftHole = shaft.diameter + 2 * pr.fit + pr.holeComp + 0.4;
|
|
217
|
-
const
|
|
218
|
-
const
|
|
219
|
-
const head = p.counterbore ? screw.head + 2 * pr.fit + pr.holeComp : null;
|
|
238
|
+
const holeD = m.type === 'servo' ? h.diameter - 0.4 + pr.holeComp : clear.diameter;
|
|
239
|
+
const head = seat ? seat.diameter : null;
|
|
220
240
|
if (pocketDepth >= plate && m.mount.side === 1) f('fail', `the plate is ${plate} mm thick and the boss's pocket ${pocketDepth} mm deep: it needs to be thicker than that, or it's only a hole`, 'mount.plate');
|
|
221
241
|
const thickest = h.thread ? h.depth : 0;
|
|
222
|
-
// a screw's length: through the plate, into the thread, its head sunk or not
|
|
242
|
+
// a screw's length: through the plate, into the thread, its head sunk or not; or the one asked for
|
|
223
243
|
const under = plate - (p.counterbore ? screw.headHeight : 0);
|
|
224
|
-
const screwLength = h.thread ? Math.floor(under + Math.min(thickest, 2.5 *
|
|
244
|
+
const screwLength = fx.length ?? (h.thread ? Math.floor(under + Math.min(thickest, 2.5 * d)) : Math.ceil(plate + (h.earThickness || h.tabThickness) + 2));
|
|
225
245
|
if (m.mount.side === 1 && h.thread && under + thickest < screwLength) f('warn', `an ${thread} × ${screwLength} would bottom out in the motor's ${thickest} mm of thread`, 'mount.screw');
|
|
226
|
-
if (plate < 1.5 *
|
|
227
|
-
|
|
246
|
+
if (plate < 1.5 * d) f('warn', `a ${plate} mm plate is thin for ${thread} screws: at least ${1.5 * d} mm, or the head pulls through`, 'mount.plate');
|
|
247
|
+
// the screw's thread in the motor's: what passes the plate, up to the depth the motor is tapped
|
|
248
|
+
let engaged = null;
|
|
249
|
+
if (m.mount.side === 1 && h.thread && thickest > 0) {
|
|
250
|
+
engaged = +Math.max(0, Math.min(screwLength - under, thickest)).toFixed(3);
|
|
251
|
+
const least = +(LEAST.value * d).toFixed(3), n = h.holes.length, name = `${thread}x${+screwLength.toFixed(3)} ${fx.head.form}`, depthRule = `${m.name}.mount_hole_depth`;
|
|
252
|
+
const lengths = fx.figures.lengths?.value ?? [], fits = [...lengths].reverse().find((L) => L - under <= thickest + 1e-9 && L - under >= least - 1e-9);
|
|
253
|
+
const dia = (x) => `${+x.toFixed(2)} diameter${+x.toFixed(2) === 1 ? '' : 's'}`, An = an(thread).replace(/^a/, 'A'), fix = fits ? ` ${An}x${fits} ${fx.head.form} would engage ${+(fits - under).toFixed(3)} mm` : ` No length sold reaches ${least} mm of thread and stops short of the motor's ${thickest} mm: a ${p.counterbore ? 'deeper counterbore' : 'counterbore'} or a thinner plate at the screws`;
|
|
254
|
+
const said = `${n} ${name} screw${n > 1 ? 's' : ''} through ${+under.toFixed(3)} mm of plate`, vals = { values: { engaged, depth: thickest, least, length: screwLength, under: +under.toFixed(3), count: n }, refs: { screw: name, rule: depthRule, least: 'engagement.steel', kind: LEAST.kind } };
|
|
255
|
+
if (screwLength - under <= 1e-9) f('fail', `${said} do not reach the motor's thread: ${name} ends ${under - screwLength > 1e-9 ? `${+(under - screwLength).toFixed(3)} mm short of` : 'at'} its face.${fix}`, 'mount.engagement', vals);
|
|
256
|
+
else if (engaged < least - 1e-9) f('fail', `${said} engage ${engaged} mm of the motor's ${thickest} mm of ${thread} thread (${depthRule}), ${dia(engaged / d)}: less than the ${least} mm (engagement.steel, ${LEAST.value} diameter, the least any metal is given), so the thread strips before the screw holds.${fix}`, 'mount.engagement', vals);
|
|
257
|
+
else f('pass', `${said} engage ${engaged} mm of the motor's ${thickest} mm of ${thread} thread (${depthRule}), ${dia(engaged / d)}, at least the ${least} mm engagement.steel gives any metal`, 'mount.engagement', vals);
|
|
258
|
+
}
|
|
259
|
+
return { plate, side: h.side, pocket: r3(pocket), pocketDepth: r3(pocketDepth), shaftHole: r3(shaftHole), holes: h.holes.map((at) => ({ at, diameter: r3(holeD) })), screw, screwLength, head, recess: p.recess ?? 0, engaged, printer: pr, findings: out };
|
|
228
260
|
}
|
|
229
261
|
|
|
230
262
|
/**
|
|
231
263
|
* The negative a part subtracts to hold a motor. For most motors the plate sits on the mounting face, on the shaft's
|
|
232
264
|
* side (z from 0 to plate); a servo's plate is under its tabs, with the body through a slot (z from -plate to 0). The
|
|
233
|
-
* part goes where the motor's mounting face is.
|
|
265
|
+
* part goes where the motor's mounting face is. The screws' holes and their counterbores are @rulecad/fixings' hole
|
|
266
|
+
* and counterbore; a servo's pilots are sized from its tabs' own holes.
|
|
234
267
|
* @param {Motor} m @param {{ plate: number, printer?: object, screw?: string, counterbore?: boolean, recess?: number }} p as mountModel
|
|
235
268
|
* @param {{ union: Function, subtract: Function }} [ops] the design's v.ops
|
|
236
269
|
* @returns {object} a JSCAD solid to subtract
|
|
237
270
|
*/
|
|
238
271
|
export function mount(m, p, ops = booleans) {
|
|
239
|
-
const g = mountModel(m, p), { plate, pocket, pocketDepth, shaftHole, holes, recess, printer: pr } = g, { body
|
|
272
|
+
const g = mountModel(m, p), { plate, pocket, pocketDepth, shaftHole, holes, recess, printer: pr } = g, { body } = m, [cx, cy] = body.centre, cuts = [], over = 0.5;
|
|
240
273
|
if (m.type === 'servo') {
|
|
241
274
|
// the body through a slot, with the fit all round; the screws' pilot holes in the plate
|
|
242
275
|
cuts.push(box(cx - body.width / 2 - pr.fit, cx + body.width / 2 + pr.fit, cy - body.depth / 2 - pr.fit, cy + body.depth / 2 + pr.fit, -plate - over, over));
|
|
@@ -245,9 +278,11 @@ export function mount(m, p, ops = booleans) {
|
|
|
245
278
|
}
|
|
246
279
|
if (pocket && pocketDepth) cuts.push(disc(pocket, -over, pocketDepth));
|
|
247
280
|
cuts.push(disc(shaftHole, -over, plate + over));
|
|
281
|
+
// each screw's hole down through the plate, from over its top face to under the motor's, its head's seat at the top
|
|
282
|
+
const values = { fit: pr.fit, hole_comp: pr.holeComp, layer: pr.layer }, top = plate + over - LIP, length = plate + 2 * (over - LIP), fx = g.screw.model;
|
|
248
283
|
for (const x of holes) {
|
|
249
|
-
|
|
250
|
-
|
|
284
|
+
const at = [x.at[0], x.at[1], top];
|
|
285
|
+
cuts.push(g.head ? counterbore(fx, { printer: values, at, depth: g.screw.headHeight + over - LIP, length, into: '-z' }) : hole(fx, { kind: 'clearance', printer: values, at, depth: length, into: '-z' }));
|
|
251
286
|
}
|
|
252
287
|
if (recess) {
|
|
253
288
|
if (body.shape === 'round') cuts.push(disc(body.width + 2 * pr.fit + pr.holeComp, -recess - over, 0, [cx, cy]));
|
|
@@ -272,14 +307,14 @@ export function boreModel(m, p) {
|
|
|
272
307
|
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`);
|
|
273
308
|
const tip = p.tip ?? depth;
|
|
274
309
|
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)})`);
|
|
275
|
-
const pr = printerOf(p.printer), { shaft } = m,
|
|
310
|
+
const pr = printerOf(p.printer), { shaft } = m, b = shaftBore(shaft.diameter, { fit, across: shaft.across, printer: { hole_comp: pr.holeComp, fit: pr.fit }, what }), flatFrom = Math.max(0, tip - shaft.flatLength), flat = Math.max(0, Math.min(depth, tip) - flatFrom);
|
|
276
311
|
const out = [], f = (level, text, code) => out.push({ level, text, code });
|
|
277
312
|
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');
|
|
278
313
|
const grip = Math.min(depth, shaft.length), want = shaft.flats ? Math.min(D('grip') * shaft.diameter, 0.8 * shaft.flatLength) : D('grip') * shaft.diameter;
|
|
279
314
|
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');
|
|
280
315
|
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');
|
|
281
316
|
if (!shaft.flats) f('warn', 'this shaft has no flat: only friction or a grub screw turns the part', 'bore.flat');
|
|
282
|
-
return { depth, diameter: r3(diameter), across: r3(
|
|
317
|
+
return { depth, diameter: r3(b.diameter), across: r3(b.across), flats: shaft.flats, flatFrom, grip, fit, findings: out };
|
|
283
318
|
}
|
|
284
319
|
|
|
285
320
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/motors",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"motors.d.mts",
|
|
23
23
|
"diagram.d.mts",
|
|
24
24
|
"README.md",
|
|
25
|
+
"CHANGELOG.md",
|
|
25
26
|
"LICENSE"
|
|
26
27
|
],
|
|
27
28
|
"license": "MIT",
|
|
@@ -33,5 +34,5 @@
|
|
|
33
34
|
"bugs": { "url": "https://github.com/JoniBach/rulecad/issues" },
|
|
34
35
|
"scripts": { "test": "node --test" },
|
|
35
36
|
"peerDependencies": { "@jscad/modeling": "^2.12.0" },
|
|
36
|
-
"dependencies": { "@rulecad/rules": "^0.3.
|
|
37
|
+
"dependencies": { "@rulecad/rules": "^0.3.11", "@rulecad/fixings": "^0.1.3", "@rulecad/shapes": "^0.4.7" }
|
|
37
38
|
}
|