@rulecad/cad 0.7.75 → 0.7.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/bin/cad.mjs +17 -2
- package/lib/machine.mjs +89 -14
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ print (a hole's diameter, a seat's depth, a part's outline). Each release lists
|
|
|
5
5
|
its reason. A **fasten** is an entry in an assembly's `"fasten"` list: one screwed joint, naming the screw by thread
|
|
6
6
|
and head, the parts it passes through and the part it ends in.
|
|
7
7
|
|
|
8
|
+
## 0.7.77: a leg's gait for the streamer (#199)
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `cad machine <project>/<assembly>` on an assembly with a `gait` and no `task`: a legged machine, an axis for each
|
|
12
|
+
motor's shaft the gait turns, ordered by the CNC shield slot (X, Y, Z) its motor is wired to, each with its `slot`.
|
|
13
|
+
- `cad plot <project>/<assembly>` with no drawing, on an assembly with a gait: the gait as a step file for the streamer,
|
|
14
|
+
`exports/<project>/<assembly>-gait.steps.json`, from the pose shown (`--pose` for another) through `--cycles` (3) and
|
|
15
|
+
back, at the gait's period or `--period`, and a picture of each axis through the run in `.preview/`. A motor wired to
|
|
16
|
+
a slot out of the streamer's order fails (`stream.wiring`); more than three axes is a warning (`stream.axes`). The
|
|
17
|
+
bench stand's gait plays at 2.89 s a cycle against its 2 s period: its knee would need 11712 steps/s, past the 5333
|
|
18
|
+
of a 17HS4401 at 200 rpm and 1/8 steps.
|
|
19
|
+
|
|
8
20
|
## 0.7.75: parts milled, cast or printed in a powder bed
|
|
9
21
|
### Added
|
|
10
22
|
|
package/README.md
CHANGED
|
@@ -1705,7 +1705,7 @@ module and read `pip`'s variables) and name them in the assembly's `"printInPlac
|
|
|
1705
1705
|
together, so the assembly order never takes them apart from each other. `cad order` fits them as one step and
|
|
1706
1706
|
`cad list` gives them one printed row, the one print's grams and minutes.
|
|
1707
1707
|
|
|
1708
|
-
An assembly with a `gait` (EXAMPLES chapter 14) plays too: `cad animate <project>/<assembly>` writes the cycle as an animated SVG in `.preview/` (a side view of the legs and a plan of the feet and what they stand on) and its data as JSON. The model page plays the same cycle in its Motion panel.
|
|
1708
|
+
An assembly with a `gait` (EXAMPLES chapter 14) plays too: `cad animate <project>/<assembly>` writes the cycle as an animated SVG in `.preview/` (a side view of the legs and a plan of the feet and what they stand on) and its data as JSON. The model page plays the same cycle in its Motion panel. `cad machine <project>/<assembly>` on such an assembly describes it as a legged machine, an axis for each motor's shaft in the order the shield's slots are wired, and `cad plot <project>/<assembly>` with no drawing writes the gait as a step file for the streamer: `--cycles` of it (3) from a pose (`--pose`, by default the one shown) and back, every axis in each block, slowed where a motor cannot keep to the gait's period (`--period` to set it) and where a joint turns back, with a picture of each axis through the run in `.preview/`. A motor wired to a shield slot out of the streamer's order (X, Y, Z) fails by name.
|
|
1709
1709
|
|
|
1710
1710
|
An assembly with a motor, or with gears that follow a joint, plays its drive: `cad animate <project>/<assembly>` writes `<assembly>-drive.svg`, the gears cut across their shafts through their teeth (up to three cuts side by side, a compound planetary's two rings each in its own), each part turning and moving as it does, the part with the load picked out. It turns the drive until the slowest part has moved about 60° (one to six turns; `--turns n` to choose). Each part's outline is drawn once and moved, so a gearbox stays a few hundred kilobytes.
|
|
1711
1711
|
|
package/bin/cad.mjs
CHANGED
|
@@ -111,6 +111,8 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
111
111
|
cad machine <project>/<assembly> the machine as plain data: axes, steps, limits, homing, the task, in exports/
|
|
112
112
|
cad plot <project>/<assembly> <drawing.svg> plans a drawing on the machine: a step file in exports/, an animation in
|
|
113
113
|
.preview/, and any stroke refused [--calibrate: the calibration drawing] [--tol 0.1] [--json]
|
|
114
|
+
cad plot <project>/<assembly> on an assembly with a gait: its cycle as a step file in exports/ for the streamer, from a pose and
|
|
115
|
+
back to it, and a picture of each axis through the run in .preview/ [--cycles 3] [--period s] [--pose <start>] [--json]
|
|
114
116
|
cad order <project>/<assembly> the order it goes together in, each step with its fasteners; a frame from bars to square: cut, drill, sides built flat, nuts to load, joins with their torque, diagonals [--preview: an exploded picture of each step in .preview/]
|
|
115
117
|
cad plates <project>/<assembly> every printed part on beds, by material and filament, spaced by the first-layer rule: written as plate assemblies and checked; a changed part re-packs only its plate; a frame's jigs on plates of their own [--gap mm] [--no-jigs] [--json]
|
|
116
118
|
cad kit <project>/<assembly> the folder to build it from without the model, in exports/: README.md (checks, what to buy and print, cut list, drilling, the build step by step), buy.csv, the plates' 3MFs, the jigs, each beam's sheet [--pictures] [--json]
|
|
@@ -164,7 +166,7 @@ const COMMANDS = ['new', 'remove', 'move', 'import-kle', 'clone', 'agents', 'tru
|
|
|
164
166
|
const OPTIONS = ['table', 'calibrate', 'check', 'turns', 'preview', 'gap', 'no-steps', 'all', 'along', 'at', 'bump', 'depth', 'dry-run', 'explode', 'force', 'fresh', 'json', 'licence', 'license', 'long', 'm', 'material', 'md', 'name', 'new',
|
|
165
167
|
'no-models', 'no-pictures', 'no-rules', 'note', 'open', 'part', 'place', 'pose', 'profile', 'progress', 'push', 'result', 'rules', 'samples', 'set', 'short', 'source', 'steps',
|
|
166
168
|
'sweep', 'tol', 'trailer', 'ttl', 'version', 'watch', 'line',
|
|
167
|
-
'unit', 'rule', 'label', 'from', 'out', 'jigs', 'no-jigs', 'expand', 'size', 'write', 'pictures', // cad set, cad rules, cad beams, cad frame, cad plates, cad kit
|
|
169
|
+
'unit', 'rule', 'label', 'from', 'out', 'jigs', 'no-jigs', 'expand', 'size', 'write', 'pictures', 'cycles', 'period', // cad set, cad rules, cad beams, cad frame, cad plates, cad kit, cad plot
|
|
168
170
|
'a', 'b', 'min', 'max', 'poses', 'id', 'type', 'parent', 'child', 'follow', 'value', 'ratio', 'object', 'assembly', 'variant', 'rotate', 'to', 'roll', // cad add
|
|
169
171
|
'screw', 'through', 'into', 'holes', 'nut', 'washer', 'length', 'torque', 'from-fits', // cad add fasten
|
|
170
172
|
'kind', 'fitting', // cad add join
|
|
@@ -1115,7 +1117,8 @@ async function machineCommand(what, ref) {
|
|
|
1115
1117
|
const m = await import('../lib/machine.mjs'), s = await buildAssembly(ref);
|
|
1116
1118
|
if (what === 'machine') { const out = m.machineOf(s), file = m.writeMachine(s, out); (await import('../lib/buildpage.mjs')).writeWiring(s); return console.log(opt('json') ? JSON.stringify(out, null, 2) : file); }
|
|
1117
1119
|
const source = positional()[2], tol = opt('tol') != null ? Number(opt('tol')) : undefined;
|
|
1118
|
-
if (!source && !opt('calibrate')
|
|
1120
|
+
if (!source && !opt('calibrate') && s.gait && !s.task?.sheet) return gaitPlot(m, s, ref);
|
|
1121
|
+
if (!source && !opt('calibrate')) throw new Error('usage: cad plot <project>/<assembly> <drawing.svg> [--calibrate], or cad plot <project>/<assembly> on an assembly with a gait');
|
|
1119
1122
|
const { sheetFrame } = await import('@rulecad/robots'), f = s.task?.sheet ? sheetFrame(s.task.sheet) : null;
|
|
1120
1123
|
const svg = opt('calibrate') ? m.CALIBRATION(f?.width ?? 148, f?.height ?? 210) : fs.readFileSync(source, 'utf8'), base = `${s.name}-${opt('calibrate') ? 'calibration' : path.basename(source, path.extname(source))}`;
|
|
1121
1124
|
const r = m.plot(s, svg, { tolerance: tol, name: base });
|
|
@@ -1126,6 +1129,18 @@ async function machineCommand(what, ref) {
|
|
|
1126
1129
|
process.exitCode = failed ? 1 : 0;
|
|
1127
1130
|
}
|
|
1128
1131
|
|
|
1132
|
+
// A gait as a step file: --cycles (3), --period (s a cycle; default the gait's), --pose (where it starts and ends; default the one shown)
|
|
1133
|
+
async function gaitPlot(m, s, ref) {
|
|
1134
|
+
const cycles = opt('cycles') != null ? Number(opt('cycles')) : 3, period = opt('period') != null ? Number(opt('period')) : undefined;
|
|
1135
|
+
if (!Number.isInteger(cycles) || cycles < 1) throw new Error(`--cycles is a whole number, 1 or more (got ${opt('cycles')})`);
|
|
1136
|
+
if (period != null && !(period > 0)) throw new Error(`--period is the seconds of one cycle, above 0 (got ${opt('period')})`);
|
|
1137
|
+
const r = m.plotGait(s, { cycles, period, from: opt('pose') });
|
|
1138
|
+
if (opt('json')) { console.log(JSON.stringify({ ok: r.ok, findings: r.findings, time: r.time, ...(r.ok ? { file: m.writeGait(s, r).file } : {}) }, null, 2)); process.exitCode = r.ok ? 0 : 1; return; }
|
|
1139
|
+
report(r.findings, { assembly: ref, title: `${ref}: its gait` });
|
|
1140
|
+
if (r.ok) { const w = m.writeGait(s, r); console.log(path.relative(WS, w.file)); console.log(path.relative(WS, w.preview)); }
|
|
1141
|
+
process.exitCode = r.ok ? 0 : 1;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1129
1144
|
async function platesCommand(what, ref) {
|
|
1130
1145
|
if (!isAssembly(ref)) throw new Error(`cad ${what} works on an assembly (<project>/<assembly>), and there is no "${ref}"`);
|
|
1131
1146
|
const s = await buildAssembly(ref);
|
package/lib/machine.mjs
CHANGED
|
@@ -2,31 +2,106 @@
|
|
|
2
2
|
// the task. cad plot plans a drawing on it, checks it against the task, and shows the result before anything moves.
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { svgToStrokes, orderStrokes, planToolpath, stepBlocks, estimate, sheetFrame, fk } from '@rulecad/robots';
|
|
5
|
+
import { svgToStrokes, orderStrokes, planToolpath, stepBlocks, estimate, sheetFrame, fk, gaitBlocks } from '@rulecad/robots';
|
|
6
|
+
import { gaitSequence } from './gait.mjs';
|
|
6
7
|
import { trainFrom, workingSpeed } from './motors.mjs';
|
|
7
8
|
import { chainOf, accuracyOf, sample, jacobianError } from './task.mjs';
|
|
8
9
|
import { paths } from './workspace.mjs';
|
|
9
10
|
|
|
10
|
-
const r6 = (x) => +Number(x).toFixed(6), n3 = (x, d = 2) => String(Number(x.toFixed(d)));
|
|
11
|
+
const num = Number.isFinite, r6 = (x) => +Number(x).toFixed(6), n3 = (x, d = 2) => String(Number(x.toFixed(d)));
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
// One driven joint as an axis: its motor, the steps it takes a degree (or mm) through its train, and the fastest it steps
|
|
14
|
+
function axisOf(s, id) {
|
|
15
|
+
const motion = s.motion, t = trainFrom(motion, id), d = motion.drives.find((x) => x.joint === t.root), j = motion.joints.find((x) => x.id === id), spec = new Map((s.a.joints || []).map((x) => [x.id, x])).get(id) ?? {};
|
|
16
|
+
if (!d?.model.stepAngle) throw new Error(`${s.project}/${s.name}: joint ${id} has no stepper driving it, and a step file needs one`);
|
|
17
|
+
const micro = d.spec.microsteps ?? 16, per = (360 / d.model.stepAngle) * micro, stepsPerUnit = j.type === 'prismatic' ? (per * t.ratio) / t.slide / 360 : (per * t.ratio) / 360;
|
|
18
|
+
const rpm = workingSpeed(d.model, d.spec, d.supply), maxRate = (rpm / 60) * per, home = spec.home;
|
|
19
|
+
const homing = home ? { endstop: home.endstop, direction: home.direction ?? -1, rate: Math.round(maxRate / 8), back: Math.round(stepsPerUnit * 3) } : null;
|
|
20
|
+
return { name: id, joint: id, motor: d.id, model: d.model.name, driver: d.spec.driver ?? null, stepAngle: d.model.stepAngle, microsteps: micro, ratio: r6(t.ratio), stepsPerUnit: r6(stepsPerUnit), unit: j.type === 'prismatic' ? 'mm' : 'deg', limits: (j.limits ?? j.dofs[0].slice(0, 2)).map(r6), maxRate: Math.round(maxRate), homing,
|
|
21
|
+
_why: { stepAngle: `${d.model.name}.step_angle`, microsteps: d.spec.microsteps != null ? `the motor item's "microsteps" (resolution only, not accuracy)` : 'the default, 1/16 (resolution only, not accuracy)', ratio: t.stages.length ? `the train from ${t.root} to ${id}` : 'direct', maxRate: `${n3(rpm, 1)} rpm, ${d.spec.speed != null ? 'the motor item\'s speed' : `the working speed of a ${d.model.name}`}` } };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The slots of a CNC shield each motor is wired to, by motor item: from a wire "<motor>.<anchor>" to "<item>.X" (X, Y, Z or A). */
|
|
25
|
+
export function shieldSlots(a) {
|
|
26
|
+
const out = {};
|
|
27
|
+
for (const w of a.wires || []) { const [from, to] = [String(w.from), String(w.to)], m = /^[^.]+\.([XYZA])$/.exec(to); if (m) out[from.split('.')[0]] = m[1]; }
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
/** The step and direction slots of the streamer (arm.ino on a CNC Shield V3), in its axis order: axis 0 on X, 1 on Y, 2 on Z. */
|
|
31
|
+
export const STREAMER_SLOTS = ['X', 'Y', 'Z'];
|
|
32
|
+
|
|
33
|
+
/** The machine as plain data. Every figure's origin is said in _why, by the name of the figure. A machine with a gait and no
|
|
34
|
+
* task is its legs: an axis for each joint a motor turns, in the order the shield's slots are wired. @param {object} s a built assembly with a task or a gait */
|
|
13
35
|
export function machineOf(s) {
|
|
14
|
-
if (!s.task
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
if (!d?.model.stepAngle) throw new Error(`${s.project}/${s.name}: joint ${id} has no stepper driving it, and a step file needs one`);
|
|
19
|
-
const micro = d.spec.microsteps ?? 16, per = (360 / d.model.stepAngle) * micro, stepsPerUnit = j.type === 'prismatic' ? (per * t.ratio) / t.slide / 360 : (per * t.ratio) / 360;
|
|
20
|
-
const rpm = workingSpeed(d.model, d.spec, d.supply), maxRate = (rpm / 60) * per, home = spec.home;
|
|
21
|
-
const homing = home ? { endstop: home.endstop, direction: home.direction ?? -1, rate: Math.round(maxRate / 8), back: Math.round(stepsPerUnit * 3) } : null;
|
|
22
|
-
return { name: id, joint: id, motor: d.id, model: d.model.name, driver: d.spec.driver ?? null, stepAngle: d.model.stepAngle, microsteps: micro, ratio: r6(t.ratio), stepsPerUnit: r6(stepsPerUnit), unit: j.type === 'prismatic' ? 'mm' : 'deg', limits: (j.limits ?? j.dofs[0].slice(0, 2)).map(r6), maxRate: Math.round(maxRate), homing,
|
|
23
|
-
_why: { stepAngle: `${d.model.name}.step_angle`, microsteps: d.spec.microsteps != null ? `the motor item's "microsteps" (resolution only, not accuracy)` : 'the default, 1/16 (resolution only, not accuracy)', ratio: t.stages.length ? `the train from ${t.root} to ${id}` : 'direct', maxRate: `${n3(rpm, 1)} rpm, ${d.spec.speed != null ? 'the motor item\'s speed' : `the working speed of a ${d.model.name}`}` } };
|
|
24
|
-
});
|
|
36
|
+
if (!s.task && s.gait) return gaitMachineOf(s);
|
|
37
|
+
if (!s.task) throw new Error(`${s.project}/${s.name} has no "task" and no "gait": a machine says what it is for`);
|
|
38
|
+
const c = chainOf(s), motion = s.motion;
|
|
39
|
+
const axes = c.names.map((id) => axisOf(s, id));
|
|
25
40
|
const kinematics = c.names.length === 2 && motion.joints.filter((j) => c.names.includes(j.id)).every((j) => j.type === 'revolute') ? 'scara' : motion.joints.filter((j) => c.names.includes(j.id)).every((j) => j.type === 'prismatic') ? 'cartesian' : 'serial';
|
|
26
41
|
const pen = s.a.task.pen ?? null;
|
|
27
42
|
return { format: 'rulecad.machine/1', name: `${s.project}/${s.name}`, kinematics, tool: s.task.tool, elbow: sample(s).elbow, axes, task: { sheet: s.a.task.sheet ?? null, region: s.a.task.region ?? null, volume: s.a.task.volume ?? null, speed: s.task.speed, accuracy: s.task.accuracy, accel: s.task.accel ?? 500, ...(s.task.blockTime ? { blockTime: s.task.blockTime } : {}) }, ...(pen ? { pen } : {}) };
|
|
28
43
|
}
|
|
29
44
|
|
|
45
|
+
function gaitMachineOf(s) {
|
|
46
|
+
const seq = gaitSequence(s), slots = shieldSlots(s.a);
|
|
47
|
+
let axes = seq.names.map((id) => { const a = axisOf(s, id); return { ...a, ...(slots[a.motor] ? { slot: slots[a.motor] } : {}) }; });
|
|
48
|
+
if (axes.every((a) => STREAMER_SLOTS.includes(a.slot))) axes = [...axes].sort((a, b) => STREAMER_SLOTS.indexOf(a.slot) - STREAMER_SLOTS.indexOf(b.slot));
|
|
49
|
+
const g = s.gait, pattern = typeof s.a.gait.pattern === 'string' ? s.a.gait.pattern : `duty ${s.a.gait.pattern?.duty}`;
|
|
50
|
+
return { format: 'rulecad.machine/1', name: `${s.project}/${s.name}`, kinematics: 'legged', tool: null, axes, task: null,
|
|
51
|
+
gait: { legs: g.legs.map((l) => l.name), pattern, period: g.period, stride: g.stride, lift: g.lift, height: g.height, frames: seq.q.length } };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A gait as a step file: its cycle played for some cycles from a pose of the assembly and back to it, every leg's joints
|
|
56
|
+
* in the same blocks. Findings say how long a cycle takes on the motors against the gait's period, and whether the
|
|
57
|
+
* streamer can take the file: three axes at most, each on the shield's slot of its own number.
|
|
58
|
+
* @param {object} s a built assembly with a gait @param {{ cycles?: number, period?: number, from?: string }} [o] from: a pose's name (default the pose the assembly shows)
|
|
59
|
+
*/
|
|
60
|
+
export function plotGait(s, { cycles = 3, period, from } = {}) {
|
|
61
|
+
if (!s.gait) throw new Error(`${s.project}/${s.name} has no "gait" to play`);
|
|
62
|
+
const m = machineOf(s), seq = gaitSequence(s), names = m.axes.map((a) => a.name), cols = names.map((n) => seq.names.indexOf(n));
|
|
63
|
+
const ordered = { period: seq.period, names, q: seq.q.map((r) => cols.map((i) => r[i])) };
|
|
64
|
+
const poses = s.motion.poses || {}, poseName = from ?? s.motion.pose ?? null;
|
|
65
|
+
if (from != null && !poses[from]) throw new Error(`--pose ${from}: no such pose (poses: ${Object.keys(poses).join(', ') || 'none'})`);
|
|
66
|
+
const pose = poseName ? poses[poseName] : null, findings = [];
|
|
67
|
+
const start = pose && names.every((n) => num(pose[n])) ? names.map((n) => pose[n]) : null;
|
|
68
|
+
if (poseName && !start) findings.push({ level: 'info', text: `the pose "${poseName}" does not set ${names.filter((n) => !num(pose?.[n])).join(', ')}, so the file starts and ends at the cycle's first frame`, code: 'gait.from', values: {} });
|
|
69
|
+
const r = gaitBlocks(ordered, { axes: m.axes.map((a) => ({ name: a.name, stepsPerUnit: a.stepsPerUnit, maxRate: a.maxRate, unit: a.unit })), cycles, ...(period != null ? { period } : {}), ...(start ? { from: start } : {}) });
|
|
70
|
+
findings.push(...r.findings);
|
|
71
|
+
// the streamer: three axes, axis k on the shield's slot X, Y or Z in that order
|
|
72
|
+
if (names.length > STREAMER_SLOTS.length) findings.push({ level: 'warn', text: `${names.length} axes, and the streamer steps ${STREAMER_SLOTS.length} (an Uno under a CNC Shield V3): the file is written, and send.mjs refuses it`, code: 'stream.axes', values: { axes: names.length, streamer: STREAMER_SLOTS.length } });
|
|
73
|
+
else for (const [k, a] of m.axes.entries()) {
|
|
74
|
+
if (!a.slot) findings.push({ level: 'info', text: `${a.name}'s motor ${a.motor} has no wire to a shield's slot: the streamer steps it as axis ${k}, on ${STREAMER_SLOTS[k]}`, code: 'stream.wiring', refs: { item: a.motor } });
|
|
75
|
+
else if (a.slot !== STREAMER_SLOTS[k]) findings.push({ level: 'fail', text: `${a.name}'s motor ${a.motor} is wired to the shield's ${a.slot}, and the streamer steps axis ${k} on ${STREAMER_SLOTS[k]}`, code: 'stream.wiring', refs: { item: a.motor } });
|
|
76
|
+
}
|
|
77
|
+
const n = r.blocks.length;
|
|
78
|
+
findings.push({ level: 'info', text: `${cycles} cycle${cycles === 1 ? '' : 's'} of the gait (${m.gait.pattern}) in ${n} blocks, ${n3(r.time, 1)} s${start ? `, from the pose "${poseName}" and back to it` : ''}`, code: 'plot.time', values: { time: r.time, cycles, blocks: n } });
|
|
79
|
+
const steps = { ...r, machine: m.name, drawing: 'gait', ...(start ? { pose: poseName } : {}) };
|
|
80
|
+
return { ok: findings.every((x) => x.level !== 'fail'), findings, steps, machine: m, time: { time: r.time } };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// A picture of a gait's step file: each axis's position through the run, from its blocks, with the gait's frames as dots
|
|
84
|
+
export function gaitPicture(result) {
|
|
85
|
+
const f = result.steps, W = 720, H = 160, pad = 40, colours = ['#135', '#c33', '#383', '#a60'];
|
|
86
|
+
const series = f.axes.map(() => []);
|
|
87
|
+
let t = 0, pos = [...f.start];
|
|
88
|
+
series.forEach((p, k) => p.push([0, pos[k] / f.axes[k].stepsPerUnit]));
|
|
89
|
+
for (const b of f.blocks) { t += b.time; pos = pos.map((x, k) => x + b.steps[k]); series.forEach((p, k) => p.push([t, pos[k] / f.axes[k].stepsPerUnit, b.kind])); }
|
|
90
|
+
const panels = series.map((p, k) => {
|
|
91
|
+
const lo = Math.min(...p.map((x) => x[1])), hi = Math.max(...p.map((x) => x[1])), y = (v) => H - 20 - ((v - lo) / (hi - lo || 1)) * (H - 40), x = (s) => pad + (s / (t || 1)) * (W - 2 * pad);
|
|
92
|
+
const line = p.map(([s, v]) => `${n3(x(s))},${n3(y(v))}`).join(' '), dots = p.filter((q) => q[2] === 'gait').map(([s, v]) => `<circle cx="${n3(x(s))}" cy="${n3(y(v))}" r="1.6" fill="${colours[k % 4]}"/>`).join('');
|
|
93
|
+
return `<g transform="translate(0 ${k * H})"><text x="${pad}" y="14" font-size="12" font-family="sans-serif">${f.axes[k].name}: ${n3(lo, 0)} to ${n3(hi, 0)} ${f.axes[k].unit} (the motor's shaft)</text><polyline points="${line}" fill="none" stroke="${colours[k % 4]}" stroke-width="1"/>${dots}</g>`;
|
|
94
|
+
}).join('');
|
|
95
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H * series.length + 24}" viewBox="0 0 ${W} ${H * series.length + 24}"><rect width="100%" height="100%" fill="#fff"/>${panels}<text x="${pad}" y="${H * series.length + 16}" font-size="12" font-family="sans-serif">${n3(t, 1)} s: ${f.cycles} cycles, ${n3(f.cycleTime, 2)} s each against the gait's ${f.period} s; dots are the gait's frames</text></svg>\n`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function writeGait(s, result) {
|
|
99
|
+
const dir = paths.exports(s.project); fs.mkdirSync(dir, { recursive: true }); const file = path.join(dir, `${s.name}-gait.steps.json`);
|
|
100
|
+
fs.writeFileSync(file, JSON.stringify(result.steps));
|
|
101
|
+
const prev = paths.preview(s.project, `${s.name}-gait.svg`); fs.mkdirSync(path.dirname(prev), { recursive: true }); fs.writeFileSync(prev, gaitPicture(result));
|
|
102
|
+
return { file, preview: prev };
|
|
103
|
+
}
|
|
104
|
+
|
|
30
105
|
// A drawing's size against the sheet: the first stroke that leaves it, named
|
|
31
106
|
function fitsSheet(strokes, frame) {
|
|
32
107
|
const off = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.77",
|
|
4
4
|
"description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@rulecad/gears": "^0.3.4",
|
|
75
75
|
"@rulecad/motors": "^0.1.6",
|
|
76
76
|
"@rulecad/fixings": "^0.1.7",
|
|
77
|
-
"@rulecad/robots": "^0.1.
|
|
77
|
+
"@rulecad/robots": "^0.1.4",
|
|
78
78
|
"@rulecad/frames": "^0.1.12"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|