@rulecad/cad 0.9.0 → 0.11.0
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 +29 -10
- package/CHANGELOG.md +604 -0
- package/EXAMPLES.md +122 -105
- package/README.md +292 -63
- package/bin/cad.mjs +500 -87
- package/lib/assembly.mjs +486 -134
- package/lib/bays.mjs +124 -0
- package/lib/cache-file.mjs +148 -0
- package/lib/clone.mjs +93 -11
- package/lib/code-text.mjs +28 -0
- package/lib/design-imports.mjs +127 -0
- package/lib/design.mjs +291 -59
- package/lib/designshapes.mjs +142 -0
- package/lib/edit.mjs +29 -5
- package/lib/estimates.mjs +51 -0
- package/lib/fasten.mjs +11 -5
- package/lib/fe-key.mjs +29 -0
- package/lib/fittings.mjs +20 -15
- package/lib/fixings.mjs +17 -4
- package/lib/framebuild.mjs +73 -92
- package/lib/framecheck.mjs +154 -77
- package/lib/framegen.mjs +9 -1
- package/lib/frames.mjs +6 -2
- package/lib/framesize.mjs +45 -82
- package/lib/gait.mjs +17 -7
- package/lib/guides.mjs +84 -50
- package/lib/host.mjs +7 -3
- package/lib/kit.mjs +5 -5
- package/lib/list.mjs +29 -21
- package/lib/live-guard.mjs +18 -8
- package/lib/loads.mjs +35 -23
- package/lib/measured.mjs +740 -99
- package/lib/mesh.mjs +156 -56
- package/lib/motors.mjs +26 -33
- package/lib/names.mjs +15 -0
- package/lib/node-version.mjs +52 -0
- package/lib/optimise.mjs +34 -25
- package/lib/order.mjs +5 -12
- package/lib/parts.mjs +3 -0
- package/lib/picture-servers.mjs +66 -0
- package/lib/power.mjs +14 -7
- package/lib/preview.mjs +12 -25
- package/lib/programs.mjs +113 -0
- package/lib/rules.mjs +2 -1
- package/lib/sandbox-guard.mjs +43 -0
- package/lib/sandbox-hooks.mjs +109 -15
- package/lib/sandbox-lock.mjs +225 -0
- package/lib/sandbox-preload.mjs +2 -2
- package/lib/sandbox-run.mjs +22 -24
- package/lib/sandbox.mjs +345 -42
- package/lib/sheet.mjs +114 -3
- package/lib/targets/gist.mjs +9 -6
- package/lib/versions.mjs +294 -35
- package/lib/workspace.mjs +6 -3
- package/package.json +14 -14
- package/schemas/assembly.schema.json +6 -5
- package/schemas/object.schema.json +1 -1
- package/schemas/project.schema.json +6 -0
- package/templates/coupons/MEASURE.md +109 -0
- package/templates/coupons/assemblies/fixings-test.json +20 -0
- package/templates/coupons/assemblies/slot-test.json +11 -0
- package/templates/coupons/objects/fixings-coupon.js +88 -0
- package/templates/coupons/objects/fixings-coupon.json +26 -0
- package/templates/coupons/objects/holds-coupon.js +130 -0
- package/templates/coupons/objects/holds-coupon.json +42 -0
- package/templates/coupons/objects/slot-coupon.js +89 -0
- package/templates/coupons/objects/slot-coupon.json +29 -0
- package/templates/coupons/project.json +10 -0
package/lib/framesize.mjs
CHANGED
|
@@ -20,13 +20,22 @@ import {
|
|
|
20
20
|
joinStiffness,
|
|
21
21
|
boughtStiffness,
|
|
22
22
|
JOINS,
|
|
23
|
-
|
|
23
|
+
blindKeyBlocked,
|
|
24
24
|
footModel,
|
|
25
25
|
levellingFootModel,
|
|
26
26
|
stackingFootModel,
|
|
27
27
|
} from '@rulecad/frames';
|
|
28
28
|
import { fixingModel } from '@rulecad/fixings';
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
frameModelOf,
|
|
31
|
+
FRAME_CHECK,
|
|
32
|
+
excitesOf,
|
|
33
|
+
rackOf,
|
|
34
|
+
sideways,
|
|
35
|
+
freeSaid,
|
|
36
|
+
endSprings,
|
|
37
|
+
heldAlong,
|
|
38
|
+
} from './framecheck.mjs';
|
|
30
39
|
import { framesContext } from './beams.mjs';
|
|
31
40
|
import { givenFor } from './frames.mjs';
|
|
32
41
|
import { fittingModel, fittedStiffness, plasticOf } from './fittings.mjs';
|
|
@@ -205,92 +214,19 @@ export function joinFit(x, pa, pb, given, beamOf = beamAt) {
|
|
|
205
214
|
const a = () => 'an'; // (a metric thread's name is said em: an M5, an M3)
|
|
206
215
|
const beamAt = (profile, length) => beamModel(profile, { length });
|
|
207
216
|
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
function metalAlong(loops, p, d) {
|
|
211
|
-
const ts = [];
|
|
212
|
-
for (const loop of loops)
|
|
213
|
-
for (let i = 0; i < loop.length; i++) {
|
|
214
|
-
const q0 = loop[i],
|
|
215
|
-
q1 = loop[(i + 1) % loop.length];
|
|
216
|
-
const s0 = d[0] * (q0[1] - p[1]) - d[1] * (q0[0] - p[0]),
|
|
217
|
-
s1 = d[0] * (q1[1] - p[1]) - d[1] * (q1[0] - p[0]);
|
|
218
|
-
if (s0 > 0 === s1 > 0) continue;
|
|
219
|
-
const k = s0 / (s0 - s1);
|
|
220
|
-
ts.push((q0[0] + k * (q1[0] - q0[0]) - p[0]) * d[0] + (q0[1] + k * (q1[1] - q0[1]) - p[1]) * d[1]);
|
|
221
|
-
}
|
|
222
|
-
ts.sort((x, y) => x - y);
|
|
223
|
-
const out = [];
|
|
224
|
-
for (let i = 0; i + 1 < ts.length; i += 2) out.push([ts[i], ts[i + 1]]);
|
|
225
|
-
return out;
|
|
226
|
-
}
|
|
227
|
-
const KEY_STRIPS = 16; // (lines across the key's width the section is looked along: its corners and between)
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Whether a blind join's hex key reaches its head straight, as fasten.access looks for it: the key comes in through
|
|
231
|
-
* the access hole drilled across b from its far face (the hole @rulecad/frames drills for the join, to its own depth)
|
|
232
|
-
* and on through b's section to the head under the near slot's lips. The section is the same all along the beam, so
|
|
233
|
-
* any metal across the key's width (its corners', from the hexkey set) between the head's top and the hole's end, or
|
|
234
|
-
* in the hole wider than the hole, stands in its way: a slot floor that slants down to a narrow groove (OpenBeam's)
|
|
235
|
-
* keeps the key off the head. Null where it reaches, else why not.
|
|
236
|
-
* @param {object} B b's beam model @param {object} place the place on b the head sits under @param {object} sl its slot
|
|
237
|
-
* @param {string} thread the screw's thread @param {object} fx its button-head screw's model @param {string} bName b's profile, as said
|
|
238
|
-
* @returns {string | null}
|
|
239
|
-
*/
|
|
217
|
+
// Whether a blind join's hex key reaches its head straight (@rulecad/frames' blindKeyBlocked), the key's width across
|
|
218
|
+
// its corners from the workspace's hexkey set where it has one
|
|
240
219
|
function keyBlocked(B, place, sl, thread, fx, bName) {
|
|
241
|
-
|
|
242
|
-
if (!(key > 0)) return null;
|
|
243
|
-
// the place across from it on the same line, as @rulecad/frames' blind join drills its access hole (on a face with
|
|
244
|
-
// two slots, a 2040's, the one in line with the head's)
|
|
245
|
-
const far = B.places.find(
|
|
246
|
-
(q) =>
|
|
247
|
-
Math.abs(q.normal[0] + place.normal[0]) < 1e-9 &&
|
|
248
|
-
Math.abs(q.normal[1] + place.normal[1]) < 1e-9 &&
|
|
249
|
-
Math.abs(place.normal[0] * (q.at[1] - place.at[1]) - place.normal[1] * (q.at[0] - place.at[0])) < 1e-6,
|
|
250
|
-
);
|
|
251
|
-
if (!far) return null; // (the join itself refuses a face with none across it)
|
|
252
|
-
let op;
|
|
253
|
-
try {
|
|
254
|
-
op = beamModel(B.profile, {
|
|
255
|
-
length: B.length,
|
|
256
|
-
ops: [{ op: 'access', at: `${far.name}@${B.length / 2}`, thread, head: 'button', through: 'beam' }],
|
|
257
|
-
}).ops.find((o) => o.op === 'access');
|
|
258
|
-
} catch {
|
|
259
|
-
return null; // (an access hole that cannot be drilled is the join's own refusal, said when it is built)
|
|
260
|
-
}
|
|
261
|
-
let radius = key / Math.cos(Math.PI / 6) / 2;
|
|
220
|
+
let corners = null;
|
|
262
221
|
try {
|
|
263
222
|
const set = peekRuleSet('hexkey').rules,
|
|
264
|
-
i = set.sizes.value.findIndex((s) => Math.abs(s - key) < 1e-6);
|
|
265
|
-
if (i >= 0)
|
|
223
|
+
i = set.sizes.value.findIndex((s) => Math.abs(s - fx.head.key) < 1e-6);
|
|
224
|
+
if (i >= 0) corners = set.corners.value[i];
|
|
266
225
|
} catch {
|
|
267
|
-
// (no hexkey set: the
|
|
268
|
-
}
|
|
269
|
-
const loops = outline(B.profile).loops,
|
|
270
|
-
d = [-place.normal[0], -place.normal[1]],
|
|
271
|
-
side = [place.normal[1], -place.normal[0]];
|
|
272
|
-
// depths from b's near face, inward: the head's top, and where the access hole from the far face ends
|
|
273
|
-
const T = Math.max(...loops.flat().map((q) => (q[0] - place.at[0]) * d[0] + (q[1] - place.at[1]) * d[1])),
|
|
274
|
-
top = sl.lip + fx.head.height,
|
|
275
|
-
holeEnd = T - op.depth,
|
|
276
|
-
hole = op.diameter / 2;
|
|
277
|
-
for (let k = 0; k <= KEY_STRIPS; k++) {
|
|
278
|
-
const s = radius * ((2 * k) / KEY_STRIPS - 1),
|
|
279
|
-
p = [place.at[0] + side[0] * s, place.at[1] + side[1] * s];
|
|
280
|
-
for (const [t0, t1] of metalAlong(loops, p, d)) {
|
|
281
|
-
const undrilled = t1 > top + 1e-3 && t0 < holeEnd - 1e-3,
|
|
282
|
-
outsideHole = Math.abs(s) > hole + 1e-9 && t1 > Math.max(top, holeEnd) + 1e-3 && t0 < T - 1e-3;
|
|
283
|
-
if (undrilled || outsideHole)
|
|
284
|
-
return `a ${mm1(key)} mm hex key cannot reach ${a(thread)} ${thread} button head in ${bName}'s slot: ${
|
|
285
|
-
undrilled
|
|
286
|
-
? `${bName}'s section stands in its way ${mm1(Math.max(t0, top) - top)} mm over the head, past the end of the Ø${mm1(op.diameter)} mm access hole`
|
|
287
|
-
: `the key is ${mm1(2 * radius)} mm across its corners and the access hole Ø${mm1(op.diameter)} mm`
|
|
288
|
-
}`;
|
|
289
|
-
}
|
|
226
|
+
// (no hexkey set: the kit's)
|
|
290
227
|
}
|
|
291
|
-
return
|
|
228
|
+
return blindKeyBlocked(B, place, sl, thread, fx, bName, corners);
|
|
292
229
|
}
|
|
293
|
-
const mm1 = (x) => String(+Number(x).toFixed(2));
|
|
294
230
|
|
|
295
231
|
// a place's face as a fitting names it: the face, or the place where the face has several (a 2040's top.1)
|
|
296
232
|
const faceName = (B, q) => (B.places.filter((p) => p.face === q.face).length > 1 ? q.name : q.face);
|
|
@@ -466,6 +402,33 @@ export function frameSizing(s, helpers, given) {
|
|
|
466
402
|
from: lim.from,
|
|
467
403
|
});
|
|
468
404
|
}
|
|
405
|
+
// every beam's own sag along its length (its bending, from where it is held), held to its span over frame.sag (or
|
|
406
|
+
// frame.limit) as frame.deflection holds it, so cad check does not fail a sized design whose long rail sags past it,
|
|
407
|
+
// loaded or not; limits.deflection, where given, in its place as at the loads
|
|
408
|
+
if (fm.beams.size) {
|
|
409
|
+
const asked = opt.limits.deflection != null,
|
|
410
|
+
frameLimit = asked ? opt.limits.deflection : s.a.frame?.limit != null ? s.num(s.a.frame.limit) : null;
|
|
411
|
+
for (const b of fm.beams.values()) {
|
|
412
|
+
const held = heldAlong(fm, b);
|
|
413
|
+
deflection.push({
|
|
414
|
+
member: b.id,
|
|
415
|
+
limit: frameLimit ?? b.L / FRAME_CHECK.sag.value,
|
|
416
|
+
along: fm.down,
|
|
417
|
+
...(held.length ? { held } : {}),
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
const shortest = [...fm.beams.values()].reduce((p, q) => (q.L < p.L ? q : p));
|
|
421
|
+
limitRows.push({
|
|
422
|
+
limit: 'deflection',
|
|
423
|
+
where: 'each beam',
|
|
424
|
+
what:
|
|
425
|
+
frameLimit != null
|
|
426
|
+
? 'each beam along its length'
|
|
427
|
+
: `each beam along its length (${shortest.id}'s the least, its span over ${FRAME_CHECK.sag.value})`,
|
|
428
|
+
value: frameLimit ?? shortest.L / FRAME_CHECK.sag.value,
|
|
429
|
+
from: asked ? 'frame.size.limits.deflection' : frameLimit != null ? 'frame.limit' : 'frame.sag',
|
|
430
|
+
});
|
|
431
|
+
}
|
|
469
432
|
const stress = opt.limits.stress ?? margin,
|
|
470
433
|
factor = opt.limits.buckling ?? margin;
|
|
471
434
|
limitRows.push({
|
package/lib/gait.mjs
CHANGED
|
@@ -62,7 +62,7 @@ export const frameValues = (s, frame, jointValues) => {
|
|
|
62
62
|
};
|
|
63
63
|
export const framesOf = (s) => (s.gaitRun ??= gait(s.gait));
|
|
64
64
|
|
|
65
|
-
export function gaitChecks(s, f, { jointValues, sweepOne }) {
|
|
65
|
+
export function gaitChecks(s, f, { jointValues, sweepOne, seamAdvice }) {
|
|
66
66
|
if (!s.gait) return;
|
|
67
67
|
const r = framesOf(s);
|
|
68
68
|
for (const x of r.findings)
|
|
@@ -111,24 +111,34 @@ export function gaitChecks(s, f, { jointValues, sweepOne }) {
|
|
|
111
111
|
}
|
|
112
112
|
// Leg against leg, leg against body: the cycle as a sweep
|
|
113
113
|
const every = Math.max(1, Math.floor(r.frames.length / 12));
|
|
114
|
+
// (a clash whose fourth entry, its seam, is set is JSCAD's small measure, in doubt, as the overlap check's is of
|
|
115
|
+
// the same pair standing still: the first pose with a sure clash fails; with none, the first with a doubtful one warns)
|
|
114
116
|
let clashes = null,
|
|
117
|
+
sure = false,
|
|
115
118
|
first = null;
|
|
116
119
|
for (const [k, frame] of r.frames.entries()) {
|
|
117
120
|
if (k % every) continue;
|
|
118
|
-
const c = sweepOne(frameValues(s, frame, jointValues))
|
|
119
|
-
|
|
121
|
+
const c = sweepOne(frameValues(s, frame, jointValues)),
|
|
122
|
+
real = c.filter((x) => !x[3]);
|
|
123
|
+
if (real.length && !sure) {
|
|
124
|
+
clashes = real;
|
|
125
|
+
sure = true;
|
|
126
|
+
first = frame.t;
|
|
127
|
+
} else if (c.length && !clashes) {
|
|
120
128
|
clashes = c;
|
|
121
129
|
first = frame.t;
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
132
|
if (clashes)
|
|
125
133
|
f(
|
|
126
|
-
'fail',
|
|
134
|
+
sure ? 'fail' : 'warn',
|
|
127
135
|
`gait: at ${n3(first * 100, 0)}% of the cycle ${clashes
|
|
128
136
|
.slice(0, 3)
|
|
129
|
-
.map(([a, b]) => `${a} hits ${b}`)
|
|
130
|
-
.join(
|
|
131
|
-
|
|
137
|
+
.map(([a, b]) => `${a} ${sure ? 'hits' : 'may hit'} ${b}`)
|
|
138
|
+
.join(
|
|
139
|
+
', ',
|
|
140
|
+
)}${sure ? '' : `: a small amount, measured by JSCAD, which can read the seams its unions and cuts leave as that much overlap. ${seamAdvice()}`}`,
|
|
141
|
+
sure ? 'gait: clash' : 'gait: may clash',
|
|
132
142
|
{ code: 'gait.sweep', refs: { at: first } },
|
|
133
143
|
);
|
|
134
144
|
else
|
package/lib/guides.mjs
CHANGED
|
@@ -66,7 +66,6 @@ const { cylinder, cuboid, polygon } = jscad.primitives,
|
|
|
66
66
|
{ subtract, union } = jscad.booleans,
|
|
67
67
|
{ extrudeRotate } = jscad.extrusions;
|
|
68
68
|
const shown = (v) => (v === undefined ? 'nothing' : JSON.stringify(v));
|
|
69
|
-
const up2 = (x, step) => Math.ceil(x / step - 1e-9) * step;
|
|
70
69
|
const mm = (x) => String(+Number(x).toFixed(2)),
|
|
71
70
|
r3 = (x) => +x.toFixed(3),
|
|
72
71
|
n3 = (x, d = 2) => String(Number(Number(x).toFixed(d)));
|
|
@@ -426,14 +425,14 @@ export function expandGuides(a, num, context = framesContext(), material = 'pla'
|
|
|
426
425
|
// the rods pressed into the holders, run through the bearings; the bearings pressed into the carriage
|
|
427
426
|
for (const r of rods)
|
|
428
427
|
fits.push(
|
|
429
|
-
{ a: r, b: ha, fastens: true,
|
|
430
|
-
{ a: r, b: hb, fastens: true,
|
|
431
|
-
{ a: r, b: cid,
|
|
428
|
+
{ a: r, b: ha, fastens: true, overlap: 'allowed', note: 'The rod pressed through its holder' },
|
|
429
|
+
{ a: r, b: hb, fastens: true, overlap: 'allowed', note: 'The rod pressed through its holder' },
|
|
430
|
+
{ a: r, b: cid, overlap: 'allowed', note: "The rod runs through the carriage's bearing" },
|
|
432
431
|
);
|
|
433
432
|
lms.forEach((x, k) =>
|
|
434
433
|
fits.push(
|
|
435
|
-
{ a: x, b: cid, fastens: true,
|
|
436
|
-
{ a: rods[k], b: x,
|
|
434
|
+
{ a: x, b: cid, fastens: true, overlap: 'allowed', note: 'The bearing pressed into its pocket' },
|
|
435
|
+
{ a: rods[k], b: x, overlap: 'allowed', note: 'Rod in bearing' },
|
|
437
436
|
),
|
|
438
437
|
);
|
|
439
438
|
const record = {
|
|
@@ -548,16 +547,22 @@ export function expandGuides(a, num, context = framesContext(), material = 'pla'
|
|
|
548
547
|
: [];
|
|
549
548
|
fits.push(
|
|
550
549
|
{ a: mo, b: plate, fastens: true, min: -0.1, note: "The motor's face on its plate" },
|
|
551
|
-
{ a: mo, b: cp,
|
|
552
|
-
{ a: sw, b: cp,
|
|
553
|
-
{ a: sw, b: nt,
|
|
554
|
-
{ a: sw, b: cid,
|
|
555
|
-
{ a: nt, b: cid, fastens: true,
|
|
556
|
-
{ a: sw, b: ha,
|
|
557
|
-
{ a: sw, b: hb,
|
|
550
|
+
{ a: mo, b: cp, overlap: 'allowed', note: "The motor's shaft in the coupler" },
|
|
551
|
+
{ a: sw, b: cp, overlap: 'allowed', note: 'The screw in the coupler' },
|
|
552
|
+
{ a: sw, b: nt, overlap: 'allowed', note: 'The screw through its nut' },
|
|
553
|
+
{ a: sw, b: cid, overlap: 'allowed', note: 'The screw through the carriage' },
|
|
554
|
+
{ a: nt, b: cid, fastens: true, overlap: 'allowed', note: 'The nut in its bore, its flange screwed on' },
|
|
555
|
+
{ a: sw, b: ha, overlap: 'allowed', note: 'The screw through holder a' },
|
|
556
|
+
{ a: sw, b: hb, overlap: 'allowed', note: 'The screw into holder b' },
|
|
558
557
|
...sup.flatMap((x, k) => [
|
|
559
|
-
{
|
|
560
|
-
|
|
558
|
+
{
|
|
559
|
+
a: x,
|
|
560
|
+
b: k ? hb : ha,
|
|
561
|
+
fastens: true,
|
|
562
|
+
overlap: 'allowed',
|
|
563
|
+
note: "The screw's bearing pressed into its holder",
|
|
564
|
+
},
|
|
565
|
+
{ a: sw, b: x, overlap: 'allowed', note: 'The screw in its bearing' },
|
|
561
566
|
]),
|
|
562
567
|
);
|
|
563
568
|
legFastens(plate, pm, `${sc.id}: the motor plate's leg`, sc.id);
|
|
@@ -588,7 +593,7 @@ export function expandGuides(a, num, context = framesContext(), material = 'pla'
|
|
|
588
593
|
added.push({ id: es.sw, bought: es.set, at: `${es.mount}.switch`, guideOf: id });
|
|
589
594
|
fits.push(
|
|
590
595
|
{ a: es.sw, b: es.mount, fastens: true, min: -0.1, note: 'The switch screwed to its mount' },
|
|
591
|
-
{ a: es.sw, b: cid,
|
|
596
|
+
{ a: es.sw, b: cid, overlap: 'allowed', note: 'The flag on the lever, at home' },
|
|
592
597
|
);
|
|
593
598
|
es.model.screws.forEach((x, k) =>
|
|
594
599
|
fasten.push({
|
|
@@ -752,7 +757,7 @@ export function expandGuides(a, num, context = framesContext(), material = 'pla'
|
|
|
752
757
|
a: nid,
|
|
753
758
|
b: bid,
|
|
754
759
|
fastens: true,
|
|
755
|
-
|
|
760
|
+
overlap: 'allowed',
|
|
756
761
|
note: `${nid} in ${bid}'s ${q.name} slot, held there by the rail's screws`,
|
|
757
762
|
});
|
|
758
763
|
}
|
|
@@ -991,7 +996,7 @@ export function expandGuides(a, num, context = framesContext(), material = 'pla'
|
|
|
991
996
|
});
|
|
992
997
|
fits.push(
|
|
993
998
|
{ a: mo, b: plate, fastens: true, min: -0.1, note: "The motor's face under its plate" },
|
|
994
|
-
{ a: mo, b: pu,
|
|
999
|
+
{ a: mo, b: pu, overlap: 'allowed', note: "The motor's shaft in the pulley" },
|
|
995
1000
|
{ a: il, b: blk, fastens: true, min: -0.1, note: "The idler on its axle, on the block's ring" },
|
|
996
1001
|
);
|
|
997
1002
|
const spec = joints.find((x) => x.id === jid);
|
|
@@ -1255,10 +1260,56 @@ export function guideBuilt(it, id) {
|
|
|
1255
1260
|
});
|
|
1256
1261
|
}
|
|
1257
1262
|
|
|
1263
|
+
/**
|
|
1264
|
+
* What each rail guide adds to an error budget (guide.budget), said once the frame is solved (after frameChecks), so
|
|
1265
|
+
* that the beam's sag under the guide is the frame's own figure, the one frame.deflection gives (s.frameGuideSag), and
|
|
1266
|
+
* the rail's estimate only where the frame is not solved. @param {object} s a built assembly @param {Function} f the
|
|
1267
|
+
* findings' sink
|
|
1268
|
+
*/
|
|
1269
|
+
export function guideBudgetFindings(s, f) {
|
|
1270
|
+
for (const r of s.guides ?? []) {
|
|
1271
|
+
if (['rods', 'belt', 'screw', 'wheels', 'slider'].includes(r.kind) || !r.terms?.length) continue;
|
|
1272
|
+
const solved = s.frameGuideSag?.get(r.id),
|
|
1273
|
+
t = r.terms.map((x) =>
|
|
1274
|
+
x.term === 'beam sag' && solved
|
|
1275
|
+
? {
|
|
1276
|
+
term: 'beam sag',
|
|
1277
|
+
value: solved.sag,
|
|
1278
|
+
kind: solved.restsOn === 'beams' ? 'derived' : solved.restsOn,
|
|
1279
|
+
note: `${solved.beam} under ${r.id}, solved with the frame${solved.pose ? `, ${solved.pose}` : ''}: ${n3(solved.rigid, 3)} mm with its joins rigid`,
|
|
1280
|
+
}
|
|
1281
|
+
: x,
|
|
1282
|
+
),
|
|
1283
|
+
sag = t.find((x) => x.term === 'beam sag');
|
|
1284
|
+
const worst = t.reduce((a, x) => a + x.value, 0);
|
|
1285
|
+
const said = !sag
|
|
1286
|
+
? ''
|
|
1287
|
+
: solved
|
|
1288
|
+
? ` The beam's sag is the frame's own, as frame.deflection gives it, with the joins' springs (${solved.restsOn === 'estimate' ? 'their stiffness an estimate' : solved.restsOn === 'measured' ? 'their stiffness measured' : 'no joins'})`
|
|
1289
|
+
: ` The beam's sag is an estimate (${GUIDE_DEFAULTS.sag.rule.split(':')[0].toLowerCase()}): the frame is not solved, so frame.deflection gives none`;
|
|
1290
|
+
f(
|
|
1291
|
+
'info',
|
|
1292
|
+
`${r.id}: along its travel it adds ${t.map((x) => `${x.term} ${n3(x.value, 3)} mm (${x.kind})`).join(', ')} to the error budget: ${n3(worst, 3)} mm at worst.${said}`,
|
|
1293
|
+
null,
|
|
1294
|
+
{
|
|
1295
|
+
code: 'guide.budget',
|
|
1296
|
+
values: { terms: t, worst },
|
|
1297
|
+
refs: {
|
|
1298
|
+
guide: r.id,
|
|
1299
|
+
beam: r.beam,
|
|
1300
|
+
rail: r.model.set,
|
|
1301
|
+
carriages: r.carriages,
|
|
1302
|
+
...(sag ? { sag: solved ? 'frame' : 'estimate' } : {}),
|
|
1303
|
+
},
|
|
1304
|
+
},
|
|
1305
|
+
);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1258
1309
|
/**
|
|
1259
1310
|
* A built assembly's guide findings: guide.holes, guide.end and guide.travel from the rail's model, guide.fit (on the
|
|
1260
|
-
* face, its nuts, its ends)
|
|
1261
|
-
*
|
|
1311
|
+
* face, its nuts, its ends) and guide.jig (the printed jig that centres it, and how to print one); guide.budget comes
|
|
1312
|
+
* after the frame's solve (guideBudgetFindings). @param {object} s a built assembly @param {Function} f the findings' sink
|
|
1262
1313
|
*/
|
|
1263
1314
|
export function guideFindings(s, f) {
|
|
1264
1315
|
for (const r of s.guides ?? []) {
|
|
@@ -1354,17 +1405,6 @@ export function guideFindings(s, f) {
|
|
|
1354
1405
|
values: x.values ?? {},
|
|
1355
1406
|
refs: { ...refs, ...(x.refs ?? {}) },
|
|
1356
1407
|
});
|
|
1357
|
-
const t = r.terms ?? [];
|
|
1358
|
-
if (t.length)
|
|
1359
|
-
f(
|
|
1360
|
-
'info',
|
|
1361
|
-
`${r.id}: along its travel it adds ${t.map((x) => `${x.term} ${n3(x.value, 3)} mm (${x.kind})`).join(', ')} to the error budget: ${n3(
|
|
1362
|
-
t.reduce((a, x) => a + x.value, 0),
|
|
1363
|
-
3,
|
|
1364
|
-
)} mm at worst. The beam's sag is an estimate (${GUIDE_DEFAULTS.sag.rule.split(':')[0].toLowerCase()})`,
|
|
1365
|
-
null,
|
|
1366
|
-
{ code: 'guide.budget', values: { terms: t, worst: t.reduce((a, x) => a + x.value, 0) }, refs },
|
|
1367
|
-
);
|
|
1368
1408
|
if (r.jig?.error) f('info', `${r.id}: no printed jig: ${r.jig.error}`, null, { code: 'guide.jig', refs });
|
|
1369
1409
|
else if (r.jig)
|
|
1370
1410
|
f(
|
|
@@ -1540,7 +1580,9 @@ function beltFindings(r, f) {
|
|
|
1540
1580
|
);
|
|
1541
1581
|
// (the belt carries the push and, off level, the weight's part along the travel: the two together at their worst.
|
|
1542
1582
|
// The motor holds the pulley, so the spans share it by their lengths, the short one taking the most: beltSpans walks
|
|
1543
|
-
// the travel for where the spans differ most, which is at one of its ends
|
|
1583
|
+
// the travel for where the spans differ most, which is at one of its ends. The layout's own belt.tension holds the
|
|
1584
|
+
// tension with no push; this one, with the push on it, takes that case in and fails past the rated tension, so it
|
|
1585
|
+
// stands in its place)
|
|
1544
1586
|
const push = r.force ?? 0,
|
|
1545
1587
|
W = r.weight ?? 0,
|
|
1546
1588
|
F = push + W,
|
|
@@ -1600,24 +1642,16 @@ function beltFindings(r, f) {
|
|
|
1600
1642
|
refs: { ...refs, ...(carried.length ? { carried } : {}) },
|
|
1601
1643
|
},
|
|
1602
1644
|
);
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
`${r.id}:
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
way = d >= 0 ? "toward the beam's end b" : 'toward the rail',
|
|
1614
|
-
fits = Math.abs(d) <= room + 1e-9;
|
|
1615
|
-
f(
|
|
1616
|
-
fits ? 'pass' : 'fail',
|
|
1617
|
-
`${r.id}: cut ${mm(L.cut)} mm, the belt sets its tension with the idler's block ${mm(Math.abs(d))} mm ${way} from where it is drawn, along the slot, which leaves it ${mm(room)} mm that way${fits ? `: ${mm(room - Math.abs(d))} mm of the tensioner's travel left` : `: the tensioner's travel is used up; cut the belt ${mm(up2(2 * (Math.abs(d) - room), B.pitch))} mm ${d >= 0 ? 'shorter' : 'longer'}, or move the block`}`,
|
|
1618
|
-
fits ? null : `${r.id}: tensioner used up`,
|
|
1619
|
-
{ code: 'belt.tensioner', values: { offset: d, room: L.idler.room, left: r3(room - Math.abs(d)) }, refs },
|
|
1620
|
-
);
|
|
1645
|
+
// (the layout's own checks, as @rulecad/frames gives them: the working run's line and the tensioner's room)
|
|
1646
|
+
for (const code of ['belt.line', 'belt.tensioner']) {
|
|
1647
|
+
const x = L.findings.find((q) => q.code === code),
|
|
1648
|
+
title = { 'belt.line': 'belt off square', 'belt.tensioner': 'tensioner used up' }[code];
|
|
1649
|
+
f(x.level, `${r.id}: ${x.text}`, x.level === 'fail' ? `${r.id}: ${title}` : null, {
|
|
1650
|
+
code,
|
|
1651
|
+
values: x.values,
|
|
1652
|
+
refs,
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1621
1655
|
f(
|
|
1622
1656
|
'info',
|
|
1623
1657
|
`${r.id}: the belt holds the carriage on two spans, the pulley's side a and the idler's side b; at its least stiff they act as ${mm(L.span)} mm of belt (a·b/(a+b), the most of it through the travel); at ${n3(B.k, 0)} N a unit of strain (${B.set}'s stiffness, ${B.kKind ?? 'its kind not given'}), ${n3(F, 2)} N${W ? ` (the push and the weight along the travel)` : ''} stretches it ${n3((F * L.span) / B.k, 4)} mm: the belt stretch term of the error budget where a task is given`,
|
package/lib/host.mjs
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
// packages, the published rule sets) from disk.
|
|
5
5
|
// host.exists(file) host.readText(file) host.writeText(file, text) host.list(dir) host.mtime(file) host.size(file)
|
|
6
6
|
// host.remove(file) host.touch(file) host.loadModule(file): a design's module (its main), for a design run in the
|
|
7
|
-
// tool's own process (a trusted one)
|
|
7
|
+
// tool's own process (a trusted one), loaded afresh when it or a file it imports has changed (design-imports.mjs)
|
|
8
|
+
// host.importsOf(file): a promise of the files of its own (not a package's) the design has imported since its last
|
|
9
|
+
// loadModule, as absolute paths, asked after its main has run, for the build's cache to follow
|
|
8
10
|
// host.runDesign(request): run a design in the sandbox, another process that can't write files, start programs or
|
|
9
11
|
// reach the network (sandbox.mjs's runSandboxed, whose request this is). build() uses it for every design it doesn't
|
|
10
12
|
// run in its own process, a board's too, so a host for a browser or an editor's server never runs a design's code in
|
|
@@ -35,7 +37,8 @@ export const nodeHost = {
|
|
|
35
37
|
const now = new Date();
|
|
36
38
|
fs.utimesSync(f, now, now);
|
|
37
39
|
},
|
|
38
|
-
loadModule: (f) => import(
|
|
40
|
+
loadModule: async (f) => (await import('./design-imports.mjs')).loadDesign(path.resolve(f)), // (its import hook is set up only when a design is first run here)
|
|
41
|
+
importsOf: async (f) => (await import('./design-imports.mjs')).importsOf(path.resolve(f)),
|
|
39
42
|
runDesign: (request) => import('./sandbox.mjs').then((s) => s.runSandboxed(request)), // (loaded when first used: sandbox.mjs reads the workspace, which reads through this host)
|
|
40
43
|
};
|
|
41
44
|
|
|
@@ -74,7 +77,7 @@ export const readOwnText = (f) => host.readText(guard(f));
|
|
|
74
77
|
* Whether a cache file is there to be read: a file of the workspace's .cache/ only where it really is inside the
|
|
75
78
|
* workspace. A cloned workspace may hold a .cache/ of its own, and a kept build or stage there that is a link to a file
|
|
76
79
|
* elsewhere would be read as the tool's own and shown, or handed to a design: such a file is a miss, made afresh (and
|
|
77
|
-
* not written through the link:
|
|
80
|
+
* not written through the link: cache-file.mjs writeCacheFile).
|
|
78
81
|
* @param {string} f
|
|
79
82
|
*/
|
|
80
83
|
export function cached(f) {
|
|
@@ -162,6 +165,7 @@ export function memoryHost(files = {}, { root = path.resolve('/rulecad-memory')
|
|
|
162
165
|
);
|
|
163
166
|
return import(`data:text/javascript;base64,${Buffer.from(src).toString('base64')}`);
|
|
164
167
|
},
|
|
168
|
+
importsOf: async () => [], // (a module loaded from its text can't import a file of its project)
|
|
165
169
|
runDesign: async (request) => {
|
|
166
170
|
const { d } = request,
|
|
167
171
|
project = path.resolve(path.dirname(path.dirname(d.js)));
|
package/lib/kit.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import path from 'node:path';
|
|
|
12
12
|
import { paths, WS } from './workspace.mjs';
|
|
13
13
|
import { CadError } from './errors.mjs';
|
|
14
14
|
import { buildAssembly } from './assembly.mjs';
|
|
15
|
-
import { shoppingList } from './list.mjs';
|
|
15
|
+
import { shoppingList, flowText } from './list.mjs';
|
|
16
16
|
import { platesOf, checkPlate } from './plates.mjs';
|
|
17
17
|
import { cutListOf, writeBeamSheets } from './beams.mjs';
|
|
18
18
|
import { writeJigs } from './jigs.mjs';
|
|
@@ -224,7 +224,7 @@ export async function writeKit(s, findings, { pictures = false, preview = null }
|
|
|
224
224
|
rows.push([
|
|
225
225
|
'bar',
|
|
226
226
|
b.count,
|
|
227
|
-
`${st.profile} x ${mm(b.length)} mm`,
|
|
227
|
+
`${st.label ?? st.profile} x ${mm(b.length)} mm`,
|
|
228
228
|
`${b.count} x ${mm(b.length)} mm`,
|
|
229
229
|
`the cut list's marks ${[...new Set(st.bars.flatMap((x) => x.cuts.map((c) => c.mark)))].join(', ')}`,
|
|
230
230
|
]);
|
|
@@ -320,7 +320,7 @@ export async function writeKit(s, findings, { pictures = false, preview = null }
|
|
|
320
320
|
...table(
|
|
321
321
|
['Profile', 'Buy', 'Left over, mm'],
|
|
322
322
|
list.cut.stock.map((st) => [
|
|
323
|
-
st.profile,
|
|
323
|
+
st.label ?? st.profile,
|
|
324
324
|
st.buy.map((b) => `${b.count} x ${mm(b.length)} mm`).join(', '),
|
|
325
325
|
mm(st.offcut ?? 0),
|
|
326
326
|
]),
|
|
@@ -404,7 +404,7 @@ export async function writeKit(s, findings, { pictures = false, preview = null }
|
|
|
404
404
|
'',
|
|
405
405
|
);
|
|
406
406
|
out.push(
|
|
407
|
-
`About ${mm(list.totals.printedGrams)} g of ${list.totals.material.toUpperCase()} and ${list.totals.minutes} min of printing (an estimate from each part's volume and
|
|
407
|
+
`About ${mm(list.totals.printedGrams)} g of ${list.totals.material.toUpperCase()} and ${list.totals.minutes} min of printing (an estimate from each part's volume and ${flowText(list.totals)}).`,
|
|
408
408
|
'',
|
|
409
409
|
);
|
|
410
410
|
}
|
|
@@ -448,7 +448,7 @@ export async function writeKit(s, findings, { pictures = false, preview = null }
|
|
|
448
448
|
'',
|
|
449
449
|
);
|
|
450
450
|
for (const st of list.cut.stock) {
|
|
451
|
-
out.push(`${st.profile}, the cuts on each bar in order:`, '');
|
|
451
|
+
out.push(`${st.label ?? st.profile}, the cuts on each bar in order:`, '');
|
|
452
452
|
st.bars.forEach((b, i) =>
|
|
453
453
|
out.push(
|
|
454
454
|
`${i + 1}. A ${mm(b.length)} mm bar: ${b.cuts.map((c) => `${c.mark} ${mm(c.length)} (${c.item})`).join(', ')}; ${mm(b.offcut)} mm left`,
|
package/lib/list.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { placeItems, jointValues } from '@rulecad/model-link';
|
|
|
7
7
|
import { screwModel, pinModel, magnetModel } from '@rulecad/fixings';
|
|
8
8
|
import { peekRuleSet as loadRuleSet } from './rules.mjs';
|
|
9
9
|
import { motorScrews } from './motors.mjs';
|
|
10
|
-
import { paths } from './workspace.mjs';
|
|
10
|
+
import { paths, printerOf } from './workspace.mjs';
|
|
11
11
|
import { readJson } from './host.mjs';
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { volume } from './mesh.mjs';
|
|
@@ -35,15 +35,25 @@ export function materialOf(project) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
// How fast the project's printer lays plastic, for the minutes: its rule set's print_flow (mm³/s), the printer named by
|
|
39
|
+
// project.json or cad.config.json (workspace.mjs printerOf), as cad check reads it. Where that rule set gives none (or
|
|
40
|
+
// cannot be read), 12 mm³/s, a usual print flow, marked assumed so the list says so.
|
|
41
|
+
export function flowOf(project) {
|
|
42
|
+
let printer = null;
|
|
42
43
|
try {
|
|
43
|
-
|
|
44
|
+
printer = printerOf(project);
|
|
45
|
+
const f = loadRuleSet(printer).rules.print_flow?.value;
|
|
46
|
+
if (typeof f === 'number' && f > 0) return { printer, flow: f };
|
|
44
47
|
} catch {
|
|
45
|
-
// (no
|
|
48
|
+
// (no printer named, or its rule set unreadable: the usual flow, said to be assumed)
|
|
46
49
|
}
|
|
50
|
+
return { printer, flow: 12, assumed: true };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Every printed thing in the assembly, once for each copy: its volume, grams and minutes
|
|
54
|
+
export function printedParts(s) {
|
|
55
|
+
const mat = materialOf(s.project);
|
|
56
|
+
const { flow } = flowOf(s.project);
|
|
47
57
|
const by = new Map();
|
|
48
58
|
for (const p of s.parts) {
|
|
49
59
|
if (p.role !== 'part' && p.role != null) continue;
|
|
@@ -72,12 +82,7 @@ function inPlaceRow(s, printed) {
|
|
|
72
82
|
members = printed.filter((p) => ids.includes(p.id));
|
|
73
83
|
if (members.length < 2) return printed;
|
|
74
84
|
const mat = materialOf(s.project);
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
flow = loadRuleSet('x1c').rules.print_flow?.value ?? flow;
|
|
78
|
-
} catch {
|
|
79
|
-
// (no x1c rule set: 12 mm³/s, a usual print flow)
|
|
80
|
-
}
|
|
85
|
+
const { flow } = flowOf(s.project);
|
|
81
86
|
const volume = members.reduce((t, p) => t + p.volume, 0),
|
|
82
87
|
row = {
|
|
83
88
|
id: members.map((p) => p.id).join(', '),
|
|
@@ -140,12 +145,8 @@ export function shoppingList(s) {
|
|
|
140
145
|
if (!b.from.includes(h.from)) b.from.push(h.from);
|
|
141
146
|
bolts.set(h.name, b);
|
|
142
147
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
flow = loadRuleSet('x1c').rules.print_flow?.value ?? flow;
|
|
146
|
-
} catch {
|
|
147
|
-
// (no x1c rule set: 12 mm³/s, a usual print flow)
|
|
148
|
-
}
|
|
148
|
+
const printer = flowOf(s.project),
|
|
149
|
+
{ flow } = printer;
|
|
149
150
|
for (const b of bolts.values()) {
|
|
150
151
|
const mm3 = (b.grams / mat.density) * 1000;
|
|
151
152
|
printed.push({
|
|
@@ -311,12 +312,19 @@ export function shoppingList(s) {
|
|
|
311
312
|
0,
|
|
312
313
|
),
|
|
313
314
|
material: mat.name,
|
|
314
|
-
...(mat.assumed ? { densityAssumed: true } : {}),
|
|
315
|
+
...(mat.assumed ? { densityAssumed: true, density: mat.density } : {}),
|
|
316
|
+
printer: printer.printer,
|
|
317
|
+
flow,
|
|
318
|
+
...(printer.assumed ? { flowAssumed: true } : {}),
|
|
315
319
|
...(unknown.length ? { noMassFor: unknown } : {}),
|
|
316
320
|
},
|
|
317
321
|
};
|
|
318
322
|
}
|
|
319
323
|
|
|
324
|
+
/** Whose flow a list's minutes are from, and what was assumed (a printer without a print_flow, a material without a density). @param {object} t a list's totals @returns {string} */
|
|
325
|
+
export const flowText = (t) =>
|
|
326
|
+
`${t.flowAssumed ? `the usual flow (${t.printer ? `${t.printer} gives no print_flow` : 'no printer named'}: ${t.flow} mm³/s assumed)` : `${t.printer ?? 'the printer'}'s flow, ${t.flow} mm³/s`}${t.densityAssumed ? `; no density known for ${t.material}: ${t.density} g/cm³ assumed for the grams` : ''}`;
|
|
327
|
+
|
|
320
328
|
export function listText(ref, l) {
|
|
321
329
|
const out = [`${ref}: what it takes to build`];
|
|
322
330
|
const row = (a) => out.push(a.join(' '));
|
|
@@ -378,7 +386,7 @@ export function listText(ref, l) {
|
|
|
378
386
|
}
|
|
379
387
|
out.push(
|
|
380
388
|
'',
|
|
381
|
-
`Total: ${l.totals.printedGrams} g printed, about ${l.totals.minutes} min of printing (an estimate from volume and
|
|
389
|
+
`Total: ${l.totals.printedGrams} g printed, about ${l.totals.minutes} min of printing (an estimate from volume and ${flowText(l.totals)}), ${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(', ')})` : ''}`,
|
|
382
390
|
);
|
|
383
391
|
if (l.cost) {
|
|
384
392
|
const c = l.cost,
|