@rulecad/cad 0.7.61 → 0.7.64
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 +22 -5
- package/CHANGELOG.md +57 -0
- package/EXAMPLES.md +29 -49
- package/README.md +104 -2
- package/bin/cad.mjs +97 -15
- package/lib/assembly.mjs +4 -4
- package/lib/belts.mjs +62 -0
- package/lib/edit.mjs +493 -36
- package/lib/errors.mjs +1 -1
- package/lib/fasten.mjs +1 -1
- package/lib/fittings.mjs +11 -1
- package/lib/guides.mjs +100 -9
- package/lib/list.mjs +1 -1
- package/lib/motors.mjs +16 -8
- package/lib/schema.mjs +2 -2
- package/lib/wires.mjs +8 -0
- package/package.json +4 -4
- package/schemas/assembly.schema.json +2 -2
- package/schemas/project.schema.json +31 -0
package/lib/assembly.mjs
CHANGED
|
@@ -39,7 +39,7 @@ import { ops as booleans } from '@rulecad/shapes';
|
|
|
39
39
|
import { motorBuilt, motorDrives, shaftFits, loadsOf, motorChecks, shaftFit, axisOf } from './motors.mjs';
|
|
40
40
|
import { runningChecks, seatFit } from './seats.mjs';
|
|
41
41
|
import { seatSize } from '@rulecad/shapes';
|
|
42
|
-
import { wiresOf, wireChecks
|
|
42
|
+
import { wiresOf, wireChecks } from './wires.mjs';
|
|
43
43
|
import { printedParts } from './list.mjs';
|
|
44
44
|
import { taskOf, taskChecks } from './task.mjs';
|
|
45
45
|
import { powerChecks } from './power.mjs';
|
|
@@ -58,6 +58,7 @@ import { frameHeatChecks } from './frameheat.mjs';
|
|
|
58
58
|
import { expandPanels, panelBuilt, panelFindings, PANEL_CHECK } from './panels.mjs';
|
|
59
59
|
import { expandServices, serviceFindings } from './services.mjs';
|
|
60
60
|
import { expandGuides, guideBuilt, guideFindings } from './guides.mjs';
|
|
61
|
+
import { beltLoads } from './belts.mjs';
|
|
61
62
|
import { slotNutChecks } from './slotnuts.mjs';
|
|
62
63
|
import { frameSquareChecks, frameBuild } from './framebuild.mjs';
|
|
63
64
|
let pinning = null; // lib/pins.mjs, loaded with the first assembly whose fits name pins
|
|
@@ -740,9 +741,7 @@ export function anchorsAt(s, values = s.jointValues) {
|
|
|
740
741
|
|
|
741
742
|
// keyCentres(layout): each key's centre, from lib/layout.mjs (kept under this name for older callers)
|
|
742
743
|
export { keyCentres };
|
|
743
|
-
export
|
|
744
|
-
export const wireTubesOf = (s) => wireTubes(s, { placeItems, mul });
|
|
745
|
-
export const wireRoutesOf = (s) => wireRoutes(s, { placeItems, mul });
|
|
744
|
+
export { wiresFor, wireTubesOf, wireRoutesOf } from './wires.mjs'; // (there, so list.mjs needn't import this module back: #278)
|
|
746
745
|
|
|
747
746
|
// ---------- checks ----------
|
|
748
747
|
export { closest };
|
|
@@ -996,6 +995,7 @@ export function checkAssembly(s) {
|
|
|
996
995
|
fittingFindings(s, f);
|
|
997
996
|
panelFindings(s, f);
|
|
998
997
|
serviceFindings(s, f);
|
|
998
|
+
beltLoads(s, { placeItems, jointValues, mul }); // (a belt's carriage pushed at its acceleration: a load on its joint, before the motor's checks read the loads)
|
|
999
999
|
guideFindings(s, f);
|
|
1000
1000
|
if (s.generated) { const m = s.generated, [what, ...more] = frameText(m); f('info', `generated: ${what}; ${more.map((x) => x.trim()).join('; ')}`, null, { code: 'frame.generated', values: { inside: m.inside, outside: m.outside, lengths: m.lengths.map(({ length, count }) => ({ length, count })) }, refs: { kind: m.kind, profile: m.profile, join: m.join.kind, arrangement: m.arrangement, by: m.by } }); }
|
|
1001
1001
|
joinChecks(s, f);
|
package/lib/belts.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// A belt guide's load, worked out once the assembly is built: the carriage and everything it carries, pushed at the
|
|
2
|
+
// carriage's acceleration (the guide's accel, else the task's, else BELT_DEFAULTS.accel). That force goes on the drive's
|
|
3
|
+
// joint as a load, so the motor's checks hold the motor to it through the belt's ratio (motor.torque, motor.speed), and
|
|
4
|
+
// the belt's stretch under it is a term of the error budget (task.mjs reads the joint's slide). Where the travel is not
|
|
5
|
+
// level, the belt also carries the weight's part along it all the time: belt.tension and the stretch read the two
|
|
6
|
+
// together (the motor's checks already have the weight, from the loads). Units: kg, mm/s², N.
|
|
7
|
+
import { BELT_DEFAULTS, beltRub } from '@rulecad/frames';
|
|
8
|
+
import { massesOf, beyond } from './loads.mjs';
|
|
9
|
+
import { axisOf } from './motors.mjs';
|
|
10
|
+
|
|
11
|
+
const G = 9.80665;
|
|
12
|
+
const invAt = (W, p) => { const q = [p[0] - W[3], p[1] - W[7], p[2] - W[11]]; return [W[0] * q[0] + W[4] * q[1] + W[8] * q[2], W[1] * q[0] + W[5] * q[1] + W[9] * q[2], W[2] * q[0] + W[6] * q[1] + W[10] * q[2]]; };
|
|
13
|
+
|
|
14
|
+
// An item's box in the belt's own frame (the face's: x along the beam from end a, y across, z over the face), from its
|
|
15
|
+
// drawn triangles, which are in the world at the motion's pose
|
|
16
|
+
function boxIn(W, parts) {
|
|
17
|
+
const lo = [Infinity, Infinity, Infinity], hi = [-Infinity, -Infinity, -Infinity];
|
|
18
|
+
for (const p of parts) for (const t of p.triangles) for (const v of t) { const q = invAt(W, v); for (let k = 0; k < 3; k++) { lo[k] = Math.min(lo[k], q[k]); hi[k] = Math.max(hi[k], q[k]); } }
|
|
19
|
+
return Number.isFinite(lo[0]) ? { lo, hi } : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Each belt guide's carried mass and the force that pushes it, added to the motion's loads and to the drive's stretch.
|
|
24
|
+
* @param {object} s a built assembly @param {{ placeItems: Function, jointValues: Function, mul: Function }} helpers
|
|
25
|
+
*/
|
|
26
|
+
export function beltLoads(s, helpers) {
|
|
27
|
+
const motion = s.motion, belts = (s.guides ?? []).filter((x) => x.kind === 'belt');
|
|
28
|
+
if (!motion || !belts.length) return;
|
|
29
|
+
const ids = motion.items.map((x) => x[0]), masses = massesOf(s, helpers), worlds = helpers.placeItems(motion, helpers.jointValues(motion, motion.pose ?? undefined));
|
|
30
|
+
const g = motion.gravity || [0, 0, -1], gn = Math.hypot(...g);
|
|
31
|
+
for (const r of belts) {
|
|
32
|
+
const j = motion.joints.find((x) => x.id === r.joints[0]);
|
|
33
|
+
if (!j) continue;
|
|
34
|
+
let kg = 0;
|
|
35
|
+
for (const q of masses) if (beyond(motion, j, q.item)) kg += q.kg;
|
|
36
|
+
const own = kg; // (the parts' own: the carriage, the clamp, what is drawn on them; the loads' masses the motor checks have)
|
|
37
|
+
for (const l of motion.loads ?? []) if (l.mass != null && !l.belt) { const k = typeof l.item === 'number' ? l.item : ids.indexOf(l.item); if (beyond(motion, j, k)) kg += l.mass; }
|
|
38
|
+
const tool = s.task?.item != null ? ids.indexOf(s.task.item) : -1;
|
|
39
|
+
if (s.task?.payload && tool >= 0 && beyond(motion, j, tool)) kg += s.task.payload;
|
|
40
|
+
const accel = r.accel ?? s.task?.accel ?? BELT_DEFAULTS.accel.value, force = (kg * accel) / 1000;
|
|
41
|
+
// the weight's part along the travel: kg × g × the cosine between the slide and gravity (0 on a level axis)
|
|
42
|
+
const { Z } = axisOf(motion, worlds, j, helpers.mul), cos = (Z[0] * g[0] + Z[1] * g[1] + Z[2] * g[2]) / (Math.hypot(...Z) * gn), along = Math.abs(cos) > 1e-9 ? cos : 0, weight = kg * G * Math.abs(along);
|
|
43
|
+
Object.assign(r, { carried: kg, accelUsed: accel, accelFrom: r.accel != null ? 'the guide' : s.task?.accel != null ? 'the task' : 'BELT_DEFAULTS.accel', force, weight });
|
|
44
|
+
// the push, either way along the travel (motors.mjs adds it in the worse direction); off level, the parts' own weight
|
|
45
|
+
// along it too, signed as gravity's (the declared loads' weight the motor checks read from their masses)
|
|
46
|
+
motion.loads = [...(motion.loads ?? []).filter((l) => l.belt !== r.id && l.beltWeight !== r.id), { joint: j.id, value: force, note: `${r.id}: ${(kg * 1000).toFixed(0)} g pushed at ${accel} mm/s²`, belt: r.id },
|
|
47
|
+
...(along && own ? [{ joint: j.id, value: own * G * along, note: `${r.id}: the carriage's own ${(own * 1000).toFixed(0)} g along the travel`, beltWeight: r.id }] : [])];
|
|
48
|
+
if (j.slide?.stretch) Object.assign(j.slide.stretch, { load: force + weight, length: r.layout.span });
|
|
49
|
+
// what else the carriage carries, by its box: held against the belt's runs through the travel (belt.rub), as the
|
|
50
|
+
// beam, the rail, the carriage and the clamp are
|
|
51
|
+
const kb = ids.indexOf(r.items.belt), kc = ids.indexOf(r.carriage), mine = new Set([r.carriage, r.items.clamp, r.items.belt]), partsOf = (id) => s.parts.filter((p) => p.item === id && p.role !== 'support' && p.triangles?.length);
|
|
52
|
+
const cbox = kb >= 0 && kc >= 0 ? boxIn(worlds[kb], partsOf(r.carriage)) : null;
|
|
53
|
+
if (!cbox) continue;
|
|
54
|
+
const xc = (cbox.lo[0] + cbox.hi[0]) / 2, carried = [];
|
|
55
|
+
ids.forEach((id, k) => {
|
|
56
|
+
if (mine.has(id) || !beyond(motion, j, k)) return;
|
|
57
|
+
const b = boxIn(worlds[kb], partsOf(id));
|
|
58
|
+
if (b) carried.push({ part: id, lo: [b.lo[0] - xc, b.lo[1], b.lo[2]], hi: [b.hi[0] - xc, b.hi[1], b.hi[2]] });
|
|
59
|
+
});
|
|
60
|
+
if (carried.length) Object.assign(r, { rub: beltRub(r.layout, { carried }), carriedParts: carried.map((x) => x.part) });
|
|
61
|
+
}
|
|
62
|
+
}
|