create-rulecad 0.3.22 → 0.3.25

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 CHANGED
@@ -5,6 +5,25 @@ print (a hole's diameter, a seat's depth, a part's outline). Each release lists
5
5
  it makes, with its reason. A **fasten** is an entry in an assembly's `"fasten"` list: one screwed joint, naming the
6
6
  screw by thread and head, the parts it passes through and the part it ends in.
7
7
 
8
+ ## 0.3.25: the arm's sender says what a gait file is (#199)
9
+ ### Changed
10
+
11
+ - The arm's `send.mjs` names a gait's cycles, time and start pose in its dry run's summary, and before it sends one it
12
+ says the leg must stand in that pose. `STREAMER.md` explains how a leg's stand runs on the same streamer.
13
+
14
+ ## 0.3.23: the leg on a 17HS4401 knee and 12 V
15
+
16
+ ### Changed
17
+
18
+ - `--machine leg` makes the stand on a 17HS4401 at hip and knee, the 12 V bench supply limited to 1.5 A and
19
+ `"have": true` on the motors, drivers, shield and supply, as the worked leg in @rulecad/cad's EXAMPLES chapter 14.
20
+ Its stand steps under `leg.stand_load`, the larger of the robot's share and what rides the rods (`leg.riding`,
21
+ 1.01 kg), and the message says which: a 2 kg robot's 1 kg share is under it, a 3 kg robot's 1.5 kg is over.
22
+
23
+ ### Printed sizes
24
+
25
+ - The thigh: the knee motor's four M3 holes on a 31 mm square (the 17HS4401's), was 26 mm (the NEMA 14's).
26
+
8
27
  ## 0.3.22: the arm streams in time (#181)
9
28
 
10
29
  ### Changed
package/index.mjs CHANGED
@@ -105,7 +105,9 @@ async function sized() {
105
105
  const file = path.join(dir, 'rules/leg.json'), rules = JSON.parse(fs.readFileSync(file, 'utf8'));
106
106
  rules.rules.robot = { ...rules.rules.robot, value: robot };
107
107
  fs.writeFileSync(file, `${JSON.stringify(rules, null, 2)}\n`);
108
- return console.log(` a leg on its stand, for a ${robot} kg robot; its share of the weight is ${robot / 2} kg: rules/leg.json`);
108
+ // The stand steps under the robot's share, or under what rides its rods (the leg and its carriage) if that is more
109
+ const riding = rules.rules.riding.value, load = Math.max(robot / 2, riding);
110
+ return console.log(` a leg on its stand, for a ${robot} kg robot; its share of the weight is ${robot / 2} kg, and the stand steps under ${load} kg${load > robot / 2 ? ', what the leg and its carriage weigh' : ''}: rules/leg.json`);
109
111
  }
110
112
  if (!SHEETS[sheet]) { console.error(`--sheet is ${Object.keys(SHEETS).join(', ')} (got "${o.sheet}"; a larger sheet's links wouldn't fit a 256 mm bed)`); process.exit(1); }
111
113
  if (!(accuracy > 0)) { console.error(`--accuracy is above 0 mm (got "${o.accuracy}")`); process.exit(1); }
@@ -24,6 +24,33 @@ hardware is your test: the arm's measured milestone.
24
24
  3. Dry run, with no board: `node projects/arm/send.mjs exports/arm/arm-test.steps.json --machine exports/arm/arm.machine.json --dry-run`. It prints each line it would send with the answer the streamer would give, then a summary. `--quiet` prints the summary only. A dry run has no clock, so it takes each block as finished before the next line: its answer to `?` is the positions summed from the blocks so far, with 0 blocks queued.
25
25
  4. Draw: `node projects/arm/send.mjs exports/arm/arm-test.steps.json --machine exports/arm/arm.machine.json --port <port>`. It turns the drivers on, homes each axis, sends the file, reports every hundredth line, and turns the drivers off. `--no-home` skips homing.
26
26
 
27
+ ## A leg on the same streamer
28
+
29
+ The streamer knows only axes and steps, so a leg runs on it as the arm does. The leg's stand (`projects/leg`, with the
30
+ hip's motor on the shield's X slot and the knee's on Y) takes the same sketch, the same drivers and the same sender:
31
+
32
+ 1. Flash `firmware/arm/arm.ino` to the stand's Uno, as in step 1 above.
33
+ 2. Write the machine and the gait's step file: `npx cad machine leg/stand` writes `exports/leg/stand.machine.json`, and
34
+ `npx cad plot leg/stand` writes `exports/leg/stand-gait.steps.json`: three cycles of the gait, from the pose the
35
+ assembly shows (`standing`) and back to it. `--cycles 5` plays five, `--pose <name>` starts and ends at another pose,
36
+ and `--period 4` plays a cycle in 4 s. `.preview/leg/stand-gait.svg` draws each axis through the run.
37
+ 3. Dry run: `node projects/arm/send.mjs exports/leg/stand-gait.steps.json --machine exports/leg/stand.machine.json --dry-run`.
38
+ 4. Stand the leg in its pose, then send the file with `--port <port>`. The stand has no home switches, so the streamer
39
+ counts from where the motors are when it starts: the file's first block takes the leg from its pose to the cycle, and
40
+ its last brings it back. At the end the drivers go off and the carriage settles on its stop collars.
41
+
42
+ How the gait becomes blocks:
43
+
44
+ | | |
45
+ |---|---|
46
+ | **A block** | The move from one frame of the gait (48 a cycle) to the next, every axis in it, at the rate that keeps to the gait's period |
47
+ | **Too fast for a motor** | A block that would step an axis past its `maxRate` (the motor's working speed, from `cad machine`) is slowed to it, and the cycle takes longer. `cad plot` says by how much, with a warning when a cycle takes over 5% longer than the gait's period. The stand's gait asks the knee for 11712 steps/s at its 2 s period, past the 5333 of a 17HS4401 at 200 rpm and 1/8 steps, so a cycle takes 2.89 s on the motors |
48
+ | **A joint turning back** | Where a foot lifts off or sets down, a joint reverses. The run slows there so that no axis changes speed by more than its jump at once: an eighth of its `maxRate`, the rate `cad machine` homes it at from rest. It speeds up and slows down at no more than 4 × `maxRate` steps/s², full speed in 0.25 s. Both are estimates: no motor's start-stop rate under load has been measured yet |
49
+ | **From the pose and back** | A move from rest to rest at half the axes' fastest |
50
+
51
+ The streamer has three axes, and the sender refuses a file with more before anything moves: the quadruped's eight
52
+ motors need more than one Uno under one shield. `cad plot` still writes its step file, and says so.
53
+
27
54
  ## The line protocol
28
55
 
29
56
  115200 baud, 8 data bits, no parity, 1 stop bit. One command a line, ended by a newline. The streamer answers every
@@ -94,7 +121,8 @@ board has not yet been timed: your bench test does that, and the USB turnaround
94
121
 
95
122
  `node scripts/firmware.mjs` (in the kit's repository) compiles every sketch for `arduino:avr:uno` and fails on a compile
96
123
  error. With `--simulate <steps file> --machine <machine file>` it also runs this streamer on a simulated Uno, and fails
97
- when any of these does not hold:
124
+ when any of these does not hold. The two flags can be given again for another step file: the kit's tests stream the arm's
125
+ drawing and then the leg's gait, each with its own machine, and measure the loop's own ceilings once.
98
126
 
99
127
  | Check | Held to |
100
128
  |---|---|
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
- // Sends a step file (rulecad.steps/1, from cad plot) to the arm's Uno, line by line, each after the last was answered.
2
+ // Sends a step file (rulecad.steps/1, from cad plot: an arm's drawing or a leg's gait) to the Uno, line by line, each after
3
+ // the last was answered.
3
4
  // node send.mjs <file.steps.json> --port /dev/tty.usbmodem101 [--machine arm.machine.json] [--no-home]
4
5
  // node send.mjs <file.steps.json> --dry-run [--machine arm.machine.json] [--quiet]
5
6
  // echoes each line it would send with the answer the streamer would give,
@@ -94,6 +95,9 @@ export function dryRun(lines, { machine, turnaround = TURNAROUND } = {}) {
94
95
  return { lines: lines.length, ...seen, peakRate: peak, axisPeaks, position, said };
95
96
  }
96
97
 
98
+ /** What a gait's step file is, for the summary: its cycles, time and start pose (nothing for a drawing). @param {object} file */
99
+ export const gait = (file) => (file?.kind === 'gait' ? `, ${file.cycles} cycle${file.cycles === 1 ? '' : 's'} of a gait, ${Number(file.time).toFixed(1)} s${file.pose ? ` from the pose "${file.pose}" and back` : ''}` : '');
100
+
97
101
  async function send(port, lines, say) {
98
102
  const r = spawnSync('stty', [process.platform === 'darwin' ? '-f' : '-F', port, '115200', 'raw', '-echo', '-hupcl'], { encoding: 'utf8' });
99
103
  if (r.status) throw new Error(`stty ${port}: ${r.stderr}`);
@@ -120,9 +124,11 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
120
124
  try { r = dryRun(lines, { machine }); } catch (e) { console.error(`${has('dry-run') ? 'dry run' : 'not sent'}: ${e.message}`); process.exit(1); }
121
125
  if (has('dry-run')) {
122
126
  if (!has('quiet')) for (const s of r.said) console.log(s);
123
- console.log(`dry run: ${r.lines} lines, ${r.m} blocks, ${r.p} pen moves, ${r.h} homes, peak ${r.peakRate} steps/s (the streamer takes ${MAX_RATE})${machine ? `, axes at most ${r.axisPeaks.slice(0, machine.axes.length).map((x, k) => `${Math.round(x)} of ${machine.axes[k].maxRate}`).join(', ')} steps/s` : ''}`);
127
+ console.log(`dry run: ${r.lines} lines, ${r.m} blocks, ${r.p} pen moves, ${r.h} homes, peak ${r.peakRate} steps/s (the streamer takes ${MAX_RATE})${machine ? `, axes at most ${r.axisPeaks.slice(0, machine.axes.length).map((x, k) => `${Math.round(x)} of ${machine.axes[k].maxRate}`).join(', ')} steps/s` : ''}${gait(file)}`);
124
128
  process.exit(0);
125
129
  }
126
130
  if (!opt('port')) { console.error('--port <device>, or --dry-run'); process.exit(2); }
131
+ // a gait has no home: the streamer counts from where the motors stand when it starts, so the leg must be in its pose
132
+ if (file.kind === 'gait') console.log(`a gait${gait(file)}: the streamer counts from where the motors stand now, so the leg must be in ${file.pose ? `its pose "${file.pose}"` : "the cycle's first frame"}`);
127
133
  send(opt('port'), lines, console.log).then(() => console.log('done')).catch((e) => { console.error(e.message); process.exit(1); });
128
134
  }
@@ -9,7 +9,7 @@
9
9
  { "id": "carriage", "object": "carriage", "rotate": [90, 0, 0] },
10
10
  { "id": "lm1", "bought": "lm8uu", "at": ["0 - leg.rod_x", "0 - leg.rod_y", "0 - carriage.boss_long / 2"] },
11
11
  { "id": "lm2", "bought": "lm8uu", "at": ["leg.rod_x", "0 - leg.rod_y", "0 - carriage.boss_long / 2"] },
12
- { "id": "m1", "motor": { "model": "17HS4401", "drives": "hd", "speed": 200, "duty": 0.3, "driver": "d1", "current": 0.5, "microsteps": 8 } },
12
+ { "id": "m1", "motor": { "model": "17HS4401", "drives": "hd", "speed": 200, "duty": 0.3, "driver": "d1", "current": 0.5, "microsteps": 8 }, "have": true },
13
13
  { "id": "housing", "object": "housing", "rotate": [-90, 0, 0] },
14
14
  { "id": "sun", "object": "sun" },
15
15
  { "id": "carrier", "object": "speck" },
@@ -19,7 +19,7 @@
19
19
  { "id": "bridge", "object": "bridge", "at": [0, "leg.bridge_low", 0], "rotate": [-90, 0, 0] },
20
20
  { "id": "b1", "bought": "bearing-6800", "at": [0, "leg.bridge_low + leg.bridge - leg.bearing_width", 0], "rotate": [-90, 0, 0] },
21
21
  { "id": "thigh", "object": "thigh" },
22
- { "id": "m2", "motor": { "model": "nema14", "drives": "kd", "speed": 200, "duty": 0.3, "driver": "d2", "current": 0.5, "microsteps": 8 } },
22
+ { "id": "m2", "motor": { "model": "17HS4401", "drives": "kd", "speed": 200, "duty": 0.3, "driver": "d2", "current": 0.5, "microsteps": 8 }, "have": true },
23
23
  { "id": "esun", "object": "sun", "set": { "tip": 11.7 } },
24
24
  { "id": "ecarrier", "object": "speck" }, { "id": "ering", "object": "speck" },
25
25
  { "id": "ep1", "object": "planet" }, { "id": "ep2", "object": "planet" }, { "id": "ep3", "object": "planet" },
@@ -34,10 +34,10 @@
34
34
  { "id": "collar1", "object": "collar", "rotate": [0, 0, 180], "at": ["0 - leg.rod_x", "0 - leg.rod_y", "0 - carriage.boss_long / 2 - leg.stop_drop - collar1.high"] },
35
35
  { "id": "collar2", "object": "collar", "at": ["leg.rod_x", "0 - leg.rod_y", "0 - carriage.boss_long / 2 - leg.stop_drop - collar2.high"] },
36
36
  { "id": "scale", "object": "scale", "at": [0, 5, "0 - leg.stance - leg.foot_r - leg.scale_h"] },
37
- { "id": "d1", "bought": "drv8825", "at": [240, -30, -180] },
38
- { "id": "d2", "bought": "drv8825", "at": [240, 0, -180] },
39
- { "id": "shield", "bought": "cnc-shield-v3", "at": [240, 0, -190] },
40
- { "id": "psu", "bought": "supply-24v", "variant": "LRS-50-24", "at": [300, 150, -190] }
37
+ { "id": "d1", "bought": "drv8825", "at": [240, -30, -180], "have": true },
38
+ { "id": "d2", "bought": "drv8825", "at": [240, 0, -180], "have": true },
39
+ { "id": "shield", "bought": "cnc-shield-v3", "at": [240, 0, -190], "have": true },
40
+ { "id": "psu", "bought": "supply-12v", "set": { "output_current": 1.5 }, "at": [300, 150, -190], "have": true }
41
41
  ],
42
42
  "joints": [
43
43
  { "id": "m1_on", "type": "fixed", "parent": "housing.motor", "child": "m1.face" },
@@ -104,8 +104,8 @@
104
104
  "wires": [
105
105
  { "id": "hip_wire", "from": "m1.connector", "to": "shield.X", "via": ["carriage.cable"], "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"] },
106
106
  { "id": "knee_wire", "from": "m2.connector", "to": "shield.Y", "via": ["thigh.cable", "carriage.cable"], "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"] },
107
- { "id": "power", "from": "psu.terminals", "to": "shield.top", "gauge": "awg22", "colour": "red, black", "conductors": 2, "current": 2, "connectors": ["Ring terminal", "Screw terminal"], "note": "24 V into the shield's motor terminals" }
107
+ { "id": "power", "from": "psu.terminals", "to": "shield.top", "gauge": "awg22", "colour": "red, black", "conductors": 2, "current": 2, "connectors": ["Ring terminal", "Screw terminal"], "note": "12 V from the bench supply, its current limit at 1.5 A, into the shield's motor terminals" }
108
108
  ],
109
- "gait": { "legs": ["shin.tip"], "pattern": { "duty": 0.6, "phase": [0] }, "stride": "leg.stride", "lift": "leg.lift", "period": 2, "height": "leg.stance", "mass": "leg.share", "clearance": 12 },
109
+ "gait": { "legs": ["shin.tip"], "pattern": { "duty": 0.6, "phase": [0] }, "stride": "leg.stride", "lift": "leg.lift", "period": 2, "height": "leg.stance", "mass": "leg.stand_load", "clearance": 12 },
110
110
  "poses": { "standing": { "hd": -5587.7, "kd": -2236 } }
111
111
  }
@@ -1,5 +1,5 @@
1
1
  // The thigh, drawn as it prints: its outer face on the bed, the knee's ring standing on it, the hub's socket opening
2
- // upward. The knee's NEMA 14 bolts on the bed side, its shaft up through the plate, as the arm's elbow does.
2
+ // upward. The knee's 17HS4401, the hip's motor, bolts on the bed side, its shaft up through the plate, as the arm's elbow does.
3
3
  // The screws' holes are v.fixings': an M3 clearance hole through the socket's floor for the screw into the spindle,
4
4
  // and an M3 pilot in each post for its clip.
5
5
  import jscad from '@jscad/modeling'
@@ -10,7 +10,7 @@ const { hull } = jscad.hulls
10
10
 
11
11
  export function main (v) {
12
12
  const screw = v.fixings.holeModel('M3').diameter, pilot = v.fixings.holeModel('M3', { kind: 'pilot' }).diameter
13
- const motor = v.motors.motorModel('nema14')
13
+ const motor = v.motors.motorModel('17HS4401')
14
14
  const at = (r, a) => [v.long + r * Math.cos(a), r * Math.sin(a)]
15
15
  const posts = [v.p1, v.p2, v.p3].map((a) => a * v.rad)
16
16
  const round = (r, c) => translate([c, 0], circle({ radius: r, segments: v.segments }))
@@ -26,6 +26,8 @@
26
26
  "lift": {"value": 15, "unit": "mm", "rule": "The foot's lift in swing", "kind": "default", "source": "EXAMPLES chapter 14", "checked": "2026-11-09"},
27
27
  "robot": {"value": 1.5, "unit": "kg", "rule": "The small robot the leg is sized for first; the quadruped built from these parts weighs more, and the chapter says how much", "kind": "default", "source": "EXAMPLES chapter 14", "checked": "2026-11-09"},
28
28
  "share": {"value": "robot / 2", "unit": "kg", "rule": "Each leg's share in a trot, the most: two feet down at once", "kind": "default", "source": "Statics: the weight split over the two feet in stance", "checked": "2026-11-09"},
29
+ "riding": {"value": 1.01, "unit": "kg", "rule": "What rides the stand's rods, and so stands on the foot: the leg (its two 17HS4401s 560 g, its prints 295 g, the 6800 5 g), the carriage 92 g, its two LM8UU 32 g and the screws 24 g", "kind": "derived", "source": "cad list leg/stand, summed by hand", "checked": "2026-11-23"},
30
+ "stand_load": {"value": "max(share, riding)", "unit": "kg", "rule": "The stand's load in its gait: the robot's share, or what rides the rods if that is more, since the foot carries all of it", "kind": "derived", "source": "Statics: the carriage, lifted off its stops, stands on the foot", "checked": "2026-11-23"},
29
31
  "scale_h": {"value": 25, "unit": "mm", "rule": "A kitchen scale's height: the foot's ground is its top. Yours differs", "kind": "estimate", "source": "A guess at a common 5 kg scale: measure yours", "checked": "2026-11-09"},
30
32
  "stop_drop": {"value": 3, "unit": "mm", "rule": "How far the carriage drops onto its stops when the foot lifts: the foot pushes it up this much standing, so the scale carries the leg", "kind": "default", "source": "EXAMPLES chapter 14", "checked": "2026-11-09"},
31
33
  "rod_x": {"value": 90, "unit": "mm", "rule": "Each rod's distance from the middle: a 130 mm scale fits between the feet", "kind": "default", "source": "EXAMPLES chapter 14", "checked": "2026-11-09"},
@@ -36,7 +38,7 @@
36
38
  "body_half": {"value": 75, "unit": "mm", "rule": "Hip to hip along the body, halved: the side plate, 242 mm long, fits on a 256 mm bed, and the knees point outward so they stay apart", "kind": "default", "source": "EXAMPLES chapter 14", "checked": "2026-11-09"},
37
39
  "body_w": {"value": 50, "unit": "mm", "rule": "The body's half-width, to the hips' plates: two hip motors back to back fit inside", "kind": "default", "source": "EXAMPLES chapter 14", "checked": "2026-11-09"},
38
40
  "side_t": {"value": 6, "unit": "mm", "rule": "The side plate's thickness", "kind": "default", "source": "EXAMPLES chapter 14", "checked": "2026-11-09"},
39
- "robot_mass": {"value": 3.8, "unit": "kg", "rule": "The quadruped as drawn: 3.37 kg of prints, motors and bearings from cad list, and about 0.4 kg for its drivers, an Uno and shield, a battery and the wires, an estimate until built", "kind": "estimate", "source": "cad list leg/quadruped and a guess at the electronics", "checked": "2026-11-09"},
41
+ "robot_mass": {"value": 4.2, "unit": "kg", "rule": "The quadruped as drawn: 3.83 kg of prints, eight 17HS4401s, bearings and screws from cad list, and about 0.4 kg for its drivers, an Uno and shield, a battery and the wires, an estimate until built", "kind": "estimate", "source": "cad list leg/quadruped (3834 g, the knees 17HS4401s at 280 g each) and a guess at the electronics", "checked": "2026-11-23"},
40
42
  "foot_socket": {"value": 12, "unit": "mm", "rule": "How far each rod goes into a foot block", "kind": "default", "source": "EXAMPLES chapter 14", "checked": "2026-11-09"}
41
43
  }
42
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-rulecad",
3
- "version": "0.3.22",
3
+ "version": "0.3.25",
4
4
  "description": "Start a rulecad project: npm create rulecad my-designs. A workspace with a soap tray to start from, ready to check, preview, export and share.",
5
5
  "type": "module",
6
6
  "bin": {