@rulecad/cad 0.7.89 → 0.7.92

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,46 @@ 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
+
9
+ ## 0.7.92: eight axes on a Mega 2560 (#199)
10
+ - The wiring sheet names a Mega slot's pins as step, dir and enable (D38, every slot's): the wire to a driver breakout carries EN, STEP, DIR and GND, and the axis's home switch is a wire of its own. A CNC shield's axis still names its limit pin.
11
+ - The quadruped carries a 12 V supply (a Mean Well LRS-100-12 to buy: about 6 A for eight motors, an estimate) and a power wire to each breakout.
12
+ ### Added
13
+
14
+ - `cad machine` writes the machine's `controller`: the bought board the streamer runs on, a CNC Shield V3 (an Uno,
15
+ three axes, slots X, Y, Z) or an `arduino-mega-2560` (eight axes, slots S0 to S7), with the Uno where the assembly
16
+ names none. A motor's slot is read from its wire to the board, or, for a driver on its own breakout, from the motor's
17
+ wire to the breakout and the breakout's signal wire on to the slot. Two different controllers are refused by name.
18
+ - `cad plot` on a gait holds the axes to the controller's slots: the quadruped's eight stream through the Mega, and an
19
+ Uno still warns `stream.axes` past three, naming the Mega as the way to more.
20
+ - The wiring sheet names a Mega slot's pins as it does a shield's.
21
+
22
+ ### Changed
23
+
24
+ - The bench quadruped and crawl carry a Mega 2560, a DRV8825 on a driver breakout for each motor and sixteen wires
25
+ (each motor to its breakout, each breakout's EN, STEP, DIR and GND to the Mega); each motor names its driver, so the
26
+ check says each trimmer's setting. The boards sit over the body as references; no printed size moved. EXAMPLES
27
+ chapter 14 says how the eight axes are wired, and `leg.robot_mass`'s rule names the Mega (its 4.2 kg is unchanged).
28
+
29
+ ## 0.7.91: problems at an assembly's joints, avoid regions from a sweep
30
+ ### Added
31
+
32
+ - Optimisation problems placed in an assembly (#28): `"in": { "assembly", "item", "pose", "z" }` puts a problem in
33
+ an item's frame. A region, support or load can sit at one of the assembly's joints (`"joint": "hinge"`, read as an
34
+ anchor is), and an `avoid` region can be a part swept through a joint's range (`{ "sweep": "gate", "through":
35
+ "swing", "steps" }`), each step kept clear; in a flat problem, all of the part within the plate's thickness (its
36
+ sections up the plate, half a cell apart and closer where a face leans, so a part dipping into the plate's top or
37
+ bottom is kept clear too), holes open. Steps by default so no point moves more than half a cell between two. Changing the assembly reruns the
38
+ optimisation. `cad why` names the assembly, the joints read and each sweep's range and steps. Schema first:
39
+ `problem.schema.json` gains `in`, `joint`, `sweep`, `through` and `steps`. Refused by name: a sweep outside avoid,
40
+ of the item itself or through a joint that doesn't move it against the item; a part that never reaches into a flat
41
+ plate's thickness; a joint or item the assembly has not got; more than 360 default steps.
42
+
43
+ ### Printed sizes that moved
44
+
45
+ - None. Problems without `in` read as before (each result is drawn again once, since this file's code is in the
46
+ drawing's key; no densities key moves).
47
+
8
48
  ## 0.7.89: fewer triangles by default
9
49
  ### Changed
10
50
 
package/EXAMPLES.md CHANGED
@@ -4410,7 +4410,7 @@ The stack of the same gearbox with the motor's face as zero, what the leg stands
4410
4410
  "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"},
4411
4411
  "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"},
4412
4412
  "side_t": {"value": 6, "unit": "mm", "rule": "The side plate's thickness", "kind": "default", "source": "EXAMPLES chapter 14", "checked": "2026-11-09"},
4413
- "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"},
4413
+ "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 electronics (a Mega 2560, eight DRV8825s on their breakouts, none weighed), 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"},
4414
4414
  "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"}
4415
4415
  }
4416
4416
  }
@@ -5453,6 +5453,8 @@ export function main (v) {
5453
5453
 
5454
5454
  The quadruped carries the leg's parts, every one, as items of a single assembly. That costs length, because each leg's gearbox is written out; it is what lets the gait below move every joint, with every planet turning, and lets the sweep look for leg against leg. Two gaits, one file each: a trot and a crawl, the same machine. The hip motors live between the two plates, with the beams between them.
5455
5455
 
5456
+ Eight motors are more than the stand's Uno under a CNC shield can step: its streamer has three axes. The quadruped carries one Arduino Mega 2560 (`mega`, the `arduino-mega-2560` rule set), which runs the same streamer built for eight axes, and a DRV8825 for each motor on its own driver breakout (`driver-breakout`): each motor's wire goes to its breakout, and each breakout's EN, STEP, DIR and GND go on to one of the Mega's slots, `S0` to `S7`. One board keeps every leg's steps in the same blocks, which two boards kept in step could not promise. The boards sit over the body, clear of the hip motors, as references for the shopping list and the wire lengths; a deck to hold them is not designed yet. `cad machine leg/quadruped` lists each axis with its slot, and `cad plot leg/quadruped` writes the trot as a step file that the sender, `projects/leg/send.mjs`, streams to the Mega (`projects/leg/STREAMER.md` says how).
5457
+
5456
5458
  ```json projects/leg/assemblies/quadruped.json
5457
5459
  {
5458
5460
  "$schema": "https://jonibach.github.io/rulecad/schemas/assembly.schema.json",
@@ -5465,7 +5467,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5465
5467
  {"id": "right", "object": "side", "at": [0, "0 - leg.body_w",0], "rotate": [90,0,180]},
5466
5468
  {"id": "beam1", "object": "beam", "at": ["left.beam_at",0,-6], "rotate": [0,0,90]},
5467
5469
  {"id": "beam2", "object": "beam", "at": ["0 - left.beam_at",0,-6], "rotate": [0,0,90]},
5468
- {"id": "fl_m1", "motor": {"model": "17HS4401", "drives": "fl_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5470
+ {"id": "fl_m1", "motor": {"model": "17HS4401", "drives": "fl_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "fl_d1"}},
5469
5471
  {"id": "fl_housing", "object": "housing", "at": ["leg.body_half", "leg.body_w",0], "rotate": [-90,0,0]},
5470
5472
  {"id": "fl_sun", "object": "sun"},
5471
5473
  {"id": "fl_carrier", "object": "speck"},
@@ -5477,7 +5479,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5477
5479
  {"id": "fl_bridge", "object": "bridge"},
5478
5480
  {"id": "fl_b1", "bought": "bearing-6800"},
5479
5481
  {"id": "fl_thigh", "object": "thigh"},
5480
- {"id": "fl_m2", "motor": {"model": "17HS4401", "drives": "fl_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5482
+ {"id": "fl_m2", "motor": {"model": "17HS4401", "drives": "fl_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "fl_d2"}},
5481
5483
  {"id": "fl_esun", "object": "sun", "set": {"tip": 11.7}},
5482
5484
  {"id": "fl_ecarrier", "object": "speck"},
5483
5485
  {"id": "fl_ering", "object": "speck"},
@@ -5490,7 +5492,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5490
5492
  {"id": "fl_clip3", "object": "clip"},
5491
5493
  {"id": "fl_shin", "object": "shin"},
5492
5494
  {"id": "fl_pad", "object": "pad"},
5493
- {"id": "fr_m1", "motor": {"model": "17HS4401", "drives": "fr_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5495
+ {"id": "fr_m1", "motor": {"model": "17HS4401", "drives": "fr_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "fr_d1"}},
5494
5496
  {"id": "fr_housing", "object": "housing", "at": ["leg.body_half", "0 - leg.body_w",0], "rotate": [-90,0,180]},
5495
5497
  {"id": "fr_sun", "object": "sun"},
5496
5498
  {"id": "fr_carrier", "object": "speck"},
@@ -5502,7 +5504,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5502
5504
  {"id": "fr_bridge", "object": "bridge"},
5503
5505
  {"id": "fr_b1", "bought": "bearing-6800"},
5504
5506
  {"id": "fr_thigh", "object": "thigh"},
5505
- {"id": "fr_m2", "motor": {"model": "17HS4401", "drives": "fr_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5507
+ {"id": "fr_m2", "motor": {"model": "17HS4401", "drives": "fr_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "fr_d2"}},
5506
5508
  {"id": "fr_esun", "object": "sun", "set": {"tip": 11.7}},
5507
5509
  {"id": "fr_ecarrier", "object": "speck"},
5508
5510
  {"id": "fr_ering", "object": "speck"},
@@ -5515,7 +5517,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5515
5517
  {"id": "fr_clip3", "object": "clip"},
5516
5518
  {"id": "fr_shin", "object": "shin"},
5517
5519
  {"id": "fr_pad", "object": "pad"},
5518
- {"id": "bl_m1", "motor": {"model": "17HS4401", "drives": "bl_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5520
+ {"id": "bl_m1", "motor": {"model": "17HS4401", "drives": "bl_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "bl_d1"}},
5519
5521
  {"id": "bl_housing", "object": "housing", "at": ["0 - leg.body_half", "leg.body_w",0], "rotate": [-90,0,0]},
5520
5522
  {"id": "bl_sun", "object": "sun"},
5521
5523
  {"id": "bl_carrier", "object": "speck"},
@@ -5527,7 +5529,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5527
5529
  {"id": "bl_bridge", "object": "bridge"},
5528
5530
  {"id": "bl_b1", "bought": "bearing-6800"},
5529
5531
  {"id": "bl_thigh", "object": "thigh"},
5530
- {"id": "bl_m2", "motor": {"model": "17HS4401", "drives": "bl_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5532
+ {"id": "bl_m2", "motor": {"model": "17HS4401", "drives": "bl_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "bl_d2"}},
5531
5533
  {"id": "bl_esun", "object": "sun", "set": {"tip": 11.7}},
5532
5534
  {"id": "bl_ecarrier", "object": "speck"},
5533
5535
  {"id": "bl_ering", "object": "speck"},
@@ -5540,7 +5542,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5540
5542
  {"id": "bl_clip3", "object": "clip"},
5541
5543
  {"id": "bl_shin", "object": "shin"},
5542
5544
  {"id": "bl_pad", "object": "pad"},
5543
- {"id": "br_m1", "motor": {"model": "17HS4401", "drives": "br_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5545
+ {"id": "br_m1", "motor": {"model": "17HS4401", "drives": "br_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "br_d1"}},
5544
5546
  {"id": "br_housing", "object": "housing", "at": ["0 - leg.body_half", "0 - leg.body_w",0], "rotate": [-90,0,180]},
5545
5547
  {"id": "br_sun", "object": "sun"},
5546
5548
  {"id": "br_carrier", "object": "speck"},
@@ -5552,7 +5554,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5552
5554
  {"id": "br_bridge", "object": "bridge"},
5553
5555
  {"id": "br_b1", "bought": "bearing-6800"},
5554
5556
  {"id": "br_thigh", "object": "thigh"},
5555
- {"id": "br_m2", "motor": {"model": "17HS4401", "drives": "br_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5557
+ {"id": "br_m2", "motor": {"model": "17HS4401", "drives": "br_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "br_d2"}},
5556
5558
  {"id": "br_esun", "object": "sun", "set": {"tip": 11.7}},
5557
5559
  {"id": "br_ecarrier", "object": "speck"},
5558
5560
  {"id": "br_ering", "object": "speck"},
@@ -5564,7 +5566,25 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5564
5566
  {"id": "br_clip2", "object": "clip"},
5565
5567
  {"id": "br_clip3", "object": "clip"},
5566
5568
  {"id": "br_shin", "object": "shin"},
5567
- {"id": "br_pad", "object": "pad"}
5569
+ {"id": "br_pad", "object": "pad"},
5570
+ {"id": "mega", "bought": "arduino-mega-2560", "at": [0, 0, 20]},
5571
+ {"id": "psu", "bought": "supply-12v", "at": [0, 150, 20]},
5572
+ {"id": "fl_board1", "bought": "driver-breakout", "at": [69, 19.5, 48]},
5573
+ {"id": "fl_d1", "bought": "drv8825", "at": [69, 19.5, 58.1]},
5574
+ {"id": "fl_board2", "bought": "driver-breakout", "at": [23, 19.5, 48]},
5575
+ {"id": "fl_d2", "bought": "drv8825", "at": [23, 19.5, 58.1]},
5576
+ {"id": "fr_board1", "bought": "driver-breakout", "at": [69, -19.5, 48]},
5577
+ {"id": "fr_d1", "bought": "drv8825", "at": [69, -19.5, 58.1]},
5578
+ {"id": "fr_board2", "bought": "driver-breakout", "at": [23, -19.5, 48]},
5579
+ {"id": "fr_d2", "bought": "drv8825", "at": [23, -19.5, 58.1]},
5580
+ {"id": "bl_board1", "bought": "driver-breakout", "at": [-69, 19.5, 48]},
5581
+ {"id": "bl_d1", "bought": "drv8825", "at": [-69, 19.5, 58.1]},
5582
+ {"id": "bl_board2", "bought": "driver-breakout", "at": [-23, 19.5, 48]},
5583
+ {"id": "bl_d2", "bought": "drv8825", "at": [-23, 19.5, 58.1]},
5584
+ {"id": "br_board1", "bought": "driver-breakout", "at": [-69, -19.5, 48]},
5585
+ {"id": "br_d1", "bought": "drv8825", "at": [-69, -19.5, 58.1]},
5586
+ {"id": "br_board2", "bought": "driver-breakout", "at": [-23, -19.5, 48]},
5587
+ {"id": "br_d2", "bought": "drv8825", "at": [-23, -19.5, 58.1]}
5568
5588
  ],
5569
5589
  "joints": [
5570
5590
  {"id": "fl_m1_on", "type": "fixed", "parent": "fl_housing.motor", "child": "fl_m1.face"},
@@ -5754,6 +5774,32 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5754
5774
  {"a": "br_ecarrier", "b": "br_ering", "min": -1},
5755
5775
  {"a": "br_pad", "b": "br_shin", "min": -2}
5756
5776
  ],
5777
+ "wires": [
5778
+ {"id": "fl_hd_motor", "from": "fl_m1.connector", "to": "fl_board1.top", "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
5779
+ {"id": "fl_hd_signal", "from": "fl_board1.centre", "to": "mega.S0", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 0"},
5780
+ {"id": "fl_kd_motor", "from": "fl_m2.connector", "to": "fl_board2.top", "via": ["fl_thigh.cable"], "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
5781
+ {"id": "fl_kd_signal", "from": "fl_board2.centre", "to": "mega.S1", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 1"},
5782
+ {"id": "fr_hd_motor", "from": "fr_m1.connector", "to": "fr_board1.top", "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
5783
+ {"id": "fr_hd_signal", "from": "fr_board1.centre", "to": "mega.S2", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 2"},
5784
+ {"id": "fr_kd_motor", "from": "fr_m2.connector", "to": "fr_board2.top", "via": ["fr_thigh.cable"], "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
5785
+ {"id": "fr_kd_signal", "from": "fr_board2.centre", "to": "mega.S3", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 3"},
5786
+ {"id": "bl_hd_motor", "from": "bl_m1.connector", "to": "bl_board1.top", "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
5787
+ {"id": "bl_hd_signal", "from": "bl_board1.centre", "to": "mega.S4", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 4"},
5788
+ {"id": "bl_kd_motor", "from": "bl_m2.connector", "to": "bl_board2.top", "via": ["bl_thigh.cable"], "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
5789
+ {"id": "bl_kd_signal", "from": "bl_board2.centre", "to": "mega.S5", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 5"},
5790
+ {"id": "br_hd_motor", "from": "br_m1.connector", "to": "br_board1.top", "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
5791
+ {"id": "br_hd_signal", "from": "br_board1.centre", "to": "mega.S6", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 6"},
5792
+ {"id": "br_kd_motor", "from": "br_m2.connector", "to": "br_board2.top", "via": ["br_thigh.cable"], "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
5793
+ {"id": "br_kd_signal", "from": "br_board2.centre", "to": "mega.S7", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 7"},
5794
+ {"id": "fl_board1_power", "from": "psu.terminals", "to": "fl_board1.bottom", "gauge": "awg22", "colour": "red, black", "conductors": 2, "current": 2, "connectors": ["Ring terminal", "Screw terminal"], "note": "12 V into the breakout's motor supply terminals (VMOT and GND), with its 100 uF capacitor across them"},
5795
+ {"id": "fl_board2_power", "from": "psu.terminals", "to": "fl_board2.bottom", "gauge": "awg22", "colour": "red, black", "conductors": 2, "current": 2, "connectors": ["Ring terminal", "Screw terminal"], "note": "12 V into the breakout's motor supply terminals (VMOT and GND), with its 100 uF capacitor across them"},
5796
+ {"id": "fr_board1_power", "from": "psu.terminals", "to": "fr_board1.bottom", "gauge": "awg22", "colour": "red, black", "conductors": 2, "current": 2, "connectors": ["Ring terminal", "Screw terminal"], "note": "12 V into the breakout's motor supply terminals (VMOT and GND), with its 100 uF capacitor across them"},
5797
+ {"id": "fr_board2_power", "from": "psu.terminals", "to": "fr_board2.bottom", "gauge": "awg22", "colour": "red, black", "conductors": 2, "current": 2, "connectors": ["Ring terminal", "Screw terminal"], "note": "12 V into the breakout's motor supply terminals (VMOT and GND), with its 100 uF capacitor across them"},
5798
+ {"id": "bl_board1_power", "from": "psu.terminals", "to": "bl_board1.bottom", "gauge": "awg22", "colour": "red, black", "conductors": 2, "current": 2, "connectors": ["Ring terminal", "Screw terminal"], "note": "12 V into the breakout's motor supply terminals (VMOT and GND), with its 100 uF capacitor across them"},
5799
+ {"id": "bl_board2_power", "from": "psu.terminals", "to": "bl_board2.bottom", "gauge": "awg22", "colour": "red, black", "conductors": 2, "current": 2, "connectors": ["Ring terminal", "Screw terminal"], "note": "12 V into the breakout's motor supply terminals (VMOT and GND), with its 100 uF capacitor across them"},
5800
+ {"id": "br_board1_power", "from": "psu.terminals", "to": "br_board1.bottom", "gauge": "awg22", "colour": "red, black", "conductors": 2, "current": 2, "connectors": ["Ring terminal", "Screw terminal"], "note": "12 V into the breakout's motor supply terminals (VMOT and GND), with its 100 uF capacitor across them"},
5801
+ {"id": "br_board2_power", "from": "psu.terminals", "to": "br_board2.bottom", "gauge": "awg22", "colour": "red, black", "conductors": 2, "current": 2, "connectors": ["Ring terminal", "Screw terminal"], "note": "12 V into the breakout's motor supply terminals (VMOT and GND), with its 100 uF capacitor across them"}
5802
+ ],
5757
5803
  "gait": {"legs": ["fl_shin.tip", "fr_shin.tip", "bl_shin.tip", "br_shin.tip"], "pattern": "trot", "stride": "leg.stride", "lift": "leg.lift", "period": 2, "height": "leg.stance", "mass": "leg.robot_mass", "clearance": 11},
5758
5804
  "poses": { "standing": {"fl_hd": -3171.4, "fl_kd": 2597, "fr_hd": -5587.7, "fr_kd": -2236, "bl_hd": -5587.7, "bl_kd": -2236, "br_hd": -3171.4, "br_kd": 2597} }
5759
5805
  }
@@ -5771,7 +5817,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5771
5817
  {"id": "right", "object": "side", "at": [0, "0 - leg.body_w",0], "rotate": [90,0,180]},
5772
5818
  {"id": "beam1", "object": "beam", "at": ["left.beam_at",0,-6], "rotate": [0,0,90]},
5773
5819
  {"id": "beam2", "object": "beam", "at": ["0 - left.beam_at",0,-6], "rotate": [0,0,90]},
5774
- {"id": "fl_m1", "motor": {"model": "17HS4401", "drives": "fl_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5820
+ {"id": "fl_m1", "motor": {"model": "17HS4401", "drives": "fl_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "fl_d1"}},
5775
5821
  {"id": "fl_housing", "object": "housing", "at": ["leg.body_half", "leg.body_w",0], "rotate": [-90,0,0]},
5776
5822
  {"id": "fl_sun", "object": "sun"},
5777
5823
  {"id": "fl_carrier", "object": "speck"},
@@ -5783,7 +5829,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5783
5829
  {"id": "fl_bridge", "object": "bridge"},
5784
5830
  {"id": "fl_b1", "bought": "bearing-6800"},
5785
5831
  {"id": "fl_thigh", "object": "thigh"},
5786
- {"id": "fl_m2", "motor": {"model": "17HS4401", "drives": "fl_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5832
+ {"id": "fl_m2", "motor": {"model": "17HS4401", "drives": "fl_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "fl_d2"}},
5787
5833
  {"id": "fl_esun", "object": "sun", "set": {"tip": 11.7}},
5788
5834
  {"id": "fl_ecarrier", "object": "speck"},
5789
5835
  {"id": "fl_ering", "object": "speck"},
@@ -5796,7 +5842,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5796
5842
  {"id": "fl_clip3", "object": "clip"},
5797
5843
  {"id": "fl_shin", "object": "shin"},
5798
5844
  {"id": "fl_pad", "object": "pad"},
5799
- {"id": "fr_m1", "motor": {"model": "17HS4401", "drives": "fr_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5845
+ {"id": "fr_m1", "motor": {"model": "17HS4401", "drives": "fr_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "fr_d1"}},
5800
5846
  {"id": "fr_housing", "object": "housing", "at": ["leg.body_half", "0 - leg.body_w",0], "rotate": [-90,0,180]},
5801
5847
  {"id": "fr_sun", "object": "sun"},
5802
5848
  {"id": "fr_carrier", "object": "speck"},
@@ -5808,7 +5854,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5808
5854
  {"id": "fr_bridge", "object": "bridge"},
5809
5855
  {"id": "fr_b1", "bought": "bearing-6800"},
5810
5856
  {"id": "fr_thigh", "object": "thigh"},
5811
- {"id": "fr_m2", "motor": {"model": "17HS4401", "drives": "fr_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5857
+ {"id": "fr_m2", "motor": {"model": "17HS4401", "drives": "fr_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "fr_d2"}},
5812
5858
  {"id": "fr_esun", "object": "sun", "set": {"tip": 11.7}},
5813
5859
  {"id": "fr_ecarrier", "object": "speck"},
5814
5860
  {"id": "fr_ering", "object": "speck"},
@@ -5821,7 +5867,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5821
5867
  {"id": "fr_clip3", "object": "clip"},
5822
5868
  {"id": "fr_shin", "object": "shin"},
5823
5869
  {"id": "fr_pad", "object": "pad"},
5824
- {"id": "bl_m1", "motor": {"model": "17HS4401", "drives": "bl_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5870
+ {"id": "bl_m1", "motor": {"model": "17HS4401", "drives": "bl_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "bl_d1"}},
5825
5871
  {"id": "bl_housing", "object": "housing", "at": ["0 - leg.body_half", "leg.body_w",0], "rotate": [-90,0,0]},
5826
5872
  {"id": "bl_sun", "object": "sun"},
5827
5873
  {"id": "bl_carrier", "object": "speck"},
@@ -5833,7 +5879,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5833
5879
  {"id": "bl_bridge", "object": "bridge"},
5834
5880
  {"id": "bl_b1", "bought": "bearing-6800"},
5835
5881
  {"id": "bl_thigh", "object": "thigh"},
5836
- {"id": "bl_m2", "motor": {"model": "17HS4401", "drives": "bl_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5882
+ {"id": "bl_m2", "motor": {"model": "17HS4401", "drives": "bl_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "bl_d2"}},
5837
5883
  {"id": "bl_esun", "object": "sun", "set": {"tip": 11.7}},
5838
5884
  {"id": "bl_ecarrier", "object": "speck"},
5839
5885
  {"id": "bl_ering", "object": "speck"},
@@ -5846,7 +5892,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5846
5892
  {"id": "bl_clip3", "object": "clip"},
5847
5893
  {"id": "bl_shin", "object": "shin"},
5848
5894
  {"id": "bl_pad", "object": "pad"},
5849
- {"id": "br_m1", "motor": {"model": "17HS4401", "drives": "br_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5895
+ {"id": "br_m1", "motor": {"model": "17HS4401", "drives": "br_hd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "br_d1"}},
5850
5896
  {"id": "br_housing", "object": "housing", "at": ["0 - leg.body_half", "0 - leg.body_w",0], "rotate": [-90,0,180]},
5851
5897
  {"id": "br_sun", "object": "sun"},
5852
5898
  {"id": "br_carrier", "object": "speck"},
@@ -5858,7 +5904,7 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5858
5904
  {"id": "br_bridge", "object": "bridge"},
5859
5905
  {"id": "br_b1", "bought": "bearing-6800"},
5860
5906
  {"id": "br_thigh", "object": "thigh"},
5861
- {"id": "br_m2", "motor": {"model": "17HS4401", "drives": "br_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8}},
5907
+ {"id": "br_m2", "motor": {"model": "17HS4401", "drives": "br_kd", "speed": 200, "duty": 0.3, "current": 1, "microsteps": 8, "driver": "br_d2"}},
5862
5908
  {"id": "br_esun", "object": "sun", "set": {"tip": 11.7}},
5863
5909
  {"id": "br_ecarrier", "object": "speck"},
5864
5910
  {"id": "br_ering", "object": "speck"},
@@ -5870,7 +5916,24 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
5870
5916
  {"id": "br_clip2", "object": "clip"},
5871
5917
  {"id": "br_clip3", "object": "clip"},
5872
5918
  {"id": "br_shin", "object": "shin"},
5873
- {"id": "br_pad", "object": "pad"}
5919
+ {"id": "br_pad", "object": "pad"},
5920
+ {"id": "mega", "bought": "arduino-mega-2560", "at": [0, 0, 20]},
5921
+ {"id": "fl_board1", "bought": "driver-breakout", "at": [69, 19.5, 48]},
5922
+ {"id": "fl_d1", "bought": "drv8825", "at": [69, 19.5, 58.1]},
5923
+ {"id": "fl_board2", "bought": "driver-breakout", "at": [23, 19.5, 48]},
5924
+ {"id": "fl_d2", "bought": "drv8825", "at": [23, 19.5, 58.1]},
5925
+ {"id": "fr_board1", "bought": "driver-breakout", "at": [69, -19.5, 48]},
5926
+ {"id": "fr_d1", "bought": "drv8825", "at": [69, -19.5, 58.1]},
5927
+ {"id": "fr_board2", "bought": "driver-breakout", "at": [23, -19.5, 48]},
5928
+ {"id": "fr_d2", "bought": "drv8825", "at": [23, -19.5, 58.1]},
5929
+ {"id": "bl_board1", "bought": "driver-breakout", "at": [-69, 19.5, 48]},
5930
+ {"id": "bl_d1", "bought": "drv8825", "at": [-69, 19.5, 58.1]},
5931
+ {"id": "bl_board2", "bought": "driver-breakout", "at": [-23, 19.5, 48]},
5932
+ {"id": "bl_d2", "bought": "drv8825", "at": [-23, 19.5, 58.1]},
5933
+ {"id": "br_board1", "bought": "driver-breakout", "at": [-69, -19.5, 48]},
5934
+ {"id": "br_d1", "bought": "drv8825", "at": [-69, -19.5, 58.1]},
5935
+ {"id": "br_board2", "bought": "driver-breakout", "at": [-23, -19.5, 48]},
5936
+ {"id": "br_d2", "bought": "drv8825", "at": [-23, -19.5, 58.1]}
5874
5937
  ],
5875
5938
  "joints": [
5876
5939
  {"id": "fl_m1_on", "type": "fixed", "parent": "fl_housing.motor", "child": "fl_m1.face"},
@@ -6060,6 +6123,24 @@ The quadruped carries the leg's parts, every one, as items of a single assembly.
6060
6123
  {"a": "br_ecarrier", "b": "br_ering", "min": -1},
6061
6124
  {"a": "br_pad", "b": "br_shin", "min": -2}
6062
6125
  ],
6126
+ "wires": [
6127
+ {"id": "fl_hd_motor", "from": "fl_m1.connector", "to": "fl_board1.top", "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
6128
+ {"id": "fl_hd_signal", "from": "fl_board1.centre", "to": "mega.S0", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 0"},
6129
+ {"id": "fl_kd_motor", "from": "fl_m2.connector", "to": "fl_board2.top", "via": ["fl_thigh.cable"], "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
6130
+ {"id": "fl_kd_signal", "from": "fl_board2.centre", "to": "mega.S1", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 1"},
6131
+ {"id": "fr_hd_motor", "from": "fr_m1.connector", "to": "fr_board1.top", "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
6132
+ {"id": "fr_hd_signal", "from": "fr_board1.centre", "to": "mega.S2", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 2"},
6133
+ {"id": "fr_kd_motor", "from": "fr_m2.connector", "to": "fr_board2.top", "via": ["fr_thigh.cable"], "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
6134
+ {"id": "fr_kd_signal", "from": "fr_board2.centre", "to": "mega.S3", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 3"},
6135
+ {"id": "bl_hd_motor", "from": "bl_m1.connector", "to": "bl_board1.top", "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
6136
+ {"id": "bl_hd_signal", "from": "bl_board1.centre", "to": "mega.S4", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 4"},
6137
+ {"id": "bl_kd_motor", "from": "bl_m2.connector", "to": "bl_board2.top", "via": ["bl_thigh.cable"], "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
6138
+ {"id": "bl_kd_signal", "from": "bl_board2.centre", "to": "mega.S5", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 5"},
6139
+ {"id": "br_hd_motor", "from": "br_m1.connector", "to": "br_board1.top", "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
6140
+ {"id": "br_hd_signal", "from": "br_board1.centre", "to": "mega.S6", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 6"},
6141
+ {"id": "br_kd_motor", "from": "br_m2.connector", "to": "br_board2.top", "via": ["br_thigh.cable"], "gauge": "awg24", "colour": "black, red, green, blue", "connectors": ["JST-XH 4 pin", "screw terminal"]},
6142
+ {"id": "br_kd_signal", "from": "br_board2.centre", "to": "mega.S7", "gauge": "awg26", "conductors": 4, "colour": "white, yellow, green, black", "connectors": ["Dupont 4 pin", "Dupont"], "note": "EN, STEP, DIR and GND: the streamer's axis 7"}
6143
+ ],
6063
6144
  "gait": {"legs": ["fl_shin.tip", "fr_shin.tip", "bl_shin.tip", "br_shin.tip"], "pattern": "crawl", "stride": "leg.stride", "lift": "leg.lift", "period": 4, "height": "leg.stance", "mass": "leg.robot_mass", "clearance": 11},
6064
6145
  "poses": { "standing": {"fl_hd": -3171.4, "fl_kd": 2597, "fr_hd": -5587.7, "fr_kd": -2236, "bl_hd": -5587.7, "bl_kd": -2236, "br_hd": -3171.4, "br_kd": 2597} }
6065
6146
  }
@@ -6091,7 +6172,7 @@ Said plainly, because a gait that passes these checks is not a robot that walks:
6091
6172
  - **Feedback.** The motors are open-loop steppers: a stall or a slip goes unnoticed. A real leg needs at least encoders at the joints and a way to feel the ground, and code that uses them.
6092
6173
  - **Measuring.** Nothing here has been printed. The stand exists to change that: run its leg, write what the scale reads into the ledger with `cad measured`, and start again from what it says.
6093
6174
 
6094
- `npm create rulecad --machine leg` starts a project from the leg and its stand. The step file for a gait, for a streamer grown to more axes, is not done yet, and neither is a measured leg.
6175
+ `npm create rulecad --machine leg` starts a project from the leg and its stand, with the streamer and its sender. The trot streams through the streamer on a simulated Mega 2560 in the kit's tests, every step counted; a measured leg is not done yet.
6095
6176
 
6096
6177
 
6097
6178
  ## 15. Fixings: a bracket screwed on
package/README.md CHANGED
@@ -1519,6 +1519,27 @@ with numbers as expressions like an object's (schema: `schemas/problem.schema.js
1519
1519
  it, as an assembly reads it). The problem then follows the design: move the plate's
1520
1520
  pivot and the support, the boss round it and the result move with it. A design built from this problem can't be
1521
1521
  named (it would need the result to be built): name the part it is fixed to.
1522
+ - **In an assembly:** `"in": { "assembly": "bench", "item": "plate" }` places the problem in an assembly of the
1523
+ project. Its coordinates are then the item's own, as that item's design draws the result, and two more kinds of
1524
+ region open up:
1525
+ - `"joint": "hinge"` in place of `at`, on any region, support or load: where the joint is, read the way an anchor
1526
+ is. When the item is one end of the joint, it is the item's own anchor for it, the same in every pose; otherwise
1527
+ it is where the joint's parent anchor stands in the pose.
1528
+ - `{ "sweep": "gate", "through": "swing" }` under `avoid`: an item (or `item.part`) moved through a joint's range,
1529
+ the other joints held at the pose, kept clear at every step. By default there are enough steps that no point of
1530
+ the part moves more than half a cell between two; `"steps"` sets them. A flat problem keeps clear of all of the
1531
+ part that lies within the plate's thickness about its middle plane (`in.z`, by default half the thickness, a plate
1532
+ drawn up from z 0): an arm dipping 1 mm into the plate's top is kept clear as surely as one through it. Its
1533
+ sections are taken up the plate no more than half a cell apart, and closer where a face leans, so together they
1534
+ cover it to half a cell; each distinct one is a region. A part passing over or under the plate, or only touching
1535
+ its face, is no obstacle; holes in a section stay open, and the design cuts each exactly.
1536
+ The assembly is read in its pose (`in.pose`, default the one it shows). While it is read, the item itself, and any
1537
+ other built from this problem, is drawn without a result (its problem variables set to `none`), so its design must
1538
+ draw something for `none`: a blank of the space will do. Change the assembly (a joint's range, a part's size) and
1539
+ the problem follows it, so the result is optimised again. `cad check <project>/<assembly> --sweep` then shows the
1540
+ part built from the result is clear through the swing. Refused by name: a sweep outside `avoid`, a sweep of the
1541
+ item itself, a joint that doesn't move the part against the item, a part that never reaches into a flat plate's thickness,
1542
+ and more than 360 default steps (give `steps`, or larger cells).
1522
1543
  - **Or a stress limit instead of a volume:** `"stress": "pla.strength / 3"` (MPa) finds the lightest layout that keeps
1523
1544
  every cell's von Mises stress under it, which rounds off the sharp inside corners where cracks start. It takes about
1524
1545
  a thousand steps, each with two solves, so it's slower: give it a coarse cell first. Give supports and loads some
@@ -1530,7 +1551,7 @@ with numbers as expressions like an object's (schema: `schemas/problem.schema.js
1530
1551
  `cad optimise <project>/<problem>` runs it, reports how far each load case moves its load and the stiffness that
1531
1552
  gives, and draws the layout in `.preview/`. The result is kept, keyed by everything it's made from, so it's only
1532
1553
  worked out again when something it depends on changes. `cad why <project>/<object>.<problem variable>` names what
1533
- that is: the problem file, its rule sets and values, the parts and anchors it reads, where its filter came from, and
1554
+ that is: the problem file, its rule sets and values, the parts and anchors it reads (and the assembly, joints and sweeps), where its filter came from, and
1534
1555
  the file the result is kept in.
1535
1556
 
1536
1557
  A 3D result with a build direction is made printable before it's drawn: built up layer by layer from the bed, every
@@ -1777,7 +1798,7 @@ module and read `pip`'s variables) and name them in the assembly's `"printInPlac
1777
1798
  together, so the assembly order never takes them apart from each other. `cad order` fits them as one step and
1778
1799
  `cad list` gives them one printed row, the one print's grams and minutes.
1779
1800
 
1780
- 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.
1801
+ 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 its controller'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 slot out of the streamer's order (X, Y, Z on a CNC shield; S0 to S7 on a Mega 2560) fails by name. The machine's `controller` is the bought board the streamer runs on: a `cnc-shield-v3` (an Uno, three axes, and the default) or an `arduino-mega-2560` (eight axes, the quadruped's). A motor on a driver of its own reaches its slot through its wire to the driver's breakout and the breakout's signal wire on to the Mega.
1781
1802
 
1782
1803
  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.
1783
1804
 
package/bin/cad.mjs CHANGED
@@ -786,6 +786,7 @@ async function explainValue(ref) {
786
786
  console.log(`${pad} rule sets: ${q.uses.join(', ')}`);
787
787
  if (vals.length) console.log(`${pad} its values: ${vals.map(([k, v]) => `${k} = ${typeof v === 'number' ? fmt(v) : v}`).join(', ')}`);
788
788
  if (q.parts.length) console.log(`${pad} parts read: ${q.parts.join(', ')}`);
789
+ if (q.assembly) { const A = q.assembly, bits = [...(A.joints.length ? [`joints read: ${A.joints.map((j) => `${j.joint} at (${j.at.map(fmt).join(', ')})`).join(', ')}`] : []), ...(A.sweeps.length ? [`swept: ${A.sweeps.map((w) => `${w.sweep} through ${w.through}, ${fmt(w.from)} to ${fmt(w.to)} in ${w.steps} steps`).join(', ')}`] : [])]; console.log(`${pad} in the assembly ${A.name}, item ${A.item}${A.pose ? `, pose ${A.pose}` : ''}${bits.length ? `: ${bits.join('; ')}` : ''}`); }
789
790
  if (q.anchors.length) console.log(`${pad} anchors read: ${q.anchors.map((a) => `${a.anchor} at (${a.at.map(fmt).join(', ')})`).join(', ')}`);
790
791
  console.log(`${pad} filter ${fmt(q.filter.value)} mm: ${q.filter.from}`);
791
792
  console.log(`${pad} ${q.made ? `kept in ${q.densities}` : `not made yet (cad optimise ${n.object.split('/')[0]}/${q.problem}); it will be kept in ${q.densities}`}: made again only when one of these, or the solver, changes`);
package/lib/machine.mjs CHANGED
@@ -22,14 +22,45 @@ function axisOf(s, id) {
22
22
  }
23
23
 
24
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
- }
25
+ export function shieldSlots(a) { return slotsOf(a, CONTROLLERS['cnc-shield-v3']); }
30
26
  /** 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
27
  export const STREAMER_SLOTS = ['X', 'Y', 'Z'];
32
28
 
29
+ /** The boards the streamer runs on, by the bought part that is the machine's controller: its build (board, as send.mjs and
30
+ * scripts/firmware.mjs name it), its step and direction slots in its axis order, the anchor a wire ends on for each, and
31
+ * how a finding names them. The Mega's slots S0 to S7 are its pins for axes 0 to 7 (arduino-mega-2560's rules). */
32
+ export const CONTROLLERS = {
33
+ 'cnc-shield-v3': { board: 'uno', title: 'an Uno under a CNC Shield V3', of: "the shield's", any: "a shield's slot", slots: STREAMER_SLOTS, wired: /^[^.]+\.([XYZA])$/ },
34
+ 'arduino-mega-2560': { board: 'mega', title: 'a Mega 2560', of: "the Mega's", any: "a slot of the Mega", slots: ['S0', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7'], wired: /^[^.]+\.(S[0-7])$/ },
35
+ };
36
+
37
+ /** The machine's controller: the bought board in its assembly that the streamer runs on, or the Uno under a CNC shield where
38
+ * it has none (as every machine had before the Mega). Two different ones are refused by name.
39
+ * @param {object} a the assembly's JSON @returns {{ set: string, item: string | null, board: string, title: string, of: string, any: string, slots: string[], wired: RegExp }} */
40
+ export function controllerOf(a) {
41
+ const found = (a.items || []).filter((it) => typeof it.bought === 'string' && CONTROLLERS[it.bought]);
42
+ if (new Set(found.map((it) => it.bought)).size > 1) throw new Error(`items ${found.map((it) => `${it.id} (${it.bought})`).join(', ')}: a machine streams through one controller, ${Object.keys(CONTROLLERS).join(' or ')}`);
43
+ const set = found[0]?.bought ?? 'cnc-shield-v3';
44
+ return { set, item: found[0]?.id ?? null, ...CONTROLLERS[set] };
45
+ }
46
+
47
+ /** The controller's slot each motor is wired to, by motor item: a wire from "<motor>.<anchor>" to "<board>.<slot>" (a CNC
48
+ * shield's slot), or a signal wire to the slot from the motor's driver (its "driver" item) or from the board its own wire
49
+ * ends on (an external driver's breakout: the motor's wire to it, its STEP and DIR on to the controller).
50
+ * @param {object} a the assembly's JSON @param {{ wired: RegExp }} c a controller (CONTROLLERS) */
51
+ export function slotsOf(a, c) {
52
+ const out = {}, motors = new Set((a.items || []).filter((it) => it.motor).map((it) => it.id)), top = (x) => String(x).split('.')[0];
53
+ const driverOf = Object.fromEntries((a.items || []).filter((it) => it.motor?.driver).map((it) => [it.motor.driver, it.id]));
54
+ for (const w of a.wires || []) for (const [m, o] of [[top(w.from), top(w.to)], [top(w.to), top(w.from)]]) if (motors.has(m) && !motors.has(o) && !(o in driverOf)) driverOf[o] = m;
55
+ for (const w of a.wires || []) {
56
+ for (const [from, to] of [[String(w.from), String(w.to)], [String(w.to), String(w.from)]]) {
57
+ const m = c.wired.exec(to), id = from.split('.')[0];
58
+ if (m && from.includes('.')) out[driverOf[id] ?? id] = m[1];
59
+ }
60
+ }
61
+ return out;
62
+ }
63
+
33
64
  /** 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
65
  * 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 */
35
66
  export function machineOf(s) {
@@ -39,22 +70,26 @@ export function machineOf(s) {
39
70
  const axes = c.names.map((id) => axisOf(s, id));
40
71
  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';
41
72
  const pen = s.a.task.pen ?? null;
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 } : {}) };
73
+ return { format: 'rulecad.machine/1', name: `${s.project}/${s.name}`, kinematics, tool: s.task.tool, elbow: sample(s).elbow, axes, controller: controllerSummary(controllerOf(s.a)), 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 } : {}) };
43
74
  }
44
75
 
76
+ // The controller as the machine description carries it: its build, and the bought item it is
77
+ const controllerSummary = (c) => ({ board: c.board, set: c.set, item: c.item, slots: c.slots });
78
+
45
79
  function gaitMachineOf(s) {
46
- const seq = gaitSequence(s), slots = shieldSlots(s.a);
80
+ const seq = gaitSequence(s), c = controllerOf(s.a), slots = slotsOf(s.a, c);
47
81
  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));
82
+ if (axes.every((a) => c.slots.includes(a.slot))) axes = [...axes].sort((a, b) => c.slots.indexOf(a.slot) - c.slots.indexOf(b.slot));
49
83
  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,
84
+ return { format: 'rulecad.machine/1', name: `${s.project}/${s.name}`, kinematics: 'legged', tool: null, axes, task: null, controller: controllerSummary(c),
51
85
  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
86
  }
53
87
 
54
88
  /**
55
89
  * 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
90
  * 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.
91
+ * streamer can take the file: as many axes as its controller has slots (three on an Uno under a CNC shield, eight on a
92
+ * Mega 2560), each on the slot of its own number.
58
93
  * @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
94
  */
60
95
  export function plotGait(s, { cycles = 3, period, from } = {}) {
@@ -68,11 +103,12 @@ export function plotGait(s, { cycles = 3, period, from } = {}) {
68
103
  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
104
  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
105
  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 } });
106
+ // the streamer: as many axes as the controller has slots, axis k on its slot k (the shield's X, Y, Z; the Mega's S0 to S7)
107
+ const c = CONTROLLERS[m.controller.set], slots = c.slots;
108
+ if (names.length > slots.length) findings.push({ level: 'warn', text: `${names.length} axes, and the streamer steps ${slots.length} on ${c.title}: the file is written, and send.mjs refuses it${c.board === 'uno' ? ' (an arduino-mega-2560 in the assembly streams up to 8)' : ''}`, code: 'stream.axes', values: { axes: names.length, streamer: slots.length } });
73
109
  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 } });
110
+ if (!a.slot) findings.push({ level: 'info', text: `${a.name}'s motor ${a.motor} has no wire to ${c.any}: the streamer steps it as axis ${k}, on ${slots[k]}`, code: 'stream.wiring', refs: { item: a.motor } });
111
+ else if (a.slot !== slots[k]) findings.push({ level: 'fail', text: `${a.name}'s motor ${a.motor} is wired to ${c.of} ${a.slot}, and the streamer steps axis ${k} on ${slots[k]}`, code: 'stream.wiring', refs: { item: a.motor } });
76
112
  }
77
113
  const n = r.blocks.length;
78
114
  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 } });
package/lib/mesh.mjs CHANGED
@@ -3,6 +3,7 @@
3
3
  // readMesh(file) -> triangles
4
4
  // profiles(tris, axis) -> the stretches along an axis where the cross-section stays the same, each with its outline
5
5
  // spans(tris, axis, at) -> where a line along an axis is inside the solid
6
+ // slabLevels(tris, lo, hi, step) -> heights whose sections together cover what lies between z lo and hi
6
7
  // align(moving, fixed) -> the turn and shift that best lays moving over fixed
7
8
  // deviation(from, to) -> how far points on one surface are from the other, signed (+ outside, - inside)
8
9
  import fs from 'node:fs';
@@ -140,6 +141,29 @@ export function section(tris, axis, v) {
140
141
  return segs;
141
142
  }
142
143
 
144
+ // Where to take sections along z so that, together, they hold all of a solid that lies within the slab from lo to hi
145
+ // (open: a part only touching a face of it is outside) to half of `step`, the grid's cell. They are no more than half a
146
+ // step apart up the slab, the first and last just inside its faces, so a feature as thick as half a cell is caught as
147
+ // a cell of the grid catches it. Where a face leans, the outline it makes moves across as the section rises, by its
148
+ // lean (its normal's z over its normal across) for each mm up, so a stretch is cut finer until no face's outline moves
149
+ // more than half a step from one section to the next. A face lying flat moves no outline: the sections either side of
150
+ // it hold what it covers.
151
+ export function slabLevels(tris, lo, hi, step) {
152
+ const eps = 1e-5, a = lo + eps, b = hi - eps, n0 = Math.max(1, Math.ceil((b - a) / (step / 2))), gap = (b - a) / n0, need = new Float64Array(n0);
153
+ for (const [p, q, r] of tris) {
154
+ const z0 = Math.max(a, Math.min(p[2], q[2], r[2])), z1 = Math.min(b, Math.max(p[2], q[2], r[2]));
155
+ if (!(z1 > z0)) continue;
156
+ const u = [q[0] - p[0], q[1] - p[1], q[2] - p[2]], v = [r[0] - p[0], r[1] - p[1], r[2] - p[2]];
157
+ const nx = u[1] * v[2] - u[2] * v[1], ny = u[2] * v[0] - u[0] * v[2], nz = u[0] * v[1] - u[1] * v[0], across = Math.hypot(nx, ny);
158
+ if (!(across > 1e-12)) continue;
159
+ const lean = Math.abs(nz) / across;
160
+ for (let i = Math.max(0, Math.floor((z0 - a) / gap)); i < n0 && a + i * gap < z1; i++) need[i] = Math.max(need[i], lean * (Math.min(z1, a + (i + 1) * gap) - Math.max(z0, a + i * gap)));
161
+ }
162
+ const out = [a];
163
+ for (let i = 0; i < n0; i++) { const m = Math.max(1, Math.ceil((2 * need[i]) / step)); for (let k = 1; k <= m; k++) out.push(a + gap * (i + k / m)); }
164
+ return out;
165
+ }
166
+
143
167
  // Where a line through a section, at height h, is inside: [[from, to], …] across
144
168
  export function crossings(segs, h) {
145
169
  const xs = [];
package/lib/optimise.mjs CHANGED
@@ -14,7 +14,8 @@ import { resolve, evaluate } from './rules.mjs';
14
14
  import { located } from './errors.mjs';
15
15
  import { discretise, optimise, outlines, surface, area, bounds, resultant, printable, refine, despike, reduce, undercuts, voids, grey } from '@rulecad/topopt';
16
16
  import { islands } from '@rulecad/printcheck';
17
- import { turn } from '@rulecad/model-link';
17
+ import { turn, mul, inv, placeItems, jointValues } from '@rulecad/model-link';
18
+ import { section, loops, slabLevels } from './mesh.mjs';
18
19
  import { threadsBackend } from '@rulecad/fea/threads'; // the solver's products shared over the machine's cores
19
20
  import { grid as makeGrid, analyse, positions } from '@rulecad/fea';
20
21
 
@@ -102,16 +103,126 @@ async function readOne(project, ref, link) {
102
103
  }
103
104
  return anchors.get(ref);
104
105
  };
106
+ // The assembly the problem is placed in ("in": { "assembly", "item", "pose", "z" }): its coordinates are that item's
107
+ // own there, as the item's design draws the result. Built once, in its pose (default the one it shows), for its
108
+ // joints and its moving parts; the item itself, and any other made from this very problem, is drawn without a result
109
+ // (its problem variables set to none), since the result can't be needed to place the problem it comes from.
110
+ const fileName = path.basename(file);
111
+ let placing = null;
112
+ const inAssembly = (what) => {
113
+ if (!p.in) throw new Error(`${fileName}: ${what} needs the problem placed in an assembly: "in": { "assembly": "<name>", "item": "<the item it is drawn in>" }`);
114
+ return (placing ||= (async () => {
115
+ const { buildAssembly, assemblyPath } = await import('./assembly.mjs'), { locate, readObject } = await import('./design.mjs');
116
+ const ref = `${project}/${p.in.assembly}`, overrides = {};
117
+ if (!host.exists(assemblyPath(ref))) throw new Error(`${fileName}: no assembly "${p.in.assembly}" to place the problem in (projects/${project}/assemblies/${p.in.assembly}.json)`);
118
+ for (const it of readJson(assemblyPath(ref)).items || []) if (typeof it.object === 'string') {
119
+ let vars = {};
120
+ try { vars = readObject(locate(`${project}/${it.object.split(/[:@]/)[0]}`)).variables || {}; } catch { continue; }
121
+ for (const [k, v] of Object.entries(vars)) if (v.type === 'problem' && (it.id === p.in.item || String(it.set?.[k] ?? v.value).split(':')[0] === name)) (overrides[it.id] ||= {})[k] = 'none';
122
+ }
123
+ const chain = reading.getStore();
124
+ const s = await reading.run([...chain.slice(0, -1), { ...link, object: `the assembly ${p.in.assembly}` }], () => buildAssembly(ref, [], overrides, { pose: p.in.pose, onePose: true }));
125
+ const k = s.motion.items.findIndex((x) => x[0] === p.in.item);
126
+ if (k < 0) throw new Error(`${fileName}: ${p.in.assembly} has no item "${p.in.item}" (items: ${s.motion.items.map((x) => x[0]).join(', ')})`);
127
+ return { s, k, W0: placeItems(s.motion, s.jointValues) };
128
+ })());
129
+ };
130
+ // A joint of that assembly, where it is in the item's frame: the joint's anchor on the item when the item is one of
131
+ // its ends (the same in every pose), else the parent's anchor as the pose places it. Its axis is the anchor's z.
132
+ const joints = new Map(), clean = (c) => (Math.abs(c) < 1e-9 ? 0 : round(c, 9));
133
+ const jointAt = async (id) => {
134
+ if (!joints.has(id)) {
135
+ const { s, k, W0 } = await inAssembly(`the joint "${id}"`), j = s.motion.joints.find((x) => x.id === id);
136
+ if (!j) throw new Error(`${fileName}: ${p.in.assembly} has no joint "${id}" (joints: ${s.motion.joints.map((x) => x.id).join(', ') || 'none'})`);
137
+ const F = j.child === k ? j.b : j.parent === k ? j.a : mul(inv(W0[k]), j.parent < 0 ? j.a : mul(W0[j.parent], j.a));
138
+ joints.set(id, { joint: id, at: [F[3], F[7], F[11]].map(clean), axis: [F[2], F[6], F[10]].map(clean) });
139
+ }
140
+ return joints.get(id);
141
+ };
142
+ // A part of the assembly swept through a joint's range, as regions to keep clear: the part at each step, in the
143
+ // item's frame (the other joints held at the pose). Steps by default so no point of it moves more than half a cell
144
+ // between two (its travel measured in 32 pieces of the range). In a flat problem, each step is all of the part that
145
+ // lies within the plate's thickness (about in.z, default half its thickness, a plate drawn up from z 0): its sections
146
+ // at heights close enough that, together, they cover it to half a cell, each distinct one a region. A part dipping
147
+ // into the plate's top or bottom is kept clear; one only passing over or under it, or touching a face, is not.
148
+ const sweeps = [];
149
+ const swept = async (r) => {
150
+ const { s, k, W0 } = await inAssembly(`the sweep of "${r.sweep}"`), item = p.in.item, cell = ev(p.cell);
151
+ const isNamed = (q, n) => q.name === n || q.leaf === n || q.item === n || q.name.startsWith(`${n}.`), moving = s.parts.filter((q) => isNamed(q, r.sweep));
152
+ if (!moving.length) throw new Error(`${fileName}: ${p.in.assembly} has no item or part "${r.sweep}" to sweep (items: ${s.motion.items.map((x) => x[0]).join(', ')})`);
153
+ if (moving.some((q) => (q.moves ?? q.item) === item)) throw new Error(`${fileName}: "${r.sweep}" is ${item} itself, the item this problem is in: sweep a part that moves against it`);
154
+ const free = s.motion.joints.filter((j) => !j.follow && j.dofs.length), through = [r.through ?? []].flat();
155
+ if (!through.length) throw new Error(`${fileName}: the sweep of "${r.sweep}" needs the joint it moves through: "through": "<joint>" (joints: ${free.map((j) => j.id).join(', ') || 'none'})`);
156
+ const apply = (M, [x, y, z]) => [M[0] * x + M[1] * y + M[2] * z + M[3], M[4] * x + M[5] * y + M[6] * z + M[7], M[8] * x + M[9] * y + M[10] * z + M[11]];
157
+ const idx = moving.map((q) => s.motion.items.findIndex((x) => x[0] === (q.moves ?? q.item)));
158
+ const local = moving.map((q, i) => { const L = inv(W0[idx[i]]); return q.triangles.map((t) => t.map((v) => apply(L, v))); }); // each in its own item's frame
159
+ const sample = local.map((tris) => { const v = tris.flat(), n = Math.ceil(v.length / 400); return v.filter((_, i) => i % n === 0); }); // (no more than about 400 points a part)
160
+ const held = Object.fromEntries(Object.entries(s.jointValues).filter(([id]) => !s.motion.joints.find((x) => x.id === id).follow));
161
+ const z = flat ? (p.in.z != null ? ev(p.in.z) : ev(p.thickness) / 2) : null, zlo = flat ? z - ev(p.thickness) / 2 : null, zhi = flat ? z + ev(p.thickness) / 2 : null, out = [];
162
+ for (const id of through) {
163
+ const j = free.find((x) => x.id === id);
164
+ if (!j) throw new Error(`${fileName}: ${p.in.assembly} has no joint "${id}" that moves on its own to sweep "${r.sweep}" through (joints: ${free.map((x) => x.id).join(', ') || 'none'})`);
165
+ j.dofs.forEach(([lo, hi], d) => {
166
+ const at = (v) => { const W = placeItems(s.motion, jointValues(s.motion, { ...held, [id]: held[id].map((x, i) => (i === d ? v : x)) })), T = inv(W[k]); return idx.map((m) => mul(T, W[m])); };
167
+ let travel = 0, before = at(lo).map((M, m) => sample[m].map((v) => apply(M, v)));
168
+ for (let i = 1; i <= 32; i++) {
169
+ const now = at(lo + ((hi - lo) * i) / 32).map((M, m) => sample[m].map((v) => apply(M, v)));
170
+ travel += Math.max(0, ...now.flatMap((pts, m) => pts.map((q, n) => Math.hypot(...q.map((c, a) => c - before[m][n][a])))));
171
+ before = now;
172
+ }
173
+ const what = `${id}${j.dofs.length > 1 ? ` (its value ${d + 1})` : ''}`;
174
+ if (!(travel > 1e-6)) throw new Error(`${fileName}: ${what} doesn't move "${r.sweep}" against ${item} (from ${round(lo)} to ${round(hi)}): sweep it through a joint between them`);
175
+ const steps = r.steps ?? Math.max(1, Math.ceil((2 * travel) / cell));
176
+ if (r.steps == null && steps > 360) throw new Error(`${fileName}: sweeping "${r.sweep}" through ${what} would take ${steps} steps on ${cell} mm cells (its farthest point travels ${round(travel, 1)} mm): give the sweep its steps, or larger cells`);
177
+ let made = 0;
178
+ for (let i = 0; i <= steps; i++) {
179
+ const v = lo + ((hi - lo) * i) / steps, Ms = at(v);
180
+ for (const [m, tris] of local.entries()) {
181
+ const moved = tris.map((t) => t.map((q) => apply(Ms[m], q).map(clean)));
182
+ if (!flat) { out.push({ triangles: moved, sweep: r.sweep, joint: id, value: round(v, 6) }); made++; continue; }
183
+ // Each section's outlines, each a ring turned solid on its left (an outline counter-clockwise, a hole in it
184
+ // clockwise), for the design to cut exactly (rings); and for the solver one polygon of them all, each closed and
185
+ // back to the first one's start, so a point is inside where it is inside an odd number of them (a hole in the
186
+ // part stays open) and the joins cancel out. A point within 0.001 mm of the line through its neighbours (where a face's diagonal is
187
+ // cut, or a boolean left a sliver) is dropped, and a section whose corners all lie within 0.01 mm of one already taken at this step is left out.
188
+ const same = (a, b) => Math.abs(a[0] - b[0]) < 1e-9 && Math.abs(a[1] - b[1]) < 1e-9, kept = [];
189
+ const off = (q, a, b) => { const d = [b[0] - a[0], b[1] - a[1]], L = Math.hypot(...d); return L < 1e-12 ? Math.hypot(q[0] - a[0], q[1] - a[1]) : Math.abs(d[0] * (q[1] - a[1]) - d[1] * (q[0] - a[0])) / L; };
190
+ const straight = (ring) => { const l = [...ring]; for (let n = 0; n < l.length && l.length > 3;) if (off(l[n], l[(n + l.length - 1) % l.length], l[(n + 1) % l.length]) < 1e-3) { l.splice(n, 1); n = Math.max(0, n - 1); } else n++; return l; };
191
+ for (const h of slabLevels(moved, zlo, zhi, cell)) {
192
+ const rings = loops(section(moved, 2, h)).map((l) => straight((same(l[0], l.at(-1)) ? l.slice(0, -1) : l).map((q) => q.map(clean)))).filter((l) => l.length >= 3);
193
+ if (!rings.length) continue;
194
+ const within = (q, P) => { let c = false; for (let a = 0, b = P.length - 1; a < P.length; b = a++) if ((P[a][1] > q[1]) !== (P[b][1] > q[1]) && q[0] < ((P[b][0] - P[a][0]) * (q[1] - P[a][1])) / (P[b][1] - P[a][1]) + P[a][0]) c = !c; return c; };
195
+ const turned = rings.map((l, n) => {
196
+ const depth = rings.filter((o, m) => m !== n && within(l[0], o)).length, ccw = l.reduce((t, q, a) => t + q[0] * l[(a + 1) % l.length][1] - l[(a + 1) % l.length][0] * q[1], 0) > 0;
197
+ return ccw === (depth % 2 === 0) ? l : [...l].reverse();
198
+ });
199
+ const near = (l, o) => l.length === o.length && l.every((q) => o.some((w) => Math.hypot(q[0] - w[0], q[1] - w[1]) < 0.01));
200
+ if (kept.some((k) => k.length === turned.length && turned.every((l) => k.some((o) => near(l, o))))) continue;
201
+ kept.push(turned);
202
+ const start = turned[0][0], points = turned.flatMap((l, n) => [...l, l[0], ...(n ? [start] : [])]);
203
+ out.push({ points, rings: turned, sweep: r.sweep, joint: id, value: round(v, 6) }); made++;
204
+ }
205
+ }
206
+ }
207
+ sweeps.push({ sweep: r.sweep, through: what, from: round(lo, 6), to: round(hi, 6), steps, regions: made });
208
+ });
209
+ }
210
+ if (!out.length) throw new Error(`${fileName}: "${r.sweep}" never reaches into the plate (z ${round(zlo)} to ${round(zhi)} mm in ${item}) through ${through.join(', ')}: nothing to keep clear there (set in.z, the plate's middle, if it lies elsewhere)`);
211
+ return out;
212
+ };
105
213
  // The build direction: a direction ('+z'), or a variable holding one
106
214
  const overhang = p.overhang ? (typeof values[p.overhang] === 'string' ? values[p.overhang] : p.overhang) : null;
107
215
  // A teardrop's point: a direction, or up or down the build direction (+z, as drawn, when it's free)
108
216
  const point = (t) => { const up = overhang && overhang !== 'none' ? overhang : '+z'; return t === 'up' ? up : t === 'down' ? (up[0] === '-' ? '+' : '-') + up[1] : t; };
109
217
  const region = async (r) => {
110
- if (r.anchor) { // at an anchor: its place (x and y in a flat problem), and a cylinder along the anchor's axis unless it names one
111
- if (r.at) throw new Error(`${path.basename(file)}: a region at an anchor ("${r.anchor}") takes no at: the anchor places it`);
112
- const a = await anchor(r.anchor), along = a.axis.map((c) => Math.abs(c) > 1e-9);
113
- if (r.length != null && !r.axis && along.filter(Boolean).length !== 1) throw new Error(`${path.basename(file)}: the anchor "${r.anchor}" points along [${a.axis.map((c) => round(c, 3)).join(', ')}], not along x, y or z: give the cylinder an axis`);
114
- return region({ ...r, anchor: undefined, at: flat ? a.at.slice(0, 2) : a.at, ...(r.length != null && !r.axis ? { axis: 'xyz'[along.indexOf(true)] } : {}) });
218
+ if (r.sweep != null) throw new Error(`${path.basename(file)}: a swept part ("${r.sweep}") is a region to keep clear: put it under avoid`);
219
+ if (r.anchor || r.joint) { // at an anchor, or an assembly's joint: its place (x and y in a flat problem), and a cylinder along its axis unless it names one
220
+ const kind = r.anchor ? 'anchor' : 'joint', named = `the ${kind} "${r.anchor || r.joint}"`;
221
+ if (r.anchor && r.joint) throw new Error(`${path.basename(file)}: a region is at an anchor or at a joint, not both ("${r.anchor}", "${r.joint}")`);
222
+ if (r.at) throw new Error(`${path.basename(file)}: a region at an ${kind} ("${r.anchor || r.joint}") takes no at: the ${kind} places it`);
223
+ const a = r.anchor ? await anchor(r.anchor) : await jointAt(r.joint), along = a.axis.map((c) => Math.abs(c) > 1e-9);
224
+ if (r.length != null && !r.axis && along.filter(Boolean).length !== 1) throw new Error(`${path.basename(file)}: ${named} points along [${a.axis.map((c) => round(c, 3)).join(', ')}], not along x, y or z: give the cylinder an axis`);
225
+ return region({ ...r, anchor: undefined, joint: undefined, at: flat ? a.at.slice(0, 2) : a.at, ...(r.length != null && !r.axis ? { axis: 'xyz'[along.indexOf(true)] } : {}) });
115
226
  }
116
227
  if (r.part) { // with where it is (its box's centre), for a load's or support's resultant
117
228
  const triangles = await part(r.part), lo = [Infinity, Infinity, Infinity], hi = [-Infinity, -Infinity, -Infinity];
@@ -132,7 +243,7 @@ async function readOne(project, ref, link) {
132
243
  const printer = printerOf(project), line = printer ? resolve({ uses: [printer] }).values[printer]?.line : null, lines = typeof line === 'number' ? 2 * line : 0;
133
244
  const space = await regions(p.space), dim = flat ? 2 : space[0].triangles || space[0].length != null || (space[0].size || space[0].at)?.length === 3 ? 3 : 2;
134
245
  const problem = {
135
- space, keep: await regions(p.keep), avoid: await regions(p.avoid),
246
+ space, keep: await regions(p.keep), avoid: (await Promise.all([p.avoid || []].flat().map(async (r) => (r.sweep != null ? swept(r) : [await region(r)])))).flat(),
136
247
  supports: await Promise.all(p.supports.map(async (s) => ({ ...(await region(s)), fix: s.fix || 'xyz'.slice(0, dim) }))),
137
248
  loads: await Promise.all(p.loads.map(async (l) => ({ ...(await region(l)), force: pt(l.force), case: l.case || 'load' }))),
138
249
  cases: Object.fromEntries(Object.entries(p.cases || {}).map(([k, w]) => [k, ev(w)])),
@@ -156,7 +267,7 @@ async function readOne(project, ref, link) {
156
267
  // What the result is made from, for cad why: the rule sets, the problem's own values, the parts and anchors of other
157
268
  // designs it reads, and where its filter came from
158
269
  const inputs = { uses, variables: Object.fromEntries(Object.keys(p.variables || {}).map((k) => [k, values[k]])), ...(variant ? { set: p.variants[variant] } : {}),
159
- parts: [...parts.keys()].sort(), anchors: [...anchors.values()].sort((a, b) => (a.anchor < b.anchor ? -1 : 1)).map(({ anchor: a, at }) => ({ anchor: a, at: at.map((c) => round(c, 4)) })),
270
+ parts: [...parts.keys()].sort(), ...(p.in ? { assembly: { name: p.in.assembly, item: p.in.item, pose: placing ? (await placing).s.pose : p.in.pose ?? null, joints: [...joints.values()].sort((a, b) => (a.joint < b.joint ? -1 : 1)).map(({ joint: j, at }) => ({ joint: j, at: at.map((c) => round(c, 4)) })), sweeps } } : {}), anchors: [...anchors.values()].sort((a, b) => (a.anchor < b.anchor ? -1 : 1)).map(({ anchor: a, at }) => ({ anchor: a, at: at.map((c) => round(c, 4)) })),
160
271
  filter: p.filter != null ? { value: problem.filter, from: `the problem: ${p.filter}` } : problem.filter ? { value: problem.filter, from: `two of ${printer}'s lines (2 × ${line} mm), more than a cell and a half` } : { value: round(problem.cell * 1.5), from: 'a cell and a half' } };
161
272
  return { ref, name, variant, file, dim, title: p.title || name, material: { name: p.material, ...m }, problem, outline, critical: !!p.critical, inputs, voids: p.voids || 'allowed' };
162
273
  }
package/lib/wires.mjs CHANGED
@@ -52,12 +52,17 @@ function currentOf(w, s, top, signal) {
52
52
  }
53
53
 
54
54
  // A wire ending on a board's axis connector: the board's pins for that axis, from its rule set
55
- function pinsAt(w, s) {
55
+ export function pinsAt(w, s) {
56
56
  for (const end of [w.from, w.to]) {
57
57
  const [id, anchor] = String(end).split('.'), o = s.objects.find((x) => x.id === id && x.bought?.part === 'board'), e = o?.built.entries;
58
- if (!e || !/^[A-Z]$/.test(anchor ?? '')) continue;
58
+ if (!e || !/^[A-Z]\d?$/.test(anchor ?? '')) continue; // (a shield's X, Y, Z; a Mega's S0 to S7)
59
59
  const pin = (k) => e.find((x) => x.name === `${o.bought.set}.${k}_pin_${anchor.toLowerCase()}`)?.value;
60
- if (pin('step')) return `step ${pin('step')}, dir ${pin('dir')}${pin('limit') ? `, limit ${pin('limit')}` : ''}`;
60
+ if (!pin('step')) continue;
61
+ // A Mega's slots (S0 to S7) go to driver boards of their own: the wire carries the driver's EN, STEP, DIR and GND, every
62
+ // slot's EN on the one enable pin, and the axis's home switch is a wire of its own. A shield's axis carries its limit pin
63
+ const en = /^S\d+$/.test(anchor) ? e.find((x) => x.name === `${o.bought.set}.enable_pin`)?.value : null;
64
+ if (en) return `step ${pin('step')}, dir ${pin('dir')}, enable ${en} (every slot's)`;
65
+ return `step ${pin('step')}, dir ${pin('dir')}${pin('limit') ? `, limit ${pin('limit')}` : ''}`;
61
66
  }
62
67
  return null;
63
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/cad",
3
- "version": "0.7.89",
3
+ "version": "0.7.92",
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": {
@@ -64,8 +64,8 @@
64
64
  "@rulecad/fit": "^0.4.0",
65
65
  "@rulecad/model-link": "^0.3.2",
66
66
  "@rulecad/versions": "^0.1.6",
67
- "@rulecad/shapes": "^0.4.8",
68
- "@rulecad/rules": "^0.3.28",
67
+ "@rulecad/shapes": "^0.4.9",
68
+ "@rulecad/rules": "^0.3.29",
69
69
  "@jscad/modeling": "^2.12.0",
70
70
  "three": "^0.186.1",
71
71
  "@rulecad/fea": "^0.2.14",
@@ -122,6 +122,18 @@
122
122
  "$ref": "#/$defs/load"
123
123
  }
124
124
  },
125
+ "in": {
126
+ "type": "object",
127
+ "additionalProperties": false,
128
+ "required": ["assembly", "item"],
129
+ "description": "The assembly the problem is placed in: its coordinates are the item's own there, as that item's design draws the result. Regions can then sit at the assembly's joints (joint) and keep clear of its moving parts (sweep). While the assembly is read, the item, and any other built from this problem, is drawn without a result (its problem variables set to none)",
130
+ "properties": {
131
+ "assembly": { "type": "string", "description": "The assembly's name, in projects/<project>/assemblies" },
132
+ "item": { "type": "string", "description": "The item whose frame the problem is drawn in: the part being optimised" },
133
+ "pose": { "type": "string", "description": "The pose it is read in (default the one the assembly shows)" },
134
+ "z": { "$ref": "#/$defs/expr", "description": "A flat problem: the plate's middle plane, mm along the item's z (default half its thickness, a plate drawn up from z 0)" }
135
+ }
136
+ },
125
137
  "cases": {
126
138
  "type": "object",
127
139
  "additionalProperties": {
@@ -218,6 +230,11 @@
218
230
  "pattern": "^[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+$",
219
231
  "description": "In place of at: another design's anchor, object.anchor, where it is as that design is built (x and y of it in a flat problem). A cylinder lies along the anchor's axis unless it names one. Move the anchor and the problem moves with it. A design built from this problem can't be named: name what it's fixed to"
220
232
  },
233
+ "joint": {
234
+ "type": "string",
235
+ "pattern": "^[A-Za-z0-9_-]+$",
236
+ "description": "In place of at: a joint of the assembly the problem is in (in), where it is in the item's frame: the joint's anchor on the item when the item is one of its ends, else its parent's anchor as the pose places it (x and y of it in a flat problem). A cylinder lies along the joint's axis unless it names one"
237
+ },
221
238
  "r": {
222
239
  "$ref": "#/$defs/expr"
223
240
  },
@@ -266,6 +283,11 @@
266
283
  "required": [
267
284
  "anchor"
268
285
  ]
286
+ },
287
+ {
288
+ "required": [
289
+ "joint"
290
+ ]
269
291
  }
270
292
  ]
271
293
  },
@@ -302,6 +324,11 @@
302
324
  "pattern": "^[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+$",
303
325
  "description": "In place of at: another design's anchor, object.anchor, where it is as that design is built (x and y of it in a flat problem). A cylinder lies along the anchor's axis unless it names one. Move the anchor and the problem moves with it. A design built from this problem can't be named: name what it's fixed to"
304
326
  },
327
+ "joint": {
328
+ "type": "string",
329
+ "pattern": "^[A-Za-z0-9_-]+$",
330
+ "description": "In place of at: a joint of the assembly the problem is in (in), where it is in the item's frame: the joint's anchor on the item when the item is one of its ends, else its parent's anchor as the pose places it (x and y of it in a flat problem). A cylinder lies along the joint's axis unless it names one"
331
+ },
305
332
  "r": {
306
333
  "$ref": "#/$defs/expr",
307
334
  "description": "A circle's or ball's radius, or a cylinder's"
@@ -339,6 +366,19 @@
339
366
  "type": "string",
340
367
  "description": "A named part of another design in the project, as it's built: object.part. In a flat (2D) problem, its section halfway up (a plate's outline, its holes open)"
341
368
  },
369
+ "sweep": {
370
+ "type": "string",
371
+ "description": "Avoid only: an item or item.part of the assembly the problem is in (in), swept through a joint's range (through), the other joints held at the pose. Each step is a region to keep clear: the part where it is then, in the item's frame (in a flat problem, all of it within the plate's thickness about its middle plane, in.z: its sections up the plate, half a cell apart and closer where a face leans). Change the assembly and the region follows"
372
+ },
373
+ "through": {
374
+ "oneOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" }, "minItems": 1 }],
375
+ "description": "With sweep: the joint it is swept through, from its min to its max (or joints, each in turn)"
376
+ },
377
+ "steps": {
378
+ "type": "integer",
379
+ "minimum": 1,
380
+ "description": "With sweep: how many steps across each joint's range (default: enough that no point of the part moves more than half a cell between two)"
381
+ },
342
382
  "label": {
343
383
  "type": "string"
344
384
  },
@@ -371,6 +411,11 @@
371
411
  "pattern": "^[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+$",
372
412
  "description": "In place of at: another design's anchor, object.anchor, where it is as that design is built (x and y of it in a flat problem). A cylinder lies along the anchor's axis unless it names one. Move the anchor and the problem moves with it. A design built from this problem can't be named: name what it's fixed to"
373
413
  },
414
+ "joint": {
415
+ "type": "string",
416
+ "pattern": "^[A-Za-z0-9_-]+$",
417
+ "description": "In place of at: a joint of the assembly the problem is in (in), where it is in the item's frame: the joint's anchor on the item when the item is one of its ends, else its parent's anchor as the pose places it (x and y of it in a flat problem). A cylinder lies along the joint's axis unless it names one"
418
+ },
374
419
  "r": {
375
420
  "$ref": "#/$defs/expr",
376
421
  "description": "A circle's or ball's radius, or a cylinder's"
@@ -447,6 +492,11 @@
447
492
  "pattern": "^[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+$",
448
493
  "description": "In place of at: another design's anchor, object.anchor, where it is as that design is built (x and y of it in a flat problem). A cylinder lies along the anchor's axis unless it names one. Move the anchor and the problem moves with it. A design built from this problem can't be named: name what it's fixed to"
449
494
  },
495
+ "joint": {
496
+ "type": "string",
497
+ "pattern": "^[A-Za-z0-9_-]+$",
498
+ "description": "In place of at: a joint of the assembly the problem is in (in), where it is in the item's frame: the joint's anchor on the item when the item is one of its ends, else its parent's anchor as the pose places it (x and y of it in a flat problem). A cylinder lies along the joint's axis unless it names one"
499
+ },
450
500
  "r": {
451
501
  "$ref": "#/$defs/expr",
452
502
  "description": "A circle's or ball's radius, or a cylinder's"