create-rulecad 0.3.21 → 0.3.23

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,41 @@ 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.23: the leg on a 17HS4401 knee and 12 V
9
+
10
+ ### Changed
11
+
12
+ - `--machine leg` makes the stand on a 17HS4401 at hip and knee, the 12 V bench supply limited to 1.5 A and
13
+ `"have": true` on the motors, drivers, shield and supply, as the worked leg in @rulecad/cad's EXAMPLES chapter 14.
14
+ Its stand steps under `leg.stand_load`, the larger of the robot's share and what rides the rods (`leg.riding`,
15
+ 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.
16
+
17
+ ### Printed sizes
18
+
19
+ - The thigh: the knee motor's four M3 holes on a 31 mm square (the 17HS4401's), was 26 mm (the NEMA 14's).
20
+
21
+ ## 0.3.22: the arm streams in time (#181)
22
+
23
+ ### Changed
24
+
25
+ - `--machine arm`'s streamer, `projects/arm/firmware/arm/arm.ino`, refuses a block faster than its `MAX_RATE` (8000
26
+ steps/s) with `error: rate`, steps every axis due on a tick in one write to the Uno's port D, and divides once a step
27
+ instead of twice. It reads a line a character at a time between steps (parsing a whole line at its end held the steps
28
+ 520 to 600 µs), a block that follows another keeps its time, and past 5000 steps/s it works out the speed every other
29
+ step. On a simulated Uno its loop now keeps up with 12428 steps/s on three axes at once while slowing down, its
30
+ slowest path (1.55 times MAX_RATE), and 21237 steps/s at a block's cruise, up from 9417. A malformed line is answered
31
+ `error: line`. The simulation in CI measures the loop speeding up and slowing down as well as at the cruise, streams
32
+ the shortest blocks the sender passes, and fails if any ceiling is under MAX_RATE or a stream falls 1% behind.
33
+ Its STEP pulse is 3.06 µs high (it was 6.3 µs), over the DRV8825's 1.9 µs minimum.
34
+ - `projects/arm/send.mjs` refuses a block shorter than its line and answer take on the serial line plus 5.1 ms for the
35
+ USB link (`leastBlockTime`: 8.66 ms for a 36-character line), naming the line, and checks the whole file before it
36
+ opens the port. The arm's task gives `"blockTime": 0.011`, so `cad plot` plans no move shorter.
37
+ - `projects/arm/send.mjs --dry-run` prints each line it would send with the answer the streamer would give (`--quiet`
38
+ for the summary only), and with `--machine` holds each axis's share of a block's rate to that axis's `maxRate`. It
39
+ takes the protocol's `?` and `!` lines too: `?` answers `q` with the positions summed from the blocks before it.
40
+ - `projects/arm/STREAMER.md` writes up the serial protocol, the timing and how the sketch is checked. No printed size
41
+ moved.
42
+
8
43
  ## 0.3.21: the arm on a 17HS4401 elbow and 12 V
9
44
 
10
45
  ### 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); }
@@ -0,0 +1,108 @@
1
+ # The arm's streamer and its sender
2
+
3
+ The arm draws with two programs. `firmware/arm/arm.ino` runs on an Arduino Uno under a CNC Shield V3: it takes blocks of
4
+ synchronised steps over the USB serial line and moves the motors. `send.mjs` runs on your computer: it reads a step
5
+ file that `cad plot` wrote, homes the arm and sends the file to the Uno a line at a time. The Uno knows nothing of the
6
+ arm's shape. All the arm's maths happens in `cad plot`.
7
+
8
+ **Status.** The sketch is compiled for the Uno, and run on a simulated Uno, on every push to the kit (the `firmware`
9
+ job of its tests). The simulation homes the arm and streams the worked arm's step file through it. Moving real
10
+ hardware is your test: the arm's measured milestone.
11
+
12
+ ## What you need
13
+
14
+ | | |
15
+ |---|---|
16
+ | **Board** | Arduino Uno (16 MHz), CNC Shield V3 on top, a step driver (DRV8825 or A4988) in each slot used |
17
+ | **On your computer** | Node 20 or later; the Arduino IDE or `arduino-cli` with the `arduino:avr` core and the `Servo` library, to flash the sketch |
18
+ | **Wiring** | The shoulder on the shield's X slot, the elbow on Y, a third axis (if any) on Z; the home switches on the X and Y limit pins (D9 and D10), a third axis's on D12; the pen servo's signal on D11 (the Z limit pin on a V3.00 shield). `cad machine` writes the wiring sheet |
19
+
20
+ ## Using it
21
+
22
+ 1. Flash the sketch: `arduino-cli compile --fqbn arduino:avr:uno firmware/arm` then `arduino-cli upload -p <port> --fqbn arduino:avr:uno firmware/arm`, or open `firmware/arm/arm.ino` in the Arduino IDE and upload it.
23
+ 2. Write the machine description and a step file: `npx cad machine arm/arm` writes `exports/arm/arm.machine.json`, and `npx cad plot arm/arm projects/arm/drawings/test.svg` writes `exports/arm/arm-test.steps.json`. `npx cad plot arm/arm --calibrate` writes the calibration drawing (a 100 mm square and a circle at three places on the sheet).
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
+ 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
+
27
+ ## The line protocol
28
+
29
+ 115200 baud, 8 data bits, no parity, 1 stop bit. One command a line, ended by a newline. The streamer answers every
30
+ line once: `ok` when it has taken the line, or `error: <what>` when it cannot. The sender waits for that answer before
31
+ it sends the next line. That is the flow control: a line that finds the queue full is held until a block finishes,
32
+ and only then answered, so the 12-block queue never overruns. A line is at most 95 characters. Every number is a whole
33
+ number.
34
+
35
+ The streamer reads a line a character at a time as it arrives, between steps, so a line costs it no more than its bytes
36
+ take on the wire. Because the sender waits for each answer, a block must last at least as long as its own line, the
37
+ newline and the 4-byte answer (`ok`, then a carriage return and a line feed) take to cross the serial line, plus the
38
+ time the USB link holds them: otherwise the queue runs dry and the motors stop between blocks. `send.mjs` refuses such a
39
+ block, naming its line, before it sends anything (see Timing). `cad plot` plans none that short: the arm's task gives
40
+ `"blockTime": 0.011`, the least seconds a move lasts, and a shorter move is slowed until it lasts that long.
41
+
42
+ | Command | Arguments | What it does | Answers |
43
+ |---|---|---|---|
44
+ | `e` | | Drivers on: the motors hold | `ok` |
45
+ | `d` | | Drivers off: the motors go slack | `ok` |
46
+ | `h` | axis, direction, rate, back | Home one axis (0, 1 or 2): step towards direction (1 or -1) at rate steps/s until its switch closes, then step back off it by back steps, and call that position 0. It waits for the queue to empty first | `ok`; `error: endstop` if the switch has not closed after 60 s; `error: home` for a bad axis or rate |
47
+ | `p` | degrees, milliseconds | Queue the pen servo to degrees, then a wait of milliseconds before the next block | `ok` |
48
+ | `w` | milliseconds | Queue a wait | `ok` |
49
+ | `m` | a, b, c, entry, peak, exit, accel, up, down | Queue a block: signed steps on axes 0, 1 and 2; the major axis's rate at entry, at its peak and at exit (steps/s); its acceleration (steps/s²); the major axis's steps spent speeding up, and slowing down. The major axis is the one with the most steps; the others step in proportion | `ok`; `error: block` if it moves nothing or its peak or acceleration is 0; `error: rate` if a rate is past MAX_RATE |
50
+ | `?` | | Report | `q <pos0> <pos1> <pos2> <queued>`: positions in steps as of the last step taken, and the blocks waiting |
51
+ | `!` | | Stop at once and empty the queue; the drivers stay on | `ok` |
52
+ | | | A line over 95 characters, or a number in it that is not a whole number | `error: line` |
53
+ | | | Anything else | `error: command` |
54
+
55
+ On power-up, and each time the serial port opens (which resets the Uno), the streamer prints `arm ready`. The sender
56
+ waits 2.5 s for it.
57
+
58
+ ## Timing
59
+
60
+ | Figure | Value | Source |
61
+ |---|---|---|
62
+ | MAX_RATE, the fastest block the streamer takes | 8000 steps/s on the major axis | `RATE_LIMIT` in `arm.ino`, and `MAX_RATE` in `send.mjs` (a test holds them equal) |
63
+ | What the worked arm asks | up to 8000 steps/s an axis (`maxRate`: 300 rpm of a 200-step motor at 1/8 microstepping is 300 × 1600 / 60), 7799 steps/s in the test drawing | `cad machine arm/arm` and `cad plot` |
64
+ | The loop's own ceiling while speeding up, one, two and three axes stepping at once | 13530, 13009 and 12526 steps/s | measured on a simulated 16 MHz Uno (avr8js), the sketch built with RATE_LIMIT raised: the mean over a long block's middle steps |
65
+ | The loop's own ceiling while slowing down, one, two and three axes | 13415, 12904 and 12428 steps/s | the same |
66
+ | The loop's own ceiling at a block's cruise, one, two and three axes | 24290, 22658 and 21237 steps/s | the same |
67
+ | A byte on the serial line | 86.8 µs | 115200 baud, 10 bits a byte (start, 8 data, stop) |
68
+ | A line's cost to the streamer | its bytes, its newline and the 4-byte answer on the wire, and nothing more measurable | measured on the simulated Uno: a 36-character block line and its answer take 3.55 ms there, against 3.56 ms on the wire (before the streamer parsed as it read, 3.87 ms) |
69
+ | The USB turnaround | 5.1 ms, an estimate | the Uno's USB chip (an ATmega16U2 running Arduino-usbserial) passes the answer on when its timer 0 overflows, 256 × 256 / 16 MHz = 4.1 ms (`Arduino-usbserial.c` in ArduinoCore-avr, read 2026-11-23); then up to a 1 ms USB frame for the next line. Copies with a CH340 USB chip differ |
70
+ | The least time a block lasts | (characters in its line + 1 + 4) × 86.8 µs + 5.1 ms: 8.66 ms for a 36-character line, 70 steps at MAX_RATE | `leastBlockTime` in `send.mjs`, from the three rows above |
71
+ | The arm's planned least block time | 0.011 s (`task.blockTime` in `assemblies/arm.json`) | the least time for a 60-character line, 10.74 ms; the worked file's block lines are 34 to 41 characters |
72
+ | STEP pulse width | 3.06 µs high | measured on the simulated Uno; the DRV8825 needs 1.9 µs, the A4988 1 µs (Pololu's DRV8825 carrier page, product 2133, from TI's datasheet) |
73
+ | Uno clock | 16 MHz | Arduino Uno Rev3 |
74
+
75
+ The slowest of the nine ceilings, three axes slowing down at 12428 steps/s, is 1.55 times MAX_RATE. A step that changes
76
+ speed costs a float multiply and a division (gap = 1000000 / rate), which is why speeding up and slowing down are slower
77
+ than the cruise (2.65 times MAX_RATE), where the gap stays as it is. Past 5000 steps/s the speed is worked out every
78
+ other step, over both steps' time: done on every step, three axes slowing down reached only 8904 steps/s, and with lines
79
+ arriving the streamer fell 8% behind on short blocks. The simulation fails if any of the nine falls under MAX_RATE.
80
+
81
+ The ceilings are measured with one long block and no serial traffic, so they do not show what a stream of short blocks
82
+ costs. The simulation streams those too: the shortest blocks the sender passes, at MAX_RATE on three axes, cruising
83
+ (29 steps, 3.63 ms) and slowing down on every step (32 steps, 4.0 ms), with no USB turnaround since the simulation has no
84
+ USB link. Both keep to their planned time (0.2500 s of 0.2500 s, and 0.2519 s of 0.2519 s); the simulation fails if
85
+ either is more than 1% behind. Before the streamer parsed as it read, the same streams took 8% and 16% longer, and
86
+ 3-axis blocks of 20 steps at MAX_RATE took 55% longer: such blocks are now refused by the sender.
87
+
88
+ A step that an interrupt (the serial line, the clock, the servo) or a block's start delays is caught up at once, so one
89
+ gap can be as long as about 240 µs and the next as short as about 50 µs; the steps keep to their planned times on
90
+ average. The simulation runs the compiled program an instruction at a time, each taking its cycles at 16 MHz. A real
91
+ board has not yet been timed: your bench test does that, and the USB turnaround with it.
92
+
93
+ ## How the sketch is checked
94
+
95
+ `node scripts/firmware.mjs` (in the kit's repository) compiles every sketch for `arduino:avr:uno` and fails on a compile
96
+ 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:
98
+
99
+ | Check | Held to |
100
+ |---|---|
101
+ | Every line answered | `ok`, homing included |
102
+ | Homing | each axis stops at its switch (placed 300 steps away) and backs off by `back` steps |
103
+ | Steps | each axis's step count and its net position equal the step file's sums, and the streamer's own `?` report agrees |
104
+ | Keeping up | the moves take no more than 5% longer than `cad plot` planned |
105
+ | Short blocks | the shortest blocks the sender passes, streamed at MAX_RATE on three axes, cruising and slowing down on every step, take no more than 1% longer than planned |
106
+ | MAX_RATE | a block 1 step/s past it is answered `error: rate`, a block at it `ok` |
107
+ | Ceiling | the loop steps one, two and three axes faster than MAX_RATE at the cruise, speeding up and slowing down (nine figures), and no axis of the machine asks more than MAX_RATE |
108
+ | STEP pulse | at least 1.9 µs high |
@@ -112,6 +112,6 @@
112
112
  { "joint": "out", "torque": "arm.shoulder_torque", "note": "The pen's drag at its reach, the arm's inertia at 500 mm/s², the bias" },
113
113
  { "joint": "elbow", "torque": "arm.elbow_torque", "note": "The pen's drag, the forearm's inertia, the bias" }
114
114
  ],
115
- "task": { "tool": "holder.tool", "sheet": { "size": "a5", "landscape": true, "at": ["arm.near + arm.sheet_h / 2", 0, 0], "u": [0, 1, 0] }, "speed": 50, "accuracy": 0.3, "accel": 500, "elbow": "left", "deflection": "arm.deflection", "pen": { "up": 20, "down": 0 } },
115
+ "task": { "tool": "holder.tool", "sheet": { "size": "a5", "landscape": true, "at": ["arm.near + arm.sheet_h / 2", 0, 0], "u": [0, 1, 0] }, "speed": 50, "accuracy": 0.3, "accel": 500, "blockTime": 0.011, "elbow": "left", "deflection": "arm.deflection", "pen": { "up": 20, "down": 0 } },
116
116
  "poses": { "rest": { "drive": -1530, "edrive": -4586, "lift_servo": 0 } }
117
117
  }
@@ -11,16 +11,33 @@
11
11
  // w <ms> wait
12
12
  // m <a> <b> <c> <entry> <peak> <exit> <accel> <up> <down>
13
13
  // a block: signed steps per axis, then the major axis's step rate at entry, peak and exit
14
- // (steps/s), its acceleration (steps/s²), and the major steps spent speeding up and slowing down
14
+ // (steps/s), its acceleration (steps/s²), and the major steps spent speeding up and slowing down.
15
+ // "error: rate" if its peak is past MAX_RATE, "error: block" if it moves nothing
16
+ // (a block must last as long as its line and answer take to cross the serial line: send.mjs
17
+ // refuses a shorter one, and cad plot plans none shorter than the task's blockTime)
15
18
  // ? prints "q <pos0> <pos1> <pos2> <blocks queued>" (positions in steps, as of the last block finished)
16
19
  // ! stop at once, empty the queue, drivers stay on: answers "ok"
17
20
  //
21
+ // "error: line" if a line is over 95 characters or a number in it is not a whole number.
22
+ //
18
23
  // Timing: steps are timed in the main loop from micros(), with serial read between them, so the servo library keeps its
19
- // timer. Rates of up to about 8000 steps/s on the major axis are within reach of a 16 MHz Uno. Compiled for the Uno and
20
- // exercised with send.mjs --dry-run here; moving hardware is a bench test (the machine's measured milestone).
24
+ // timer. A line is parsed a character at a time as it arrives, so no step waits for a whole line to be read, and a block
25
+ // that follows another keeps its time: its first step is one gap after the last block's last. The step and direction
26
+ // pins are all on the Uno's port D (D2 to D7), so the axes due on a tick are stepped in one write. A step that changes
27
+ // speed costs a division; past 5000 steps/s that is done every other step, over both steps' time. MAX_RATE is the
28
+ // fastest block it takes: on a simulated 16 MHz Uno (scripts/firmware.mjs --simulate, in CI) the loop keeps up with more
29
+ // than that with all three axes stepping at once, speeding up and slowing down as well as at the cruise, and with the
30
+ // shortest blocks the sender passes streaming in.
31
+ // Compiled for the Uno and run on the simulated one in CI; moving hardware is a bench test (the machine's measured milestone).
21
32
  #include <Servo.h>
22
33
 
34
+ #ifndef RATE_LIMIT
35
+ #define RATE_LIMIT 8000
36
+ #endif
37
+ const long MAX_RATE = RATE_LIMIT; // steps/s on a block's major axis; the simulation builds with -DRATE_LIMIT raised to find the loop's own limit
23
38
  const uint8_t STEP[3] = { 2, 3, 4 }, DIR[3] = { 5, 6, 7 }, LIMIT[3] = { 9, 10, 12 }, ENABLE_PIN = 8, PEN_PIN = 11;
39
+ const uint8_t STEP_MASK[3] = { _BV(PD2), _BV(PD3), _BV(PD4) }; // the STEP pins' bits in PORTD
40
+ const uint8_t DIR_MASK[3] = { _BV(PD5), _BV(PD6), _BV(PD7) }; // the DIR pins' bits in PORTD
24
41
  const uint8_t QUEUE = 12;
25
42
  const long MIN_RATE = 80; // steps/s: slower than this a block would take seconds to start
26
43
 
@@ -32,8 +49,13 @@ inline uint8_t count() { return head >= tail ? head - tail : head + QUEUE - tail
32
49
 
33
50
  Servo pen;
34
51
  long position[3] = { 0, 0, 0 };
35
- char line[96];
36
- uint8_t len = 0;
52
+ // The line being read, taken a character at a time as it arrives, between steps: its command letter, then up to ARGS
53
+ // whole numbers, each built up digit by digit. Parsing a whole line at its end (strtol) held the steps up 520 to 600 µs.
54
+ const uint8_t ARGS = 9, LINE_MAX = 95;
55
+ char cmd = 0;
56
+ long arg[ARGS];
57
+ uint8_t len = 0, nargs = 0;
58
+ bool inNumber = false, negative = false, bad = false;
37
59
  bool pending = false; // a whole line is waiting for room in the queue
38
60
 
39
61
  // The block being run
@@ -42,7 +64,17 @@ Block cur;
42
64
  long done = 0, acc[3];
43
65
  unsigned long nextAt = 0, waitUntil = 0;
44
66
  bool waiting = false;
45
- float rate = 0;
67
+ bool chained = false; // the last block ended on a step with the next due one gap after it: the next block keeps that time
68
+ float rate = 0, gap = 0; // steps/s, and the µs from this step to the next
69
+ // The block's speed figures as floats, worked out once at its start: the acceleration per µs, the peak, the least exit
70
+ // rate, and the step from which it slows down
71
+ float accelUs = 0, peakF = 0, floorF = 0;
72
+ long downFrom = 0;
73
+ // A gap shorter than this (faster than 5000 steps/s), µs: the speed is worked out every other step, over both steps' time.
74
+ // A speed change costs a float multiply and a division, about half the 125 µs between steps at MAX_RATE, and the loop
75
+ // reads the serial line too; done every step the streamer fell behind slowing down from MAX_RATE with lines arriving.
76
+ const float FINE_GAP = 200;
77
+ bool skipped = false; // the last step in a ramp left its speed change to this one
46
78
 
47
79
  void setup() {
48
80
  Serial.begin(115200);
@@ -53,36 +85,50 @@ void setup() {
53
85
  Serial.println(F("arm ready"));
54
86
  }
55
87
 
56
- void pulse(uint8_t axis) { digitalWrite(STEP[axis], HIGH); delayMicroseconds(3); digitalWrite(STEP[axis], LOW); }
88
+ // A STEP pulse on the axes in mask, 3 µs high (delayMicroseconds(3) gave 2.06 µs on the simulated Uno, too near the
89
+ // DRV8825's 1.9 µs minimum; the A4988's is 1 µs)
90
+ void pulse(uint8_t mask) { PORTD |= mask; delayMicroseconds(4); PORTD &= ~mask; }
57
91
 
58
92
  bool home(uint8_t axis, int dir, long hz, long back) {
59
93
  digitalWrite(DIR[axis], dir > 0 ? HIGH : LOW);
60
94
  unsigned long gap = 1000000UL / hz, start = millis();
61
95
  while (digitalRead(LIMIT[axis]) == HIGH) {
62
96
  if (millis() - start > 60000UL) return false;
63
- pulse(axis); delayMicroseconds(gap);
97
+ pulse(STEP_MASK[axis]); delayMicroseconds(gap);
64
98
  }
65
99
  digitalWrite(DIR[axis], dir > 0 ? LOW : HIGH);
66
- for (long i = 0; i < back; i++) { pulse(axis); delayMicroseconds(gap); }
100
+ for (long i = 0; i < back; i++) { pulse(STEP_MASK[axis]); delayMicroseconds(gap); }
67
101
  position[axis] = 0;
68
102
  return true;
69
103
  }
70
104
 
71
- // Reads longs from a line, space separated
72
- const char *cursor;
73
- long nextLong() { char *end; long v = strtol(cursor, &end, 10); cursor = end; return v; }
105
+ // One character of a line: the first is the command, then numbers separated by spaces, a minus sign before a negative one
106
+ void endNumber() { if (inNumber) { if (negative) arg[nargs] = -arg[nargs]; nargs++; inNumber = false; } }
107
+ void take(char c) {
108
+ if (!len++) { cmd = c; nargs = 0; inNumber = false; bad = false; return; }
109
+ if (len > LINE_MAX) { bad = true; return; }
110
+ if (c == ' ') { endNumber(); return; }
111
+ if (!inNumber) {
112
+ if (nargs >= ARGS) { bad = true; return; }
113
+ inNumber = true; negative = c == '-'; arg[nargs] = 0;
114
+ if (negative) return;
115
+ }
116
+ if (c < '0' || c > '9') { bad = true; return; }
117
+ arg[nargs] = arg[nargs] * 10 + (c - '0');
118
+ }
119
+ long a(uint8_t i) { return i < nargs ? arg[i] : 0; } // a number missing from the end of a line is 0
74
120
 
75
121
  // True if the line was dealt with; false if it has to wait for room in the queue
76
122
  bool obey() {
77
- char c = line[0];
78
- cursor = line + 1;
123
+ char c = cmd;
124
+ if (bad) { Serial.println(F("error: line")); return true; }
79
125
  if (c == 'e') { digitalWrite(ENABLE_PIN, LOW); Serial.println(F("ok")); return true; }
80
126
  if (c == 'd') { digitalWrite(ENABLE_PIN, HIGH); Serial.println(F("ok")); return true; }
81
- if (c == '!') { head = tail = 0; running = false; waiting = false; Serial.println(F("ok")); return true; }
127
+ if (c == '!') { head = tail = 0; running = false; waiting = false; chained = false; Serial.println(F("ok")); return true; }
82
128
  if (c == '?') { Serial.print(F("q ")); for (uint8_t i = 0; i < 3; i++) { Serial.print(position[i]); Serial.print(' '); } Serial.println(count()); return true; }
83
129
  if (c == 'h') {
84
130
  if (running || count()) return false; // home only when everything before it is finished
85
- long axis = nextLong(), dir = nextLong(), hz = nextLong(), back = nextLong();
131
+ long axis = a(0), dir = a(1), hz = a(2), back = a(3);
86
132
  if (axis < 0 || axis > 2 || hz <= 0) { Serial.println(F("error: home")); return true; }
87
133
  Serial.println(home(axis, dir, hz, back) ? F("ok") : F("error: endstop"));
88
134
  return true;
@@ -92,13 +138,14 @@ bool obey() {
92
138
  Block &b = queue[head];
93
139
  if (c == 'm') {
94
140
  b.kind = MOVE;
95
- for (uint8_t i = 0; i < 3; i++) b.steps[i] = nextLong();
96
- b.entry = nextLong(); b.peak = nextLong(); b.exit_ = nextLong(); b.accel = nextLong(); b.up = nextLong(); b.down = nextLong();
141
+ for (uint8_t i = 0; i < 3; i++) b.steps[i] = a(i);
142
+ b.entry = a(3); b.peak = a(4); b.exit_ = a(5); b.accel = a(6); b.up = a(7); b.down = a(8);
97
143
  b.major = max(max(labs(b.steps[0]), labs(b.steps[1])), labs(b.steps[2]));
98
144
  if (b.major == 0 || b.peak <= 0 || b.accel <= 0) { Serial.println(F("error: block")); return true; }
99
- } else if (c == 'p') { b.kind = PEN; b.major = nextLong(); b.up = nextLong(); }
100
- else { b.kind = WAIT; b.up = nextLong(); }
101
- head = (head + 1) % QUEUE;
145
+ if (b.peak > MAX_RATE || b.entry > MAX_RATE || b.exit_ > MAX_RATE) { Serial.println(F("error: rate")); return true; }
146
+ } else if (c == 'p') { b.kind = PEN; b.major = a(0); b.up = a(1); }
147
+ else { b.kind = WAIT; b.up = a(0); }
148
+ if (++head == QUEUE) head = 0;
102
149
  Serial.println(F("ok"));
103
150
  return true;
104
151
  }
@@ -109,41 +156,60 @@ void readSerial() {
109
156
  char c = Serial.read();
110
157
  if (c == '\n' || c == '\r') {
111
158
  if (!len) continue;
112
- line[len] = 0; len = 0;
159
+ endNumber(); len = 0;
113
160
  if (!obey()) pending = true;
114
161
  return;
115
162
  }
116
- if (len < sizeof(line) - 1) line[len++] = c;
163
+ take(c);
117
164
  }
118
165
  }
119
166
 
120
167
  void start() {
121
168
  cur = queue[tail];
122
- tail = (tail + 1) % QUEUE;
169
+ if (++tail == QUEUE) tail = 0;
170
+ if (cur.kind != MOVE) chained = false;
123
171
  if (cur.kind == PEN) { pen.write(cur.major); waitUntil = millis() + cur.up; waiting = true; return; }
124
172
  if (cur.kind == WAIT) { waitUntil = millis() + cur.up; waiting = true; return; }
125
- for (uint8_t i = 0; i < 3; i++) { digitalWrite(DIR[i], cur.steps[i] < 0 ? LOW : HIGH); acc[i] = cur.major / 2; }
126
- rate = max(cur.entry, MIN_RATE);
127
- done = 0; running = true; nextAt = micros();
173
+ // the direction pins in one write, and each axis's Bresenham count from half the block (a shift: a long division here
174
+ // cost about 600 cycles an axis between one block's last step and the next block's first)
175
+ uint8_t dirs = 0;
176
+ for (uint8_t i = 0; i < 3; i++) { if (cur.steps[i] >= 0) dirs |= DIR_MASK[i]; acc[i] = cur.major >> 1; }
177
+ PORTD = (PORTD & ~(DIR_MASK[0] | DIR_MASK[1] | DIR_MASK[2])) | dirs;
178
+ rate = max(cur.entry, MIN_RATE); gap = 1000000.0 / rate;
179
+ accelUs = cur.accel * 1e-6f; peakF = cur.peak; floorF = max(cur.exit_, MIN_RATE); downFrom = cur.major - cur.down; skipped = false;
180
+ done = 0; running = true;
181
+ if (!chained) nextAt = micros(); // from rest, its first step now; following a block, one gap after that block's last
182
+ chained = false;
128
183
  }
129
184
 
130
185
  void tick() {
131
186
  if ((long)(micros() - nextAt) < 0) return;
187
+ uint8_t mask = 0;
132
188
  for (uint8_t i = 0; i < 3; i++) {
133
189
  acc[i] += labs(cur.steps[i]);
134
- if (acc[i] >= cur.major) { acc[i] -= cur.major; pulse(i); position[i] += cur.steps[i] < 0 ? -1 : 1; }
190
+ if (acc[i] >= cur.major) { acc[i] -= cur.major; mask |= STEP_MASK[i]; position[i] += cur.steps[i] < 0 ? -1 : 1; }
135
191
  }
192
+ pulse(mask);
136
193
  done++;
137
- if (done >= cur.major) { running = false; return; }
138
- // Constant acceleration: dv = a dt, dt = 1 / v
139
- if (done < cur.up) { rate += (float)cur.accel / rate; if (rate > cur.peak) rate = cur.peak; }
140
- else if (done >= cur.major - cur.down) { rate -= (float)cur.accel / rate; float floor_ = max(cur.exit_, MIN_RATE); if (rate < floor_) rate = floor_; }
141
- nextAt += (unsigned long)(1000000.0 / rate);
194
+ if (done >= cur.major) { running = false; nextAt += (unsigned long)gap; chained = true; return; }
195
+ // Constant acceleration: dv = a dt, dt this step's gap (1 / v), or two gaps when the last step left its change to this one
196
+ // (the gap is the same for both: it changes only here). The last step speeding up always changes, so the cruise is at peak.
197
+ bool up = done < cur.up;
198
+ if (up || done >= downFrom) {
199
+ if (gap >= FINE_GAP || skipped || done + 1 == cur.up) {
200
+ float dv = accelUs * (skipped ? gap + gap : gap);
201
+ skipped = false;
202
+ if (up) { rate += dv; if (rate > peakF) rate = peakF; }
203
+ else { rate -= dv; if (rate < floorF) rate = floorF; }
204
+ gap = 1000000.0 / rate;
205
+ } else skipped = true;
206
+ }
207
+ nextAt += (unsigned long)gap;
142
208
  }
143
209
 
144
210
  void loop() {
145
211
  readSerial();
146
212
  if (waiting) { if ((long)(millis() - waitUntil) >= 0) waiting = false; return; }
147
213
  if (running) { tick(); return; }
148
- if (count()) start();
214
+ if (count()) start(); else chained = false; // the queue ran dry: the motors stopped, and the next block starts from rest
149
215
  }
@@ -1,12 +1,38 @@
1
1
  #!/usr/bin/env node
2
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.
3
3
  // node send.mjs <file.steps.json> --port /dev/tty.usbmodem101 [--machine arm.machine.json] [--no-home]
4
- // node send.mjs <file.steps.json> --dry-run says what it would send, and checks it against the protocol
4
+ // node send.mjs <file.steps.json> --dry-run [--machine arm.machine.json] [--quiet]
5
+ // echoes each line it would send with the answer the streamer would give,
6
+ // checked against the protocol, the streamer's MAX_RATE and the machine's rates
7
+ // The protocol is written up in STREAMER.md, beside this file.
5
8
  // No dependencies: a serial port is a file, set up with stty.
6
9
  import fs from 'node:fs';
7
10
  import { spawnSync } from 'node:child_process';
8
11
  import { fileURLToPath } from 'node:url';
9
12
 
13
+ /** The fastest block the streamer takes, steps/s on its major axis: arm.ino's RATE_LIMIT (a test holds the two equal). */
14
+ export const MAX_RATE = 8000;
15
+
16
+ /** The serial line's time for one byte, s: 115200 baud, 10 bits a byte (a start bit, 8 data bits, a stop bit). */
17
+ export const BYTE_TIME = 10 / 115200;
18
+ /** The bytes of the streamer's answer to a block: "ok", then CR and LF (Serial.println). */
19
+ export const ANSWER_BYTES = 4;
20
+ /** The time a line and its answer wait in the USB link, past their own bytes on the wire, s: an estimate. The Uno's
21
+ * USB chip (an ATmega16U2 running Arduino-usbserial) passes the streamer's answer on to the computer when its timer 0
22
+ * overflows, every 256 x 256 / 16 MHz = 4.1 ms (Arduino-usbserial.c in ArduinoCore-avr, "TCCR0B = (1 << CS02)" and the
23
+ * TOV0 flush, read 2026-11-23), and the computer sends the next line in a USB frame, every 1 ms at full speed. A board
24
+ * with another USB chip (a CH340 on many copies) differs: the bench test times it. */
25
+ export const TURNAROUND = 0.0051;
26
+
27
+ /** The least time a block must last for the streamer to keep up, s: its line's bytes and newline, then the answer, on the
28
+ * wire, and the turnaround. The sender sends a line only after the last was answered, so a run of shorter blocks empties
29
+ * the queue and the motors stop between blocks. On a simulated Uno the streamer answers a line as soon as its last byte
30
+ * is in (it parses each character as it arrives), so the line and its answer are the whole of its cost there.
31
+ * @param {string} line @param {{ turnaround?: number }} [o] turnaround 0 for a board with no USB link (the simulation) */
32
+ export function leastBlockTime(line, { turnaround = TURNAROUND } = {}) {
33
+ return (line.length + 1 + ANSWER_BYTES) * BYTE_TIME + turnaround;
34
+ }
35
+
10
36
  /** One step file as the protocol's lines, in order. @param {object} file @param {{ pen?: { up: number, down: number }, axes?: number }} [o] */
11
37
  export function linesOf(file, { pen = { up: 90, down: 30 }, axes = 3 } = {}) {
12
38
  if (file?.format !== 'rulecad.steps/1') throw new Error(`not a step file (format is ${JSON.stringify(file?.format)}, wanted rulecad.steps/1)`);
@@ -28,19 +54,44 @@ export function homeLines(machine) {
28
54
  return machine.axes.flatMap((a, i) => (a.homing ? [`h ${i} ${a.homing.direction} ${a.homing.rate} ${a.homing.back}`] : []));
29
55
  }
30
56
 
31
- // What the firmware would say to a line, so the protocol can be tested with no board
32
- export function dryRun(lines) {
33
- const seen = { m: 0, p: 0, w: 0, h: 0, e: 0, d: 0 };
57
+ /** What the streamer would answer to each line, so the protocol can be tested with no board. Throws at the first line it
58
+ * would refuse, naming it, and at a block too short for the streamer to keep up with (leastBlockTime). With a machine
59
+ * (cad machine's description), each axis's share of a block's rate is held to that axis's maxRate too. A dry run has no clock, so it takes each block as finished before the next line: `?` answers the
60
+ * positions summed from the blocks so far (a home sets its axis to 0) with 0 blocks queued, and `!` answers `ok`.
61
+ * @param {string[]} lines @param {{ machine?: object, turnaround?: number }} [o] turnaround as leastBlockTime takes it
62
+ * @returns {{ lines: number, m: number, p: number, w: number, h: number, e: number, d: number, '?': number, '!': number, peakRate: number, axisPeaks: number[], position: number[], said: string[] }} */
63
+ export function dryRun(lines, { machine, turnaround = TURNAROUND } = {}) {
64
+ const seen = { m: 0, p: 0, w: 0, h: 0, e: 0, d: 0, '?': 0, '!': 0 }, axisPeaks = [0, 0, 0], position = [0, 0, 0], said = [];
34
65
  let peak = 0;
35
66
  for (const [i, l] of lines.entries()) {
36
67
  const [c, ...args] = l.split(' '), n = args.map(Number), at = `line ${i + 1} ("${l}")`;
37
68
  if (l.length > 95) throw new Error(`${at}: longer than the streamer's 95 characters`);
38
- if (!(c in seen)) throw new Error(`${at}: no such command`);
69
+ if (!(c in seen)) throw new Error(`${at}: no such command (the streamer takes e, d, h, p, w, m, ? and !)`);
39
70
  if (n.some((x) => !Number.isInteger(x))) throw new Error(`${at}: its numbers are whole`);
40
- if (c === 'm') { if (n.length !== 9) throw new Error(`${at}: a block is 9 numbers`); if (!n.slice(0, 3).some(Boolean)) throw new Error(`${at}: a block that moves nothing`); if (n[4] > 8000) throw new Error(`${at}: ${n[4]} steps/s is past the streamer's 8000`); peak = Math.max(peak, n[4]); }
71
+ if (c === 'h' && (n.length !== 4 || n[0] < 0 || n[0] > 2 || n[2] <= 0)) throw new Error(`${at}: a home is an axis 0, 1 or 2, a direction, a rate over 0 and the steps back`);
72
+ if (c === 'm') {
73
+ if (n.length !== 9) throw new Error(`${at}: a block is 9 numbers`);
74
+ const major = Math.max(...n.slice(0, 3).map(Math.abs));
75
+ if (!major) throw new Error(`${at}: a block that moves nothing`);
76
+ if (n[4] <= 0 || n[6] <= 0) throw new Error(`${at}: a block's peak rate and acceleration are over 0`);
77
+ const fastest = Math.max(n[3], n[4], n[5]);
78
+ if (fastest > MAX_RATE) throw new Error(`${at}: ${fastest} steps/s is past the streamer's MAX_RATE of ${MAX_RATE} (it would answer "error: rate")`);
79
+ for (const k of [0, 1, 2]) {
80
+ const r = (fastest * Math.abs(n[k])) / major, axis = machine?.axes?.[k];
81
+ axisPeaks[k] = Math.max(axisPeaks[k], r);
82
+ if (axis?.maxRate && r > axis.maxRate * (1 + 1e-6) + 0.5) throw new Error(`${at}: axis ${axis.name ?? k} at ${Math.round(r)} steps/s, past the machine's ${axis.maxRate} for it`);
83
+ }
84
+ // the block is over in major / fastest seconds at the soonest
85
+ const least = leastBlockTime(l, { turnaround });
86
+ if (major / fastest < least) throw new Error(`${at}: ${major} steps at up to ${fastest} steps/s can be over in ${(major / fastest * 1000).toFixed(2)} ms, and the streamer needs ${(least * 1000).toFixed(2)} ms for each block's line and answer: it would fall behind and stop between blocks (plan with a least block time, task.blockTime for cad plot, or a lower speed)`);
87
+ peak = Math.max(peak, fastest);
88
+ for (const k of [0, 1, 2]) position[k] += n[k];
89
+ }
90
+ if (c === 'h') position[n[0]] = 0;
41
91
  seen[c]++;
92
+ said.push(`${l} ${c === '?' ? `q ${position.join(' ')} 0` : 'ok'}`);
42
93
  }
43
- return { lines: lines.length, ...seen, peakRate: peak };
94
+ return { lines: lines.length, ...seen, peakRate: peak, axisPeaks, position, said };
44
95
  }
45
96
 
46
97
  async function send(port, lines, say) {
@@ -64,7 +115,14 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
64
115
  if (!fileName) { console.error('usage: node send.mjs <file.steps.json> --port <device> [--machine <file>] [--no-home] | --dry-run'); process.exit(2); }
65
116
  const file = JSON.parse(fs.readFileSync(fileName, 'utf8')), machine = opt('machine') ? JSON.parse(fs.readFileSync(opt('machine'), 'utf8')) : null;
66
117
  const lines = ['e', ...(machine && !has('no-home') ? homeLines(machine) : []), ...linesOf(file, machine?.pen ? { pen: machine.pen } : {}), 'd'];
67
- if (has('dry-run')) { const r = dryRun(lines); console.log(`dry run: ${r.lines} lines, ${r.m} blocks, ${r.p} pen moves, ${r.h} homes, peak ${r.peakRate} steps/s`); process.exit(0); }
118
+ // the whole file is checked before anything moves: a block refused halfway through a drawing would spoil it
119
+ let r;
120
+ try { r = dryRun(lines, { machine }); } catch (e) { console.error(`${has('dry-run') ? 'dry run' : 'not sent'}: ${e.message}`); process.exit(1); }
121
+ if (has('dry-run')) {
122
+ 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` : ''}`);
124
+ process.exit(0);
125
+ }
68
126
  if (!opt('port')) { console.error('--port <device>, or --dry-run'); process.exit(2); }
69
127
  send(opt('port'), lines, console.log).then(() => console.log('done')).catch((e) => { console.error(e.message); process.exit(1); });
70
128
  }
@@ -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.21",
3
+ "version": "0.3.23",
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": {