@rulecad/cad 0.7.55 → 0.7.57
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/AGENTS.md +73 -7
- package/CHANGELOG.md +149 -0
- package/EXAMPLES.md +942 -268
- package/README.md +366 -16
- package/TUTORIAL.md +27 -15
- package/bin/cad.mjs +54 -14
- package/lib/assembly.mjs +75 -16
- package/lib/beams.mjs +2 -2
- package/lib/bought.mjs +41 -5
- package/lib/buildpage.mjs +8 -3
- package/lib/design.mjs +6 -4
- package/lib/edit.mjs +36 -5
- package/lib/fasten.mjs +322 -55
- package/lib/fittings.mjs +271 -0
- package/lib/framebuild.mjs +407 -0
- package/lib/frames.mjs +4 -3
- package/lib/guides.mjs +354 -0
- package/lib/jigs.mjs +237 -0
- package/lib/joins.mjs +259 -0
- package/lib/jsonedit.mjs +19 -0
- package/lib/list.mjs +24 -8
- package/lib/loads.mjs +9 -2
- package/lib/measured.mjs +64 -17
- package/lib/motors.mjs +28 -13
- package/lib/order.mjs +23 -12
- package/lib/panels.mjs +220 -0
- package/lib/plates.mjs +11 -4
- package/lib/schema.mjs +3 -2
- package/lib/services.mjs +132 -0
- package/lib/sheet.mjs +20 -3
- package/lib/slotnuts.mjs +159 -0
- package/lib/task.mjs +4 -2
- package/lib/wires.mjs +2 -1
- package/package.json +8 -7
- package/schemas/assembly.schema.json +41 -14
- package/schemas/object.schema.json +2 -2
package/lib/list.mjs
CHANGED
|
@@ -13,14 +13,14 @@ import path from 'node:path';
|
|
|
13
13
|
import { volume } from './mesh.mjs';
|
|
14
14
|
import { wiresFor } from './assembly.mjs';
|
|
15
15
|
import { cutListOf, cutListData } from './beams.mjs';
|
|
16
|
-
import { cutListText } from '@rulecad/frames';
|
|
16
|
+
import { cutListText, printedCost } from '@rulecad/frames';
|
|
17
17
|
|
|
18
18
|
const n = (x, d = 1) => Number(x.toFixed(d));
|
|
19
19
|
|
|
20
20
|
export function materialOf(project) {
|
|
21
21
|
let name = 'pla';
|
|
22
22
|
try { name = String(readJson(path.join(paths.project(project), 'project.json')).material || 'pla').toLowerCase().split(/\s/)[0]; } catch {}
|
|
23
|
-
try { return { name, density:
|
|
23
|
+
try { const set = loadRuleSet(name); return { name, density: set.rules.density.value, ...(set.rules.cost ? { cost: set.rules.cost } : {}) }; } catch { return { name, density: 1.25, assumed: true }; }
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// Every printed thing in the assembly, once for each copy: its volume, grams and minutes
|
|
@@ -41,8 +41,9 @@ export function shoppingList(s) {
|
|
|
41
41
|
const mat = materialOf(s.project), printed = printedParts(s), bought = new Map(), fasteners = new Map();
|
|
42
42
|
for (const o of s.objects) if (o.bought && !o.unplaced) {
|
|
43
43
|
// (a beam by its profile and length: one line for each length cut, lib/beams.mjs)
|
|
44
|
-
|
|
45
|
-
const
|
|
44
|
+
// (a panel by its sheet and size: lib/panels.mjs)
|
|
45
|
+
const len = o.bought.length != null ? Number(o.bought.length.toFixed(2)) : null, size = o.bought.size ?? null, key = `${o.bought.set}|${o.bought.variant ?? ''}|${len ?? ''}|${size ?? ''}`;
|
|
46
|
+
const line = bought.get(key) ?? { set: o.bought.set, variant: o.bought.variant, part: o.bought.part, ...(len != null ? { length: len } : {}), ...(size ? { size } : {}), qty: 0, grams: o.bought.mass != null ? o.bought.mass * 1000 : null, ...(o.bought.cost ? { cost: o.bought.cost.value, currency: o.bought.cost.unit } : {}), items: [] };
|
|
46
47
|
line.qty++; line.items.push(o.id); bought.set(key, line);
|
|
47
48
|
}
|
|
48
49
|
// fasten.count: the hardware a fasten placed (a component's too), one part a piece; a motor's mounting screws; and a fit
|
|
@@ -50,9 +51,11 @@ export function shoppingList(s) {
|
|
|
50
51
|
const add = (name, n, from, more = {}) => { const line = fasteners.get(name) ?? { fastener: name, qty: 0, from: [], ...more }; line.qty += n; if (!line.from.includes(from)) line.from.push(from); fasteners.set(name, line); };
|
|
51
52
|
for (const p of s.parts) if (p.hardware) { const h = p.hardware; add(h.name, 1, h.from ?? h.name, { kind: h.kind, thread: h.thread ?? null, length: h.length ?? null, head: h.head ?? null, grams: h.grams ?? null }); }
|
|
52
53
|
for (const m of motorScrews(s, { placeItems, jointValues })) {
|
|
53
|
-
let grams = null; try { grams = screwModel(m.thread, { length: m.length, head:
|
|
54
|
-
add(
|
|
54
|
+
let grams = null; try { grams = screwModel(m.thread, { length: m.length, head: m.head, anyLength: true }).mass; } catch {}
|
|
55
|
+
add(m.name, m.count, `${m.item} on ${m.other} (its mount, a fit that fastens)`, { kind: 'screw', thread: m.thread, length: m.length, head: m.head, grams });
|
|
55
56
|
}
|
|
57
|
+
// what a printed fitting takes besides its screws: a hinge's pin and its nut, a catch's magnet and strike (lib/fittings.mjs)
|
|
58
|
+
for (const o of s.objects) if (o.fitting?.hardware && !o.unplaced) for (const h of o.fitting.hardware) add(h.name, h.count ?? 1, `${o.id} (${h.why ?? 'its fitting'})`, { kind: h.kind, thread: h.thread ?? null, length: h.length ?? null, head: h.head ?? null, grams: null });
|
|
56
59
|
for (const x of s.fits) if (x.fastener && x.fasten == null) add(x.fastener, x.count != null ? x.num(x.count) : 1, x.note || `${x.a} / ${x.b}`);
|
|
57
60
|
// Rounded up to whole packs (packs.pack), the spares said
|
|
58
61
|
let pack = null; try { const r = loadRuleSet('packs').rules.pack; pack = { size: r.value, rule: 'packs.pack', kind: r.kind }; } catch {}
|
|
@@ -64,13 +67,19 @@ export function shoppingList(s) {
|
|
|
64
67
|
const printedGrams = printed.reduce((t, p) => t + p.grams, 0), boughtGrams = boughtList.reduce((t, b) => t + (b.grams ?? 0) * b.qty, 0), unknown = boughtList.filter((b) => b.grams == null).map((b) => b.set);
|
|
65
68
|
const cut = cutListData(cutListOf(s));
|
|
66
69
|
const fixingsGrams = fixings.reduce((t, f) => t + (f.mass ?? 0), 0);
|
|
67
|
-
|
|
70
|
+
// what it costs, where prices are given: the bought items' by their sets, the printed parts' plastic by the material's
|
|
71
|
+
// price a kilogram; fixings and bars are not priced, and the list says which lines have no price
|
|
72
|
+
const priced = boughtList.filter((b) => b.cost != null), currencies = [...new Set(priced.map((b) => b.currency))];
|
|
73
|
+
const plastic = printedGrams > 0 ? printedCost(printedGrams, { name: mat.name, rules: mat.cost ? { cost: mat.cost } : {} }) : null;
|
|
74
|
+
const cost = priced.length || plastic ? { bought: priced.length && currencies.length === 1 ? n(priced.reduce((t, b) => t + b.cost * b.qty, 0), 2) : null, currency: currencies.length === 1 ? currencies[0] : plastic?.unit ?? null, ...(currencies.length > 1 ? { currencies } : {}),
|
|
75
|
+
unpriced: [...new Set(boughtList.filter((b) => b.cost == null).map((b) => b.set))], printed: plastic ? n(plastic.value, 2) : null, ...(plastic ? { printedUnit: plastic.unit, printedRule: plastic.rule } : {}) } : null;
|
|
76
|
+
return { bought: boughtList, fasteners: fixings, wires: [...wires.values()], printed, cut, ...(cost ? { cost } : {}), totals: { printedGrams: n(printedGrams), boughtGrams: n(boughtGrams), fixingsGrams: n(fixingsGrams), machineGrams: n(printedGrams + boughtGrams + fixingsGrams), ...(pack && fixings.some((f) => f.packs) ? { pack } : {}), minutes: n(printed.reduce((t, p) => t + p.minutes, 0), 0), material: mat.name, ...(mat.assumed ? { densityAssumed: true } : {}), ...(unknown.length ? { noMassFor: unknown } : {}) } };
|
|
68
77
|
}
|
|
69
78
|
|
|
70
79
|
export function listText(ref, l) {
|
|
71
80
|
const out = [`${ref}: what it takes to build`];
|
|
72
81
|
const row = (a) => out.push(a.join(' '));
|
|
73
|
-
if (l.bought.length) { out.push('', 'Bought'); for (const b of l.bought) row([` ${String(b.qty).padStart(3)} ×`, `${b.set}${b.variant ? ` (${b.variant})` : ''}${b.length != null ? ` x ${b.length} mm` : ''}`, `a ${b.part}`, b.grams != null ? `${b.grams} g each` : 'mass not given', b.items.join(', ')]); }
|
|
82
|
+
if (l.bought.length) { out.push('', 'Bought'); for (const b of l.bought) row([` ${String(b.qty).padStart(3)} ×`, `${b.set}${b.variant ? ` (${b.variant})` : ''}${b.length != null ? ` x ${b.length} mm` : ''}${b.size ? ` cut ${b.size[0]} x ${b.size[1]} mm` : ''}`, `a ${b.part}`, b.grams != null ? `${b.grams} g each` : 'mass not given', ...(b.cost != null ? [`${b.cost} ${b.currency} each`] : []), b.items.join(', ')]); }
|
|
74
83
|
if (l.cut) { out.push('', `Cut list (kerf ${l.cut.rules.kerf.value} mm, trim ${l.cut.rules.trim.value} mm; a sheet for each mark: cad beams ${ref})`, ...cutListText(l.cut)); }
|
|
75
84
|
if (l.fasteners.length) {
|
|
76
85
|
out.push('', 'Fasteners');
|
|
@@ -80,5 +89,12 @@ export function listText(ref, l) {
|
|
|
80
89
|
if (l.wires.length) { out.push('', 'Wire'); for (const w of l.wires) row([` ${w.length} mm of`, w.gauge ?? 'gauge not given', `in ${w.runs.join(', ')}`]); }
|
|
81
90
|
if (l.printed.length) { out.push('', `Printed (${l.totals.material})`); for (const p of l.printed) row([` ${String(p.grams).padStart(7)} g`, `about ${p.minutes} min`, `${p.id}${p.object && p.object !== p.id ? ` (${p.object})` : ''}`]); }
|
|
82
91
|
out.push('', `Total: ${l.totals.printedGrams} g printed, about ${l.totals.minutes} min of printing (an estimate from volume and the printer's flow), ${l.totals.fixingsGrams ? `${l.totals.fixingsGrams} g of fixings, ` : ''}${l.totals.machineGrams} g as a machine${l.totals.noMassFor ? ` (no mass given for ${l.totals.noMassFor.join(', ')})` : ''}`);
|
|
92
|
+
if (l.cost) {
|
|
93
|
+
const c = l.cost, parts = [];
|
|
94
|
+
if (c.bought != null) parts.push(`${c.bought} ${c.currency} bought${c.unpriced.length ? ` (no price given for ${c.unpriced.join(', ')})` : ''}`);
|
|
95
|
+
else if (c.currencies) parts.push(`bought items priced in ${c.currencies.join(' and ')}, not added together`);
|
|
96
|
+
if (c.printed != null) parts.push(`${c.printed} ${c.printedUnit} of ${l.totals.material} printed (the plastic alone)`);
|
|
97
|
+
out.push(`Cost: ${parts.join(', ')}; fixings and bars are not priced. Prices are each set's, on the date it was checked`);
|
|
98
|
+
}
|
|
83
99
|
return out.join('\n');
|
|
84
100
|
}
|
package/lib/loads.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { solidFill } from './optimise.mjs';
|
|
|
12
12
|
import { materialOf } from './list.mjs';
|
|
13
13
|
import { axisOf, trainFrom, workingSpeed, atCurrent } from './motors.mjs';
|
|
14
14
|
import { sample, chainOf } from './task.mjs';
|
|
15
|
+
import { carriageChecks } from './guides.mjs';
|
|
15
16
|
|
|
16
17
|
const G = 9.80665, sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]], dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
17
18
|
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]], add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]], scale = (a, k) => a.map((x) => x * k);
|
|
@@ -45,7 +46,8 @@ export function massesOf(s, { placeItems, jointValues }) {
|
|
|
45
46
|
const chainSet = (motion, names, q) => Object.fromEntries(names.map((n, i) => { const j = motion.joints.find((x) => x.id === n), lead = j?.follow && !names.includes(j.follow[0]) ? j.follow : null; return lead ? [lead[0], [(q[i] - (lead[2] ?? 0)) / (lead[1] ?? 1)]] : [n, [q[i]]]; }));
|
|
46
47
|
// A mesh's bounding box, as lo and hi: a loop, as a large part's triangles overflow Math.min(...spread)
|
|
47
48
|
function extent(tris) { const lo = [Infinity, Infinity, Infinity], hi = [-Infinity, -Infinity, -Infinity]; for (const t of tris) for (const p of t) for (let k = 0; k < 3; k++) { if (p[k] < lo[k]) lo[k] = p[k]; if (p[k] > hi[k]) hi[k] = p[k]; } return { lo, hi }; }
|
|
48
|
-
|
|
49
|
+
/** Whether an item moves with a joint: the joint is on its chain to the base. */
|
|
50
|
+
export const beyond = (motion, j, item) => { const by = new Map(motion.joints.map((x) => [x.child, x])); for (let i = item, n = 0; i >= 0 && n < 99; n++) { const x = by.get(i); if (!x) return false; if (x === j) return true; i = x.parent; } return false; };
|
|
49
51
|
|
|
50
52
|
// Force and moment about a joint's origin, at one pose
|
|
51
53
|
function loadAt(motion, masses, payload, worlds, j, mul) {
|
|
@@ -59,7 +61,8 @@ function loadAt(motion, masses, payload, worlds, j, mul) {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
// The poses the machine will be in: the task's samples, the named poses, or each joint at its ends
|
|
62
|
-
|
|
64
|
+
/** The poses the machine will be in: the task's samples, the named poses, or each joint at its ends; and as drawn. */
|
|
65
|
+
export function posesOf(s, jointValues) {
|
|
63
66
|
const motion = s.motion, base = jointValues(motion, motion.pose ?? undefined), leads = Object.fromEntries(Object.entries(base).filter(([id]) => !motion.joints.find((x) => x.id === id)?.follow)), out = [];
|
|
64
67
|
for (const p of Object.keys(motion.poses || {})) out.push({ label: `pose ${p}`, values: jointValues(motion, p) });
|
|
65
68
|
if (s.task) { const { c, r } = sample(s), every = Math.max(1, Math.ceil(r.samples.length / 40)); r.samples.filter((x, i) => x.reachable && !(i % every)).forEach((x) => out.push({ label: 'on the task', point: x.point, values: jointValues(motion, { ...leads, ...chainSet(motion, c.names, x.q) }) })); }
|
|
@@ -99,6 +102,7 @@ export function momentChecks(s, f, helpers, masses, payload) {
|
|
|
99
102
|
const mat = (() => { const n = materialOf(s.project).name; try { return Object.fromEntries(Object.entries(peekRuleSet(n).rules).map(([k, r]) => [k, r.value])); } catch { return null; } })();
|
|
100
103
|
for (const j of motion.joints) {
|
|
101
104
|
if (j.type !== 'revolute' && j.type !== 'prismatic') continue;
|
|
105
|
+
if (specs.get(j.id)?._guide) continue; // (a guide's carriage: carriageChecks holds it to its ratings)
|
|
102
106
|
let worst = null;
|
|
103
107
|
for (const p of poses) { const w = placeItems(motion, p.values), L = loadAt(motion, masses, payload, w, j, mul); if (!worst || L.tipping + L.radial / 50 > worst.L.tipping + worst.L.radial / 50) worst = { L, p, w }; }
|
|
104
108
|
if (!worst || !worst.L.carried) continue;
|
|
@@ -214,6 +218,9 @@ function pinv2(J, v) {
|
|
|
214
218
|
|
|
215
219
|
export function loadChecks(s, f, helpers) {
|
|
216
220
|
const motion = s.motion;
|
|
221
|
+
// a guide's carriages are held to their ratings whether or not the machine has a task: they carry what is on them
|
|
222
|
+
// (the masses' centres read against the frames of the pose the parts were built at, which a pose's own check is)
|
|
223
|
+
if (s.guides?.length && motion?.joints?.length) carriageChecks(s, f, helpers, { masses: massesOf(s, { ...helpers, jointValues: (m, p) => s.jointValues ?? helpers.jointValues(m, p) }), beyond, poses: posesOf(s, helpers.jointValues) });
|
|
217
224
|
if (!motion?.joints?.length || !(s.task || s.a.gravity)) return;
|
|
218
225
|
const masses = massesOf(s, helpers), payload = s.task?.payload ? { kg: s.task.payload, item: motion.items.findIndex((x) => x[0] === s.task.item), point: s.task.point } : null;
|
|
219
226
|
const unknown = masses.filter((m) => !m.known).map((m) => m.id);
|
package/lib/measured.mjs
CHANGED
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
// the estimate was (in the workspace's copy of the rule set), or a measurement of something a check predicts (a figure
|
|
3
3
|
// no rule holds, like the pen's error at the far corner), runs the assembly's checks either side, says what moved, and
|
|
4
4
|
// keeps a ledger of predicted against measured beside prints.jsonl. The rules the fixings coupon measures (a pilot or an
|
|
5
|
-
// insert hole per thread, the nut fits, the thread gap and flank form)
|
|
6
|
-
// each is comes from here; a slot's figures go in the workspace's copy of its set,
|
|
5
|
+
// insert hole per thread, the nut fits, the thread gap and flank form), the slot coupon's fits and a slot nut's hold
|
|
6
|
+
// along its slot need no --rule: what each is comes from here; a slot's figures go in the workspace's copy of its set,
|
|
7
|
+
// checked as a slot. A drop measured on the joint rig (join.drop's <beam>.drop) also writes the join's spring, worked
|
|
8
|
+
// out from it, to the rule the spring came from: the joins set (the workspace's copy, started from @rulecad/frames'
|
|
9
|
+
// estimates), a bought fitting's set, or a printed fitting's share of its finite-element figure.
|
|
7
10
|
import fs from 'node:fs';
|
|
8
11
|
import path from 'node:path';
|
|
9
12
|
import { setAt } from './jsonedit.mjs';
|
|
10
13
|
import { CadError } from './errors.mjs';
|
|
11
14
|
import { paths, WS, RULE_DIRS, printerOf } from './workspace.mjs';
|
|
12
|
-
import { loadRuleSet } from './rules.mjs';
|
|
15
|
+
import { loadRuleSet, peekRuleSet } from './rules.mjs';
|
|
13
16
|
import { buildAssembly, checkAssembly, assemblyPath } from './assembly.mjs';
|
|
14
|
-
import { slotModel } from '@rulecad/frames';
|
|
17
|
+
import { slotModel, JOIN_SET, joinRuleSet } from '@rulecad/frames';
|
|
15
18
|
import { fixingsContext } from './design.mjs';
|
|
16
19
|
import { fixingsFor, threads } from '@rulecad/fixings';
|
|
17
20
|
|
|
@@ -24,12 +27,17 @@ const keyOf = (x) => `${x.code}|${JSON.stringify(x.refs ?? {})}`;
|
|
|
24
27
|
// A prediction's name, as cad measured takes it: the check's code, and the part or joint it's about if there are several
|
|
25
28
|
export const predictionsOf = (findings) => findings.filter((x) => x.predict);
|
|
26
29
|
|
|
30
|
+
// A rule's set, read and not written: its text as it starts (the workspace's copy, else the kit's, else for the joins
|
|
31
|
+
// set @rulecad/frames' estimates), so nothing is written until every value has been checked
|
|
27
32
|
function ruleFile(name) {
|
|
28
33
|
const dot = name.indexOf('.');
|
|
29
34
|
if (dot < 1) throw new CadError('measured.name', `"${name}": name a rule as <set>.<rule> (x1c.press), or a prediction by its check's code (task.accuracy)`);
|
|
30
35
|
const set = name.slice(0, dot), rule = name.slice(dot + 1);
|
|
31
|
-
const
|
|
32
|
-
|
|
36
|
+
const file = path.join(WS, 'rules', `${set}.json`), from = RULE_DIRS.map((d) => path.join(d, `${set}.json`)).find((f) => fs.existsSync(f));
|
|
37
|
+
// the joins set has no file in the kit: the workspace's copy starts from @rulecad/frames' estimates
|
|
38
|
+
if (set === JOIN_SET && !from) { const text = JSON.stringify(joinRuleSet(), null, 2) + '\n'; return { set, rule, data: JSON.parse(text), file, text, copied: `started rules/${set}.json from @rulecad/frames' estimates: yours to keep and edit` }; }
|
|
39
|
+
const data = peekRuleSet(set); // (the measurement goes in your copy: the tool's set is copied there when it is written)
|
|
40
|
+
return { set, rule, data, file, text: fs.readFileSync(from, 'utf8'), copied: from === file ? null : `copied the ${set} rule set into rules/${set}.json: yours to keep and edit` };
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
// The slot coupon (examples/bench/projects/benchmarks/MEASURE.md, rows 29 to 33): the two fits it measures, which a
|
|
@@ -47,6 +55,27 @@ function slotRule(project, set, key, data) {
|
|
|
47
55
|
return null;
|
|
48
56
|
}
|
|
49
57
|
|
|
58
|
+
// The joint rig (examples/bench/projects/benchmarks/MEASURE.md, rows 34 to 37): a join's bending spring, written to the
|
|
59
|
+
// joins set or a bought fitting's set, and a slot nut's hold along its slot, which no maker publishes, so a nut's set
|
|
60
|
+
// has no rule for it until it is measured
|
|
61
|
+
const RIG = 'the joint rig (examples/bench/projects/benchmarks/MEASURE.md)';
|
|
62
|
+
function rigRule(set, key, data) {
|
|
63
|
+
if (data.part === 'slot_nut' && key === 'hold_along') return { unit: 'N', predicted: null, was: 'no figure: no maker publishes it', source: `${RIG}, a luggage scale`,
|
|
64
|
+
rule: `The pull along its slot at which this nut slips, its screw tightened as its maker says (or firmly by hand with a hex key where it says nothing): the reading on ${RIG}'s luggage scale as the nut moved` };
|
|
65
|
+
// what a spring measured on the rig is, in place of the estimate's sentence ("a working guess ... until the joint rig
|
|
66
|
+
// measures it"); the drop it came from goes in its source
|
|
67
|
+
const how = `measured on ${RIG}: a beam held out by the join, the drop of its end under a hung mass less the beam's own bending (F L² / that)`;
|
|
68
|
+
const turn = (who) => ({ bending: `How stiffly ${who} holds the end of a beam against turning across its axis`, twist: `How stiffly ${who} holds the end of a beam against twisting about its own axis` });
|
|
69
|
+
if (set === JOIN_SET) {
|
|
70
|
+
const j = key.match(/^(.+)_(bending|twist|printed_share)$/), kind = j?.[1].replace(/_/g, '-');
|
|
71
|
+
if (!j) return { source: RIG };
|
|
72
|
+
return { source: RIG, measuredRule: j[2] === 'printed_share' ? `A ${kind} join with a printed fitting, as a share of the fitting's own bending stiffness by finite elements: the join's spring ${how}, over the fitting's figure`
|
|
73
|
+
: `${turn(`a ${kind} join`)[j[2]]}, for a 20 mm series profile: ${how}` };
|
|
74
|
+
}
|
|
75
|
+
if (data.part === 'fitting' && /_stiffness$/.test(key)) { const k = key.replace(/_stiffness$/, ''); return { source: RIG, ...(turn('this fitting')[k] ? { measuredRule: `${turn('this fitting')[k]}, its screws tight: ${how}` } : {}) }; }
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
50
79
|
// The printer's rules the fixings read that a printer's set may not hold yet, each measured on the fixings coupon
|
|
51
80
|
// (examples/bench/projects/benchmarks/MEASURE.md): what it is, its unit, and what the kit drew before it was measured,
|
|
52
81
|
// so the ledger shows predicted against measured. A pilot or an insert hole is per thread, and may name a plastic
|
|
@@ -94,28 +123,46 @@ export async function recordMeasured(ref, values, { unit, source, rule, date = t
|
|
|
94
123
|
if (!Object.keys(values).length) throw new CadError('measured.usage', 'usage: cad measured <project>/<assembly> <name>=<value> … [--unit mm] [--source "how it was measured"]');
|
|
95
124
|
const before = await findingsOf(ref), entries = [], predictions = predictionsOf(before);
|
|
96
125
|
const writes = [], slots = new Map(); // (every value is checked before any is written, so a refusal leaves the rule sets as they were)
|
|
126
|
+
// a rule's new value, checked before anything is written (a refusal leaves the rule sets as they were)
|
|
127
|
+
const writeRule = (k, value, { from = null, unit: u = unit } = {}) => {
|
|
128
|
+
const { set, rule: key, data, file, text, copied } = ruleFile(k);
|
|
129
|
+
const old = data.rules?.[key], known = slotRule(project, set, key, data) ?? rigRule(set, key, data) ?? fixingsRule(project, set, key) ?? (old ? null : kitRule(set, key));
|
|
130
|
+
if (known?.allowed && !known.allowed.includes(value)) throw new CadError('measured.value', `${k} is ${known.allowed.join(' or ')}: the flank forms the coupon prints (got ${value})`);
|
|
131
|
+
if (!old && !rule && !known) throw new CadError('measured.rule', `${set} has no rule "${key}" (and no check here predicts "${k}"): --rule "what it is" to add it (checks: ${[...new Set(predictions.map((x) => x.code))].join(', ') || 'none'})`);
|
|
132
|
+
const had = old ?? known, prior = typeof had?.value === 'number' ? had.value : known?.predicted ?? null;
|
|
133
|
+
if (u && had?.unit && u !== had.unit) throw new CadError('measured.unit', `${k} is in ${had.unit}, and this is in ${u}: give it in ${had.unit}`);
|
|
134
|
+
// its sentence: what was measured, never the estimate's "until it is measured": the one given, else the rig's, else the rule's own
|
|
135
|
+
const entry = { value, unit: u ?? had?.unit ?? '', rule: (from ? null : rule) ?? known?.measuredRule ?? had.rule, kind: 'measured', source: [source || known?.source || 'measured on the bench', from].filter(Boolean).join(': '), checked: date };
|
|
136
|
+
if (data.part === 'slot') slots.set(set, { data, change: { ...slots.get(set)?.change, [key]: value } });
|
|
137
|
+
writes.push({ file, key, entry, text, copied, set });
|
|
138
|
+
entries.push({ date, assembly: name, name: k, figure: entry.rule, unit: entry.unit, predicted: prior, was: old ? old.kind : known?.was ?? known?.kind ?? null, measured: value, ratio: prior ? value / prior : null, ...(source ? { source } : {}) });
|
|
139
|
+
};
|
|
97
140
|
for (const [k, value] of Object.entries(values)) {
|
|
98
141
|
if (!Number.isFinite(value)) throw new CadError('measured.value', `${k}: a measurement is a number (got ${value})`);
|
|
99
142
|
const named = predictions.filter((x) => x.code === k || x.predict.name === k);
|
|
100
143
|
if (named.length) {
|
|
101
144
|
const p = named[0].predict;
|
|
102
145
|
entries.push({ date, assembly: name, name: k, code: named[0].code, figure: p.figure, unit: p.unit, predicted: p.value, measured: value, ratio: p.value ? value / p.value : null, ...(source ? { source } : {}) });
|
|
146
|
+
// a drop on the joint rig: what the beam bends of it is the beam's own; the rest is the join turning, so its spring
|
|
147
|
+
if (p.rig) {
|
|
148
|
+
const r = p.rig, n = (x) => String(Number(Number(x).toFixed(3)));
|
|
149
|
+
if (!(value > r.beam)) throw new CadError('measured.value', `${k}: ${n(value)} mm is no more than the ${n(r.beam)} mm the beam bends by itself under ${n(r.force)} N at ${n(r.arm)} mm, so the join would be stiffer than solid metal: read the drop again, from the dial's reading with the mass hung less its reading without`);
|
|
150
|
+
const spring = (r.force * r.arm * r.arm) / (value - r.beam), figure = Number((spring * r.per).toPrecision(4));
|
|
151
|
+
writeRule(r.rule, figure, { unit: r.unit, from: `${n(value)} mm drop of ${k.replace(/\.drop$/, '')} under ${n(r.force)} N at ${n(r.arm)} mm (${r.join}), less the beam's own ${n(r.beam)} mm, is a spring of ${(spring / 1e6).toFixed(3)} N·m/mrad` });
|
|
152
|
+
}
|
|
103
153
|
continue;
|
|
104
154
|
}
|
|
105
|
-
|
|
106
|
-
const old = data.rules?.[key], known = slotRule(project, set, key, data) ?? fixingsRule(project, set, key) ?? (old ? null : kitRule(set, key));
|
|
107
|
-
if (known?.allowed && !known.allowed.includes(value)) throw new CadError('measured.value', `${k} is ${known.allowed.join(' or ')}: the flank forms the coupon prints (got ${value})`);
|
|
108
|
-
if (!old && !rule && !known) throw new CadError('measured.rule', `${set} has no rule "${key}" (and no check here predicts "${k}"): --rule "what it is" to add it (checks: ${[...new Set(predictions.map((x) => x.code))].join(', ') || 'none'})`);
|
|
109
|
-
const had = old ?? known, prior = typeof had?.value === 'number' ? had.value : known?.predicted ?? null;
|
|
110
|
-
if (unit && had?.unit && unit !== had.unit) throw new CadError('measured.unit', `${k} is in ${had.unit}, and this is in ${unit}: give it in ${had.unit}`);
|
|
111
|
-
const entry = { value, unit: unit ?? had?.unit ?? '', rule: rule ?? had.rule, kind: 'measured', source: source || known?.source || 'measured on the bench', checked: date };
|
|
112
|
-
if (data.part === 'slot') slots.set(set, { data, change: { ...slots.get(set)?.change, [key]: value } });
|
|
113
|
-
writes.push([file, key, entry]);
|
|
114
|
-
entries.push({ date, assembly: name, name: k, figure: entry.rule, unit: entry.unit, predicted: prior, was: old ? old.kind : known?.was ?? known?.kind ?? null, measured: value, ratio: prior ? value / prior : null, ...(source ? { source } : {}) });
|
|
155
|
+
writeRule(k, value);
|
|
115
156
|
}
|
|
116
157
|
// a slot's figures together still make a slot (an opening narrower than its cavity, lips thinner than it is deep)
|
|
117
158
|
for (const [set, { data, change }] of slots) { try { slotModel(data, change); } catch (e) { throw new CadError('measured.value', `${set}: ${e.message.replace(/^slotModel: /, '')}`); } }
|
|
118
|
-
|
|
159
|
+
// every value checked: now each set is written, the workspace's copy made from where it started where there is none
|
|
160
|
+
const texts = new Map();
|
|
161
|
+
for (const w of writes) texts.set(w.file, { ...w, text: setAt(texts.get(w.file)?.text ?? w.text, ['rules', w.key], w.entry) });
|
|
162
|
+
for (const [file, w] of texts) {
|
|
163
|
+
fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, w.text);
|
|
164
|
+
if (w.copied) console.error(w.copied);
|
|
165
|
+
}
|
|
119
166
|
const after = await findingsOf(ref), was = new Map(before.map((x) => [keyOf(x), x])), moved = [];
|
|
120
167
|
for (const x of after) {
|
|
121
168
|
const y = was.get(keyOf(x));
|
package/lib/motors.mjs
CHANGED
|
@@ -223,9 +223,13 @@ export function motorChecks(s, f, helpers, materialName) {
|
|
|
223
223
|
// The case, against what it's bolted to
|
|
224
224
|
const mat = material(materialName), rise = fig('temperature_rise');
|
|
225
225
|
if (mat?.softening != null && rise != null) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
// (the rise is the maker's at rated current; the heat goes as the current squared, so a driver set lower runs cooler)
|
|
227
|
+
const I = fig('rated_current'), set = d.spec.current != null && I ? Math.min(1, (d.spec.current / I) ** 2) : 1;
|
|
228
|
+
const duty = d.spec.duty != null ? d.spec.duty : 1, room = 25, caseT = room + rise * duty * set, ok = caseT <= mat.softening, name = mat.name.toUpperCase();
|
|
229
|
+
const how = [set < 1 ? `at ${n3(d.spec.current, 2)} A` : null, duty < 1 ? `at ${n3(duty * 100, 0)}% duty` : null].filter(Boolean).join(' and ') || 'at rated current';
|
|
230
|
+
const est = `an estimate: ${m.name}'s ${n3(rise, 1)} °C rise at rated current${set < 1 ? ', scaled by the current squared (its copper loss)' : ''}${duty < 1 ? ', by the duty' : ''}, over a ${room} °C room`;
|
|
231
|
+
if (ok) f('pass', `${d.id}'s case reaches at most ${n3(caseT, 1)} °C ${how}, under ${name}'s ${mat.softening} °C (${est})`, null, { code: 'motor.heat', at: S, refs: { item: d.id }, values: { case: caseT, softening: mat.softening, rise, room, scale: set * duty } });
|
|
232
|
+
else { const k = Math.sqrt((mat.softening - room) / (rise * duty)); f('warn', `${d.id}'s case can reach ${n3(caseT, 1)} °C ${how} (${est}), past where ${name} softens (${mat.softening} °C). Set the driver to ${I ? `${n3(I * k, 2)} A` : `${n3(k * 100, 0)}% of its current`} (${n3(k * 100, 0)}% of the torque), or print the mount in a material that takes it`, `${d.id}: mount will soften`, { code: 'motor.heat', at: S, refs: { item: d.id }, values: { case: caseT, softening: mat.softening, rise, room, scale: set * duty } }); }
|
|
229
233
|
}
|
|
230
234
|
}
|
|
231
235
|
}
|
|
@@ -246,12 +250,24 @@ function mountPlate(s, d, W) {
|
|
|
246
250
|
return { fit, other, parts, inv, t, plate, hd };
|
|
247
251
|
}
|
|
248
252
|
|
|
253
|
+
// The screws a motor is held by on a plate this thick: mountModel's (from @rulecad/fixings), at a length sold, the
|
|
254
|
+
// longest that does not take them past mountModel's length into the motor's own thread, or through plain holes the
|
|
255
|
+
// shortest that reaches; or the length the motor item names ("screw": "M3x8 cap"). Where the wall at the holes (t) is
|
|
256
|
+
// thinner than the plate round them, the heads are sunk in counterbores (mount()'s, as deep as the head is high), and
|
|
257
|
+
// the screws are chosen for the plate under them
|
|
258
|
+
function screwsFor(d, plate, t = plate) {
|
|
259
|
+
const here = mountModel(d.model, { plate, ...(t < plate - 0.5 ? { counterbore: true } : {}), ...(d.spec.screw ? { screw: d.spec.screw } : {}) }), fx = here.screw.model, L = here.screwLength, sold = fx.figures.lengths?.value;
|
|
260
|
+
const length = fx.length ?? (!Array.isArray(sold) || !sold.length ? L : d.model.mount.thread ? [...sold].reverse().find((l) => l <= L) ?? sold[0] : sold.find((l) => l >= L) ?? sold.at(-1));
|
|
261
|
+
return { here, fx, length, wanted: L, name: `${fx.thread}x${length} ${fx.head.form}` };
|
|
262
|
+
}
|
|
263
|
+
|
|
249
264
|
/**
|
|
250
265
|
* The screws that hold each motor to the part it is fastened to by a fit with "fastens" (a motor named in a "fasten"
|
|
251
|
-
* has its screws counted there): as many as its mounting holes,
|
|
252
|
-
* taken to a length sold (the longest that does not pass it
|
|
266
|
+
* has its screws counted there): as many as its mounting holes, @rulecad/fixings' screw on the thread mountModel takes,
|
|
267
|
+
* at the length mountModel works out for the plate as drawn taken to a length sold (the longest that does not pass it
|
|
268
|
+
* into the motor's own thread; through plain holes, the shortest that reaches), or the length the motor item names.
|
|
253
269
|
* @param {object} s a built assembly @param {{ placeItems: Function, jointValues: Function }} helpers
|
|
254
|
-
* @returns {{ item: string, other: string, thread: string, length: number, wanted: number, count: number }[]}
|
|
270
|
+
* @returns {{ item: string, other: string, fit: object, thread: string, head: string, name: string, key: number | null, length: number, wanted: number, count: number }[]}
|
|
255
271
|
*/
|
|
256
272
|
export function motorScrews(s, { placeItems, jointValues }) {
|
|
257
273
|
const drives = s.motion?.drives || [], top = (n) => String(n).split(/[.@]/)[0];
|
|
@@ -261,11 +277,9 @@ export function motorScrews(s, { placeItems, jointValues }) {
|
|
|
261
277
|
for (const d of drives) {
|
|
262
278
|
if (named.has(d.id)) continue;
|
|
263
279
|
const p = mountPlate(s, d, worlds[d.item]); if (!p || p.t === Infinity) continue;
|
|
264
|
-
const
|
|
265
|
-
if (!
|
|
266
|
-
|
|
267
|
-
const length = !sold ? L : d.model.mount.thread ? [...sold].reverse().find((l) => l <= L) ?? sold[0] : sold.find((l) => l >= L) ?? sold.at(-1);
|
|
268
|
-
out.push({ item: d.id, other: p.other, thread, length, wanted: L, count: d.model.mount.holes.length });
|
|
280
|
+
const { fx, length, wanted, name } = screwsFor(d, +p.plate.toFixed(2), +p.t.toFixed(2));
|
|
281
|
+
if (!(wanted > 0)) continue;
|
|
282
|
+
out.push({ item: d.id, other: p.other, fit: p.fit, thread: fx.thread, head: fx.head.form, name, key: fx.head.key ?? null, length, wanted, count: d.model.mount.holes.length });
|
|
269
283
|
}
|
|
270
284
|
return out;
|
|
271
285
|
}
|
|
@@ -275,8 +289,9 @@ function mountCheck(s, d, f, W, avail, materialName, frame) {
|
|
|
275
289
|
if (!at) return;
|
|
276
290
|
const { other, parts, inv, t, plate, hd } = at;
|
|
277
291
|
if (t === Infinity) return f('warn', `${d.id}: couldn't find the plate at its screw holes in ${other}`, `${d.id}: mount not found`, { code: 'motor.mount' });
|
|
278
|
-
|
|
279
|
-
|
|
292
|
+
// the screws as bought (screwsFor), so the engagement mountModel checks is the bought screw's
|
|
293
|
+
const sunk = t < plate - 0.5, here = mountModel(m, { plate: +plate.toFixed(2), ...(sunk ? { counterbore: true } : {}), screw: screwsFor(d, +plate.toFixed(2), +t.toFixed(2)).name }), mat = material(materialName) || material('pla'), each = Math.max(...screwGroup(m.mount.holes, { moment: [0, 0, avail] }).screws.map((x) => x.shear)), bearing = each / (hd * t), margin = mat.strength / bearing;
|
|
294
|
+
for (const x of here.findings) f(x.level, `${d.id} on ${other}: ${x.text}`, x.level === 'pass' ? null : `${d.id}: ${x.code.split('.')[1]}`, { code: 'motor.mount', ...(x.values ? { values: x.values } : {}), ...(x.refs ? { refs: { item: d.id, ...x.refs } } : {}) });
|
|
280
295
|
f(margin < 2 ? 'fail' : 'pass', `${d.id} on ${other}: ${n3(plate, 2)} mm of plate at the screws, each taking ${n3(each, 1)} N against the torque (bearing ${n3(bearing, 1)} MPa, ${n3(margin, 0)} times under ${mat.name.toUpperCase()}'s ${mat.strength} MPa)`, margin < 2 ? `${d.id}: screws pull through` : null, { code: 'motor.mount', values: { plate, bearing, margin } });
|
|
281
296
|
mountBends(s, d, f, W, avail, mat, { other, parts, inv, plate, hd, ...frame });
|
|
282
297
|
}
|
package/lib/order.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import fs from 'node:fs';
|
|
|
11
11
|
import { placeItems, jointValues, mul } from '@rulecad/model-link';
|
|
12
12
|
import { host } from './host.mjs';
|
|
13
13
|
import { paths } from './workspace.mjs';
|
|
14
|
+
import { motorScrews } from './motors.mjs';
|
|
14
15
|
|
|
15
16
|
const top = (n) => String(n).split(/[.@]/)[0];
|
|
16
17
|
const round = (v) => v.map((x) => (Math.abs(x) < 1e-9 ? 0 : +x.toFixed(6)));
|
|
@@ -91,7 +92,8 @@ function hitsAlong(origin, dir, tris) {
|
|
|
91
92
|
/**
|
|
92
93
|
* The order to put an assembly together, as data.
|
|
93
94
|
* @param {object} s a built assembly
|
|
94
|
-
* @returns {{ steps: { n: number, items: string[], object: string|null, dir: number[], fasteners: {fit: string, fastener?: string, count?: number}[], text: string }[], stuck: object|null }}
|
|
95
|
+
* @returns {{ steps: { n: number, items: string[], object: string|null, dir: number[], fasteners: {fit: string, fastener?: string, count?: number}[], text: string }[], stuck: object|null, covers?: { fit: string, fasten?: number, screwed: string[], wall: string }[] }}
|
|
96
|
+
* covers: each part that stands over a screw, which has to go on after the parts the screw joins
|
|
95
97
|
*/
|
|
96
98
|
export function assemblyOrder(s) {
|
|
97
99
|
const all = groups(s).filter((g) => g.bought || g.motor || g.parts.some((p) => p.role === 'part' || p.role == null) || s.fits.some((x) => [x.a, x.b].flat().some((n) => top(n) === g.id)));
|
|
@@ -118,7 +120,7 @@ export function assemblyOrder(s) {
|
|
|
118
120
|
}
|
|
119
121
|
// Screws: what stands on the tool's line goes on after the screw, and if it must already be there, nothing can
|
|
120
122
|
const worlds = placeItems(s.motion, s.jointValues), marks = s.motion.marks, reaches = (u, v, seen = new Set()) => { if (u === v) return true; if (seen.has(u)) return false; seen.add(u); return [...before.get(u).keys()].some((w) => reaches(w, v, seen)); };
|
|
121
|
-
const R = 1.5, bad = [];
|
|
123
|
+
const R = 1.5, bad = [], covers = []; // (covers: what stands over a screw, kept so another order of the same parts, a frame's build, can be held to it)
|
|
122
124
|
for (const x of s.fits.filter((f) => f.access)) {
|
|
123
125
|
const [id, name] = String(x.access).split('.'), m = marks.find((k) => k.id === id && k.name === name) ?? (s.items.find((i) => i.id === id)?.beam ? s.motion.address(String(x.access), 'access') : null); // (a beam's address: x1.top@120)
|
|
124
126
|
if (!m) throw new Error(`fit ${x.note || `${x.a} / ${x.b}`}: access: no anchor "${x.access}" (give <item>.<anchor>${items.includes(id) ? `; ${id} has ${marks.filter((k) => k.id === id).map((k) => k.name).join(', ') || 'none'}` : ''})`);
|
|
@@ -127,7 +129,7 @@ export function assemblyOrder(s) {
|
|
|
127
129
|
for (const q of all) {
|
|
128
130
|
if (screwed.includes(q.id) || !starts.some((p) => hitsAlong(p, D, q.tris))) continue;
|
|
129
131
|
if (later && reaches(q.id, later)) bad.push({ fit: x, wall: q.id, at: O, later });
|
|
130
|
-
else if (later) add(later, q.id, `${q.id} covers the screw of ${x.note || later}`);
|
|
132
|
+
else if (later) { add(later, q.id, `${q.id} covers the screw of ${x.note || later}`); covers.push({ fit: x.note || `${x.a} to ${x.b}`, screwed, wall: q.id }); }
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
// A fasten's screws (lib/fasten.mjs): what stands over a head goes on after the parts the screw joins. A part that
|
|
@@ -138,7 +140,7 @@ export function assemblyOrder(s) {
|
|
|
138
140
|
const screwed = [...rel.through, rel.into].map(top).filter((t) => by.has(t)), later = [...screwed].sort(earlier).at(-1), walls = [...new Set(acc.blockers.map((b) => b.item))];
|
|
139
141
|
const first = walls.filter((q) => !by.has(q) || screwed.includes(q) || (later && reaches(q, later)));
|
|
140
142
|
if (first.length) { if (acc.tilt == null) bad.push({ fit: { note: rel.label }, wall: first[0], at: acc.top, later, fasten: rel.index, screw: sc.index, member: screwed.includes(first[0]), fixed: !by.has(first[0]) }); continue; }
|
|
141
|
-
for (const q of walls) add(later, q, `${q} covers the screws of ${rel.label}`);
|
|
143
|
+
for (const q of walls) { add(later, q, `${q} covers the screws of ${rel.label}`); covers.push({ fasten: rel.index, fit: rel.label, screwed, wall: q }); }
|
|
142
144
|
}
|
|
143
145
|
const box = (g) => { const p = g.tris.flat(); return [0, 1, 2].map((k) => { const v = p.map((x) => x[k]); return (Math.min(...v) + Math.max(...v)) / 2; }); };
|
|
144
146
|
if (bad.length) {
|
|
@@ -197,11 +199,13 @@ export function assemblyOrder(s) {
|
|
|
197
199
|
const seq = [], lay = (off) => { for (const x of [...off].reverse()) { if (x.group) { lay(x.sub.off); seq.push({ group: x.group, d: x.d }); } else seq.push(x); } };
|
|
198
200
|
lay(apart.off);
|
|
199
201
|
const at = new Map(), steps = [];
|
|
202
|
+
// a motor's mounting screws, on the fit that fastens it (motorScrews): counted, with the key that turns them
|
|
203
|
+
const motorFits = new Map(motorScrews(s, { placeItems, jointValues }).map((m) => [m.fit, { fastener: m.name, count: m.count, ...(m.key != null ? { key: `${+m.key.toFixed(3)} mm hex key` } : {}) }]));
|
|
200
204
|
seq.forEach((x, i) => { for (const g of x.group ?? [x.p]) at.set(g.id, i); });
|
|
201
205
|
for (const [i, x] of seq.entries()) {
|
|
202
206
|
if (x.group) { steps.push({ items: x.group.map((g) => g.id), object: null, dir: round(x.d), fasteners: [], together: true }); continue; }
|
|
203
207
|
const { p, d } = x, list = [...new Set(s.fits.filter((f) => [...names(f.a), ...names(f.b)].includes(p.id) && (f.fastens || f.seat != null || f.fastener) && [...names(f.a), ...names(f.b)].every((n) => (at.get(n) ?? 0) <= i)))];
|
|
204
|
-
steps.push({ items: [p.id], object: p.object, dir: round(d), fasteners: list.map((f) => ({ fit: f.note || f.label || `${f.a} to ${f.b}`, ...(f.fastener ? { fastener: f.fastener } : {}), ...(f.count != null ? { count: f.num(f.count) } : {}), ...(f.key ? { key: f.key } : {}), ...(f.tighten ? { tighten: f.tighten } : {}) })) });
|
|
208
|
+
steps.push({ items: [p.id], object: p.object, dir: round(d), fasteners: list.map((f) => ({ fit: f.note || f.label || `${f.a} to ${f.b}`, ...(f.fastener ? { fastener: f.fastener } : {}), ...(f.count != null ? { count: f.num(f.count) } : {}), ...(f.key ? { key: f.key } : {}), ...(f.tighten ? { tighten: f.tighten } : {}), ...(!f.fastener ? motorFits.get(f) : {}) })) });
|
|
205
209
|
}
|
|
206
210
|
// Copies of one thing fitted the same way, one after another, are one step
|
|
207
211
|
const merged = [];
|
|
@@ -211,7 +215,7 @@ export function assemblyOrder(s) {
|
|
|
211
215
|
else merged.push({ items: [...st.items], object: st.object, dir: st.dir, fasteners: st.fasteners, ...(st.together ? { together: true } : {}) });
|
|
212
216
|
}
|
|
213
217
|
merged.forEach((st, i) => { st.n = i + 1; st.text = `${st.items.join(', ')}${st.object && !st.items.includes(st.object) ? ` (${st.object})` : ''}${st.together ? ' go on as one' : i ? ` goes on${st.items.length > 1 ? ', one by one' : ''}` : ' first'}${st.fasteners.length ? `: ${st.fasteners.map(fastenerText).join('; ')}` : ''}`; });
|
|
214
|
-
return { steps: merged, stuck: null };
|
|
218
|
+
return { steps: merged, stuck: null, covers };
|
|
215
219
|
}
|
|
216
220
|
|
|
217
221
|
/** One fastening of a step as the order and the build page say it: the fit, its screws by count and name, the key and how tight. */
|
|
@@ -219,7 +223,7 @@ export const fastenerText = (f) => `${f.fit}${f.fastener ? ` (${f.count != null
|
|
|
219
223
|
|
|
220
224
|
// Cached by what the parts are and where they are, with everything else that changes the answer
|
|
221
225
|
function orderFile(s) {
|
|
222
|
-
const key = crypto.createHash('sha256').update(JSON.stringify([
|
|
226
|
+
const key = crypto.createHash('sha256').update(JSON.stringify([6, s.parts.map((p) => [p.item, p.hash ?? p.shape, Array.from(p.m ?? []).map((x) => +x.toFixed(4))]), s.fits.map(({ num, ...x }) => x), s.motion.joints.map((j) => [j.id, j.child, j.parent])])).digest('hex');
|
|
223
227
|
return paths.cache('order', `${key}.json`);
|
|
224
228
|
}
|
|
225
229
|
export function orderOf(s) {
|
|
@@ -234,12 +238,19 @@ export function orderOf(s) {
|
|
|
234
238
|
// Whether an assembly is something that goes together with fastenings: anything else has no steps to find
|
|
235
239
|
export const isBuilt = (s) => s.a.kind !== 'plate' && s.fits.some((x) => x.fastens || x.seat != null || x.shaft != null || x.access);
|
|
236
240
|
|
|
237
|
-
/**
|
|
238
|
-
|
|
241
|
+
/**
|
|
242
|
+
* assembly.order, in the assembly's findings shape. With a frame's build (frameBuild, for an assembly with joins) the
|
|
243
|
+
* steps counted are its, as cad order prints them: one count for the one sequence. @param {object} s @param {Function} f
|
|
244
|
+
* @param {{ frame?: (s: object) => object }} [o]
|
|
245
|
+
*/
|
|
246
|
+
export function orderChecks(s, f, { frame = null } = {}) {
|
|
239
247
|
if (!isBuilt(s) || (s.pose != null && s.pose !== s.motion.pose)) return;
|
|
240
248
|
const r = orderOf(s);
|
|
241
|
-
if (r.stuck) f('fail', r.stuck.text, `${r.stuck.item}: can't be reached`, { code: 'assembly.order', at: r.stuck.at, refs: { item: r.stuck.item, ...(r.stuck.wall ? { wall: r.stuck.wall } : {}), ...(r.stuck.screw ? { screw: r.stuck.screw } : {}), ...(r.stuck.holders ? { holders: r.stuck.holders } : {}) } });
|
|
242
|
-
|
|
249
|
+
if (r.stuck) return f('fail', r.stuck.text, `${r.stuck.item}: can't be reached`, { code: 'assembly.order', at: r.stuck.at, refs: { item: r.stuck.item, ...(r.stuck.wall ? { wall: r.stuck.wall } : {}), ...(r.stuck.screw ? { screw: r.stuck.screw } : {}), ...(r.stuck.holders ? { holders: r.stuck.holders } : {}) } });
|
|
250
|
+
const b = frame && s.joins?.length ? frame(s) : null;
|
|
251
|
+
if (b?.stuck) return f('fail', `no build from bars to a square frame: ${b.stuck.text}`, `${b.stuck.item}: no build`, { code: 'assembly.order', refs: { item: b.stuck.item, ...(b.stuck.place ? { place: b.stuck.place } : {}), ...(b.stuck.joins ? { joins: b.stuck.joins } : {}) } });
|
|
252
|
+
const n = b ? b.steps.length : r.steps.length, first = b ? b.steps.find((st) => st.now?.length)?.now[0] : r.steps[0]?.items[0];
|
|
253
|
+
f('pass', `goes together in ${n} step${n === 1 ? '' : 's'}${b ? ' from bars to a square frame (cad order)' : ''}, ${first} first, nothing trapped`, null, { code: 'assembly.order', values: { steps: n }, refs: { first } });
|
|
243
254
|
}
|
|
244
255
|
|
|
245
256
|
/** Each step's picture: what's there, and the new part held off along the way it goes on. @returns {object[][]} parts lists, for preview() */
|
|
@@ -253,4 +264,4 @@ export function stepPictures(s, r) {
|
|
|
253
264
|
});
|
|
254
265
|
}
|
|
255
266
|
|
|
256
|
-
export const orderText = (ref, r) => (r.stuck ? `${ref}: ${r.stuck.text}` : [`${ref}: how it goes together`, ...r.steps.
|
|
267
|
+
export const orderText = (ref, r) => (r.stuck ? `${ref}: ${r.stuck.text}` : [`${ref}: how it goes together`, ...r.steps.flatMap((st) => [...(st.load || []).map((t) => ` first, ${t}`), ` ${String(st.n).padStart(2)}. ${st.text}`])].join('\n'));
|