@rulecad/cad 0.7.77 → 0.7.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +3 -2
- package/CHANGELOG.md +84 -0
- package/README.md +69 -17
- package/bin/cad.mjs +32 -5
- package/lib/explain.mjs +18 -0
- package/lib/fittings.mjs +20 -2
- package/lib/framecheck.mjs +111 -37
- package/lib/frameprint.mjs +3 -3
- package/lib/framesize.mjs +105 -13
- package/lib/live.mjs +52 -2
- package/lib/optimise.mjs +80 -12
- package/package.json +6 -6
- package/schemas/assembly.schema.json +1 -1
- package/schemas/problem.schema.json +51 -7
- package/schemas/rules.schema.json +2 -0
package/AGENTS.md
CHANGED
|
@@ -126,13 +126,14 @@ variable says which rule it comes from. Follow these steps; they're what makes a
|
|
|
126
126
|
measurement (and its date): report it as it says. A `join.drop` is a prediction for a beam held by one join, to
|
|
127
127
|
measure and write back with `cad measured`, never a figure to tune. `frame.deflection` gives each sag twice, on
|
|
128
128
|
the joins' springs and with the joins rigid: report the first with what it rests on (`refs.restsOn`), never the
|
|
129
|
-
rigid one alone. Say where the frame stands with `"frame": { "supports" }` or fitted feet, not by moving beams.
|
|
129
|
+
rigid one alone. Say where the frame stands with `"frame": { "supports" }` or fitted feet, not by moving beams. A `frame.solve` warning that its supports are guessed means neither is given.
|
|
130
130
|
`frame.rack` gives the racking stiffness each way and the gain each change (gussets, a brace, a panel) solves to:
|
|
131
131
|
report the stiffness, the gain and the change it advises, and say the push and the joins' springs are estimates.
|
|
132
132
|
`frame.frequency` gives the lowest mode against what the machine excites: report it with its pose, and look at
|
|
133
133
|
`<assembly>.frame-mode.svg` from `cad beams` to see what moves. To choose profiles, give `"frame": { "size": {
|
|
134
134
|
"profiles": [...] } }` and read `frame.size` (or `npx cad frame <project>/<assembly> --size`): report each group's
|
|
135
|
-
profile with the limit that set it
|
|
135
|
+
profile with the limit that set it (or the join a lighter profile could not make) and its margin, never pick a
|
|
136
|
+
profile by hand where the sizing can; give `"rack"` to hold racking too; write it with
|
|
136
137
|
`--size --write` and check again, as its joins and lengths change. A task on a guide counts the beam's sag (the
|
|
137
138
|
frame's own figure where the frame is solved), straightness and twist in `task.accuracy`: report the biggest term
|
|
138
139
|
as it is named. `frame.heat` (given `"frame": { "heat": { "air": 45 } }`) says how much the frame grows and holds
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,90 @@ print (a hole's diameter, a seat's depth, a part's outline). Each release lists
|
|
|
5
5
|
its reason. A **fasten** is an entry in an assembly's `"fasten"` list: one screwed joint, naming the screw by thread
|
|
6
6
|
and head, the parts it passes through and the part it ends in.
|
|
7
7
|
|
|
8
|
+
## 0.7.80: problems tied to designs, and optimisation you can watch again
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- A problem's regions, supports and loads can sit at another design's anchor: `"anchor": "plate.pivot"` in place of
|
|
12
|
+
`at`, where that anchor is as the design is built (x and y of it in a flat problem; a cylinder along the anchor's
|
|
13
|
+
axis unless it names one; an anchor with a `rotate` points along its z turned by it, as an assembly reads it).
|
|
14
|
+
Moving the anchor moves the problem and optimises it again; a value of that design the anchors do not read leaves
|
|
15
|
+
the result as it is. A design built from the problem itself is refused by name, as is an anchor that is not there
|
|
16
|
+
(with the anchors there are). So are problems that reach each other through designs built from them, however long
|
|
17
|
+
the loop (problem a held at a design built from b, and b at one built from a): refused with the chain, where before
|
|
18
|
+
they were read until memory ran out. Schema first: `anchor` on regions, supports, loads and the output.
|
|
19
|
+
- `cad preview <project>/problems/<problem>` (or the problem file's path) shows the run: the result is drawn as by
|
|
20
|
+
`cad optimise`, and `.preview/<project>/<problem>-run.html` replays the run step by step with no server (the live
|
|
21
|
+
view's page, its densities, compliance and change for every step read from the file). Every `cad optimise` run is
|
|
22
|
+
recorded and kept by its densities' key, so a cached result still shows the run that made it; one made without
|
|
23
|
+
recording (by a design's build) shows its end and each step's compliance, and says to run it with `--fresh`.
|
|
24
|
+
`--watch` on the preview shows the run live, as on `cad optimise`.
|
|
25
|
+
- A flat (2D) problem's regions can be another design's part (`{ "part": "blank.body" }`), as solid problems' could:
|
|
26
|
+
its section halfway up, holes open, so an arm is optimised within the blank it is cut from. A problem with a
|
|
27
|
+
`thickness` is flat whatever its regions are.
|
|
28
|
+
- `cad why <project>/<object>.<problem variable>` says what the optimised result is made from: the problem file, its
|
|
29
|
+
title and material, its rule sets and values, the parts and anchors of other designs it reads, where its filter
|
|
30
|
+
came from, and the file its densities are kept in (made, or not yet).
|
|
31
|
+
|
|
32
|
+
- `"outline": { "reduce": 0.1 }` on a solid problem draws its surface with fewer triangles: within that many mm of
|
|
33
|
+
the surface as drawn, closed, with no more area past the printer's overhang limit and no new tips (topopt's
|
|
34
|
+
`reduce`). `cad optimise` says how many triangles it had and has. Off unless given: no existing result changes.
|
|
35
|
+
On the bracket bench's printable result, 0.1 mm took 75,592 triangles to 21,124 (27.808 to 27.806 cm³).
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
- A problem with no `filter` is never filtered under two of the printer's lines (the thinnest wall it lays solid).
|
|
40
|
+
It was a cell and a half always, and still is wherever that is more: on an X1C's 0.42 mm lines, every cell of
|
|
41
|
+
0.56 mm or more. No existing problem's result moves: the kit's problems all give their filter or use cells of 1 mm
|
|
42
|
+
or more.
|
|
43
|
+
|
|
44
|
+
## 0.7.79: strength in optimisation
|
|
45
|
+
### Added
|
|
46
|
+
|
|
47
|
+
- A problem takes `strain`, a strain limit (a share: `"pla.strength / pla.modulus / 2"`), in place of `stress`: the
|
|
48
|
+
stress limit is it times the material's modulus. A mechanism given either is optimised as before and then checked:
|
|
49
|
+
`cad optimise` gives its peak stress at its push and the push and output travel that take it to the limit.
|
|
50
|
+
- The rule set schema takes `low` and `high` on a rule: the range it is found in.
|
|
51
|
+
|
|
52
|
+
### Changed
|
|
53
|
+
|
|
54
|
+
- A project whose material has no rule set is refused with every plastic the workspace and the kit have a set for
|
|
55
|
+
(abs, asa, pa_cf, petg and pla in the kit), where it named only pla and petg. A plastic is a set that gives
|
|
56
|
+
strength, modulus, density and modulus_z. `plastics()` in `lib/fittings.mjs` lists them. A project of ABS, ASA or
|
|
57
|
+
PA-CF has its printed fittings sized from the kit's set.
|
|
58
|
+
|
|
59
|
+
No printed size moved.
|
|
60
|
+
|
|
61
|
+
## 0.7.78: frames solved under their joints' loads, sized with joins that fit (#302, #303, #304)
|
|
62
|
+
|
|
63
|
+
### Added
|
|
64
|
+
|
|
65
|
+
- The frame checks carry each `"loads"` entry on a joint (a force on a slide, a torque on a hinge) and a belt guide's
|
|
66
|
+
push at its carriage's acceleration into the beam the joint is mounted on, as a force and its moment at that node,
|
|
67
|
+
solved one way and then the other in every pose (#302). `frame.solve` names them (`refs.onJoints`).
|
|
68
|
+
- `frame.size` holds every join of a grouped beam to fit the profiles chosen (#303): a blind join's screw must pass
|
|
69
|
+
the other beam's slot opening and its button head sit under the lips; an end-tap's cap head must not fall through
|
|
70
|
+
the far face's slot; a bought fitting must fit both profiles. A group whose next lighter profile breaks a join says
|
|
71
|
+
so as what set it ("set by a join").
|
|
72
|
+
- Racking as a sizing limit (#303): with `"frame": { "rack" }` or `"size": { "limits": { "rack": mm } }`, the side
|
|
73
|
+
push each way across, alone, is a case of its own, and the sway at each top node is held to the limit. A way nothing
|
|
74
|
+
holds the frame is said and left out.
|
|
75
|
+
- `frame.solve`, `frame.rack`, `frame.buckling` and `frame.frequency` say how a frame moves where nothing holds it
|
|
76
|
+
("the frame tips over along y", "x1 spins on its own axis", `refs.how`), with the freedoms that show it, where
|
|
77
|
+
they named a freedom at a node (#304).
|
|
78
|
+
|
|
79
|
+
### Changed
|
|
80
|
+
|
|
81
|
+
- A moving joint mounted on a beam is swept through its travel: each end and its quarters between
|
|
82
|
+
(`FRAME_CHECK.sweep`, 4), where a slide was solved at its ends and middle and a hinge at its ends (#302). A
|
|
83
|
+
carriage's worst place for the sag at a point off a span's middle lies between the two: on the riding test's
|
|
84
|
+
600 mm beam, 325 mm along where the far end was taken before. Frames with a moving joint now say more poses.
|
|
85
|
+
- A frame stood on its lowest ends with nothing saying so (no feet, no `"frame": { "supports" }`) now warns in
|
|
86
|
+
`frame.solve` even where those ends, pinned, hold it (#304); before, only a guess that changed how they are held
|
|
87
|
+
warned. Give a frame feet or supports to clear it.
|
|
88
|
+
- `"frame": { "supports": {} }` is refused by name: it names nowhere the frame is held (#304).
|
|
89
|
+
- The sizing table's example in the README: the table's legs and short rails are 2020, not 1515 OpenBeam, whose joins
|
|
90
|
+
to the 2040 rails and 2020 legs do not go together.
|
|
91
|
+
|
|
8
92
|
## 0.7.77: a leg's gait for the streamer (#199)
|
|
9
93
|
### Added
|
|
10
94
|
|
package/README.md
CHANGED
|
@@ -818,7 +818,8 @@ address stands for the faces near it, as `item@anchor` does (`"within"`, 10 mm b
|
|
|
818
818
|
load, a named point or a support meets it), where it is held, the poses solved, and each join's spring with what
|
|
819
819
|
it rests on. A join puts the end of `a` on a node at `b`'s axis through a rigid link (the end stands half `b`'s
|
|
820
820
|
width off that axis) and its spring (`join.stiffness`) at that end. It is held where `"frame": { "supports": {
|
|
821
|
-
"z1.a": "pinned", "z2.a": "fixed" } }` says
|
|
821
|
+
"z1.a": "pinned", "z2.a": "fixed" } }` says (an empty `"supports": {}` is refused by name: it names nowhere the
|
|
822
|
+
frame is held); else at the beam ends a foot, levelling foot, castor plate or
|
|
822
823
|
stacking foot (printed or bought) is fitted to; else at its lowest beam ends. Feet and lowest ends are pinned: held
|
|
823
824
|
from moving and free to turn, as a foot stands on a floor. Where lowest ends pinned would leave the frame free to
|
|
824
825
|
move (two posts and a rail leaning over out of their plane, a beam on the floor rolling with a post on it), a beam
|
|
@@ -827,14 +828,18 @@ address stands for the faces near it, as `item@anchor` does (`"within"`, 10 mm b
|
|
|
827
828
|
feet would leave it free (the portal tipping over out of its plane, below), so `frame.solve` warns: it names the
|
|
828
829
|
freedoms pinned feet would leave (`refs.free`) and the ends held in their place (`refs.guessed`), says that every
|
|
829
830
|
sag, rack, buckling and frequency figure rests on them, and asks for feet or `"frame": { "supports" }`.
|
|
830
|
-
`frame.rack`, `frame.buckling` and `frame.frequency` each say they rest on the guess (`refs.guessed`).
|
|
831
|
+
`frame.rack`, `frame.buckling` and `frame.frequency` each say they rest on the guess (`refs.guessed`). Lowest ends
|
|
832
|
+
guessed and left pinned (a frame they hold) are a guess too: `frame.solve` warns that nothing says where the frame
|
|
833
|
+
stands, names the ends (`refs.guessed`) and asks for feet or supports. Beams no support holds through joins are left out by
|
|
831
834
|
name, and so is what is mounted only on them, as not weighed (`refs.off`). A beam that rides a moving joint (a
|
|
832
835
|
gantry's cross beam on its carriages) is a load on the frame, named as riding (`refs.riding`), not part of it;
|
|
833
836
|
lying across two parallel beams at one level (a gantry's beam on its two side beams), its weight is shared between
|
|
834
837
|
them by the lever rule, though its joint is on one, and `refs.riding` gives each share. Where part of the frame can
|
|
835
838
|
move with nothing resisting it (a frame in one plane on pinned feet sways out of that plane; a beam pinned at both
|
|
836
839
|
ends spins on its own axis) and its loads do not move it that way, it is held there for the sag and the stresses,
|
|
837
|
-
and `frame.solve`
|
|
840
|
+
and `frame.solve` says how it moves there (`refs.how`: "the frame tips over along y" where its top moves across
|
|
841
|
+
and its feet stay, "x1 spins on its own axis" where a beam only turns) with the freedoms that show it
|
|
842
|
+
(`refs.held`); `frame.rack` then warns that a push that way finds it
|
|
838
843
|
free. The modes and buckling count it free: `frame.frequency` gives a lowest mode of 0 Hz and warns, and where
|
|
839
844
|
the frame's squeezed beams lean it that way (a portal on pinned feet), `frame.buckling` fails it as tipping over
|
|
840
845
|
before anything buckles, at a factor of 0 (`refs.tipped`).
|
|
@@ -843,7 +848,16 @@ address stands for the faces near it, as `item@anchor` does (`"within"`, 10 mm b
|
|
|
843
848
|
centre, as a force and a moment at the node where its chain of mounts meets the beam; a riding beam's sheet weight
|
|
844
849
|
at its middle the same way) and each `mass` in `"loads"`.
|
|
845
850
|
A mass on a moving joint mounted on a beam, such as a carriage on a guide, is solved at each end of its travel
|
|
846
|
-
|
|
851
|
+
and at its quarters between (`frame.sweep`, 4 steps), at every named pose and as drawn; the worst is named. A
|
|
852
|
+
carriage's worst place for the sag at a point off a span's middle lies between the point and the middle, which
|
|
853
|
+
the ends alone miss.
|
|
854
|
+
Each `"loads"` entry on a joint (a force on a slide, a torque on a hinge) and a belt guide's push at its
|
|
855
|
+
carriage's acceleration is carried through the joint, held by its motor, into the beam the joint's chain is
|
|
856
|
+
mounted on: a slide's force along its axis through the joint's place, as a force and its moment at that node, a
|
|
857
|
+
hinge's torque as a moment. Nothing says which way such a load acts, so each pose is solved with them one way and
|
|
858
|
+
then the other (`as drawn, joint loads +`, `... joint loads -`), and `frame.solve` names them (`refs.onJoints`).
|
|
859
|
+
A belt's share of its carriage's own weight along the travel is that weight, already on the frame, and is not
|
|
860
|
+
counted again.
|
|
847
861
|
- `frame.deflection`: the sag at each load's point, at each place in `"frame": { "points": ["x2.top@50%"] }` and
|
|
848
862
|
along every guide's travel, with the joins' springs and with the joins rigid, and the load's own share. The first
|
|
849
863
|
rests on the joins' springs, estimates until the joint rig measures them, and the finding says so (`refs.restsOn`:
|
|
@@ -1126,29 +1140,44 @@ joins' springs, the loads and mounted items):
|
|
|
1126
1140
|
- `"groups"`: `{ "rails": ["x1", "x2", "y1", "y2"] }`, beams that take one profile together. The rest group by
|
|
1127
1141
|
themselves: beams of one profile lying the same way whose lengths agree within 0.5 mm (`FRAME_SIZING.match`), so a
|
|
1128
1142
|
table's four legs are one group and each pair of rails another.
|
|
1143
|
+
- Joins that fit: a design is only solved where every join of a grouped beam still goes together with the profiles
|
|
1144
|
+
chosen. A blind join needs a bore in a's end and a slot in b's face whose opening passes the bore's screw and holds
|
|
1145
|
+
its button head under the lips, the head no wider than the slot is under them; an end-tap join a bore in a's end,
|
|
1146
|
+
and a cap head wider than the opening of a slot on b's far face; a bought fitting must fit both profiles (its set's
|
|
1147
|
+
`fitting.fit`). A printed fitting is drawn for the profiles it joins. A group whose next lighter profile breaks a
|
|
1148
|
+
join says so as what set it ("set by a join": with 1515-openbeam, an M5 screw from a 2040's bore does not pass
|
|
1149
|
+
OpenBeam's 3.2 mm slot opening).
|
|
1150
|
+
- Racking: where the assembly gives `"frame": { "rack" }` or `"limits": { "rack": mm }`, each way across the side
|
|
1151
|
+
push `frame.rack` uses, alone and with no weight, is a case of its own, and the sway at each top node is held to
|
|
1152
|
+
the limit `frame.rack` uses (or `limits.rack`). A way nothing holds the frame (one plane on pinned feet) is said and
|
|
1153
|
+
left out: a brace or fixed feet hold it, not a profile. The joins' springs are as drawn and do not grow with the
|
|
1154
|
+
profile, so a frame that racks on its joins' bending may meet the limit with no profile in the list: the sizing then
|
|
1155
|
+
gives the nearest and says racking is what it misses.
|
|
1129
1156
|
- `"limits"`: in place of the checks' own. Left out, each is the check's: the sag at each load, named point and guide
|
|
1130
1157
|
as `frame.deflection` holds it (a guide's rail parallelism, `frame.limit`, the task's accuracy, else the span over
|
|
1131
1158
|
360; a load that moves with a joint anywhere along its beam), each beam's stress with the joins' springs and with
|
|
1132
1159
|
them rigid against its alloy's strength `frame.margin` (2) times over, the frame's first buckling factor and each
|
|
1133
1160
|
grouped beam's Euler load (K 1) the same, and the lowest mode at twice the task's moves where it has a task.
|
|
1134
|
-
`"deflection"` (mm, at every load, point and guide), `"stress"` and `"buckling"` (margins)
|
|
1135
|
-
replace them.
|
|
1161
|
+
`"deflection"` (mm, at every load, point and guide), `"stress"` and `"buckling"` (margins), `"frequency"` (Hz) and
|
|
1162
|
+
`"rack"` (the sway allowed at the top, mm) replace them.
|
|
1136
1163
|
- `"by"`: `mass`. No profile set in the kit gives a price per metre yet, so `cost` is refused by name.
|
|
1137
1164
|
|
|
1138
1165
|
`cad check` gives `frame.size`: each group's profile, its mass, the limit that set it and how many times inside that
|
|
1139
1166
|
limit it stands. `cad frame <project>/<assembly> --size` prints the table:
|
|
1140
1167
|
|
|
1141
1168
|
```
|
|
1142
|
-
sized:
|
|
1169
|
+
sized: 3.348 kg of grouped beams (drawn 2.74 kg), 14 designs solved (every design ranked by mass)
|
|
1143
1170
|
group | profile | kg | set by | margin
|
|
1144
|
-
z1, z2, z3, z4 |
|
|
1145
|
-
x1, x2 | 2040-misumi-hfs5 turned (drawn 2020-misumi-hfs5) | 1.408 | deflection: with 2020-misumi-hfs5, the sag at
|
|
1146
|
-
y1, y2 |
|
|
1171
|
+
z1, z2, z3, z4 | 2020-misumi-hfs5 | 1.44 | a join: with 1515-openbeam, blind join of x1.a to z1.back@710 does not go together (an M5 screw (2040-misumi-hfs5's bore) does not pass 1515-openbeam's 3.2 mm slot opening) | 7.29x
|
|
1172
|
+
x1, x2 | 2040-misumi-hfs5 turned (drawn 2020-misumi-hfs5) | 1.408 | deflection: with 2020-misumi-hfs5, the sag at x1@400 breaks its limit 1.96 times over | 2.56x
|
|
1173
|
+
y1, y2 | 2020-misumi-hfs5 | 0.5 | a join: with 1515-openbeam, blind join of y1.a to z1.top@710 does not go together (an M3 button head, 5.7 mm across, pulls through 2020-misumi-hfs5's 6 mm slot opening) | 3.33x
|
|
1147
1174
|
```
|
|
1148
1175
|
|
|
1149
1176
|
"Set by" is the limit the group's next lighter profile breaks, the other groups as chosen: what stops it being any
|
|
1150
|
-
lighter. A group already at the lightest in the list says so. With `"limits": {
|
|
1151
|
-
drop to 2020 and the grouped beams to
|
|
1177
|
+
lighter, or the join it would not make. A group already at the lightest in the list says so. With `"limits": {
|
|
1178
|
+
"deflection": 6 }` the long rails drop to 2020 and the grouped beams to 2.74 kg. Without the joins held to fit, the
|
|
1179
|
+
legs and short rails came out 1515 OpenBeam, whose M3 ends and 3.2 mm slots take neither the 2040 rails' M5 screws
|
|
1180
|
+
nor a 2020 leg's slot.
|
|
1152
1181
|
|
|
1153
1182
|
`--write` writes the profiles into the assembly: each grouped beam's profile, a quarter `roll` where it was turned,
|
|
1154
1183
|
and its printed end fittings drawn for it. A generated frame is written out expanded, as `--expand` does, since a
|
|
@@ -1158,8 +1187,8 @@ join at an end that now has two bores (a 2040) becomes a join a bore. A drawn be
|
|
|
1158
1187
|
the end of the beam it meets (a rail flush with its legs' tops, now a 2060) moves along that beam by as much, so its
|
|
1159
1188
|
face there stays where it was, if the move fits at its other end too; where it does not, nothing is written and the
|
|
1160
1189
|
refusal names the join and the beam. Otherwise beams keep their lines. Check the
|
|
1161
|
-
written frame: its join checks
|
|
1162
|
-
|
|
1190
|
+
written frame: its join checks hold every screw, nut and length, where the sizing held each join's screw and head to
|
|
1191
|
+
its slot.
|
|
1163
1192
|
|
|
1164
1193
|
What it rests on: the joins' springs are as drawn (an estimate until the joint rig measures them) and do not change
|
|
1165
1194
|
with the profile; the sizing solves the drawn layout, with each beam's line where it is drawn, so a figure on the
|
|
@@ -1455,14 +1484,23 @@ with numbers as expressions like an object's (schema: `schemas/problem.schema.js
|
|
|
1455
1484
|
}
|
|
1456
1485
|
```
|
|
1457
1486
|
|
|
1458
|
-
- **The space** is where material may go (a circle `r`, a rectangle `size`,
|
|
1487
|
+
- **The space** is where material may go (a circle `r`, a rectangle `size`, a polygon `points`, in mm, or another
|
|
1488
|
+
design's part, `{ "part": "blank.body" }`, taken as its section halfway up, holes open). **Keep**
|
|
1459
1489
|
regions stay solid (bosses round bolts), **avoid** regions stay empty (the holes, clearances).
|
|
1460
1490
|
- **Supports** hold the material within `r` of a point (a bolt's hole); **loads** push on it, in newtons, each in a load
|
|
1461
1491
|
case. Cases are optimised together, each by its weight in `cases` (0: analysed, not optimised for).
|
|
1462
1492
|
- **The material** is a rule set with `modulus` (MPa) and `poisson`: `pla`, `petg`, `al6061`, `al7075`, `s275`,
|
|
1463
1493
|
`ss304`, `ti64` come with rulecad. Printed values vary: measure yours.
|
|
1464
1494
|
- **Settings:** `volume`, the share of the space to fill; `cell`, the grid (smaller is finer and slower: a 140 × 40
|
|
1465
|
-
grid takes about half a minute); `filter`, about the thinnest member, in mm.
|
|
1495
|
+
grid takes about half a minute); `filter`, about the thinnest member, in mm. Left out, the filter is a cell and a
|
|
1496
|
+
half, and never under two of the project's printer's lines (the thinnest wall it lays solid): on an X1C's 0.42 mm
|
|
1497
|
+
lines that is 0.84 mm, which only takes over on cells under 0.56 mm.
|
|
1498
|
+
- **At a design's anchors:** any region, support or load can take `"anchor": "plate.pivot"` in place of `at`: the
|
|
1499
|
+
anchor of another design in the project, where it is as that design is built (x and y of it in a flat problem; a
|
|
1500
|
+
cylinder lies along the anchor's axis unless it names one, and an anchor with a `rotate` points along its z turned by
|
|
1501
|
+
it, as an assembly reads it). The problem then follows the design: move the plate's
|
|
1502
|
+
pivot and the support, the boss round it and the result move with it. A design built from this problem can't be
|
|
1503
|
+
named (it would need the result to be built): name the part it is fixed to.
|
|
1466
1504
|
- **Or a stress limit instead of a volume:** `"stress": "pla.strength / 3"` (MPa) finds the lightest layout that keeps
|
|
1467
1505
|
every cell's von Mises stress under it, which rounds off the sharp inside corners where cracks start. It takes about
|
|
1468
1506
|
a thousand steps, each with two solves, so it's slower: give it a coarse cell first. Give supports and loads some
|
|
@@ -1473,7 +1511,9 @@ with numbers as expressions like an object's (schema: `schemas/problem.schema.js
|
|
|
1473
1511
|
|
|
1474
1512
|
`cad optimise <project>/<problem>` runs it, reports how far each load case moves its load and the stiffness that
|
|
1475
1513
|
gives, and draws the layout in `.preview/`. The result is kept, keyed by everything it's made from, so it's only
|
|
1476
|
-
worked out again when something it depends on changes.
|
|
1514
|
+
worked out again when something it depends on changes. `cad why <project>/<object>.<problem variable>` names what
|
|
1515
|
+
that is: the problem file, its rule sets and values, the parts and anchors it reads, where its filter came from, and
|
|
1516
|
+
the file the result is kept in.
|
|
1477
1517
|
|
|
1478
1518
|
A 3D result with a build direction is made printable before it's drawn: built up layer by layer from the bed, every
|
|
1479
1519
|
cell that nothing holds up (an icicle, a loose bit, a sheet hanging under an edge: whatever the optimiser's smooth
|
|
@@ -1490,6 +1530,13 @@ dropped, and `cad check` tests the part for one piece and nothing starting in mi
|
|
|
1490
1530
|
the densities as they change (a 3D part as a surface you can turn, and from three sides), a chart of its compliance and how much it still changes, with a scrubber to look back at any earlier step, its run time and time left, the machine it runs on, and a button that stops the run. It shows the end for ten minutes after the run finishes.
|
|
1491
1531
|
It listens on this computer only. To watch from elsewhere, reach it through a private network such as Tailscale.
|
|
1492
1532
|
|
|
1533
|
+
Every run is kept to watch again. `cad optimise` writes `.preview/<project>/<problem>-run.html`: the same page,
|
|
1534
|
+
reading its steps from the file, so it opens with no server and can be sent to someone. Drag the slider or the chart
|
|
1535
|
+
to any step. `cad preview <project>/problems/<problem>` (or the file's path) draws the result and writes that page.
|
|
1536
|
+
A result made without its steps recorded (by building a design that reads it) shows its end and each step's
|
|
1537
|
+
compliance; `cad preview <project>/problems/<problem> --fresh` runs it again to record the steps, and `--watch`
|
|
1538
|
+
shows the run live. A 3D run shows its three views; the turning surface needs the live view.
|
|
1539
|
+
|
|
1493
1540
|
A design uses it through a variable of type `problem`, which picks a problem by name:
|
|
1494
1541
|
|
|
1495
1542
|
```json
|
|
@@ -1546,6 +1593,11 @@ regions exactly. The surface is a big mesh, so set the object's `"engine": "mani
|
|
|
1546
1593
|
surface is also kept within the printer's overhang limit: faces smoothing tipped past it are tipped back. An
|
|
1547
1594
|
`analysis` of a solid part voxelises it on the problem's grid.
|
|
1548
1595
|
|
|
1596
|
+
The surface comes out with many small triangles. `"outline": { "reduce": 0.1 }` thins them: the surface stays within
|
|
1597
|
+
0.1 mm of where it was drawn (a quarter of an X1C's print line), closed, with no more overhang and no new tips, and
|
|
1598
|
+
`cad optimise` says how many triangles it had and has. On the bracket bench's printable result that took 75,592
|
|
1599
|
+
triangles to 21,124 and 27.808 cm³ to 27.806 cm³, a quarter of the size in a file or a link. It is off unless given.
|
|
1600
|
+
|
|
1549
1601
|
A part prints in one orientation and is loaded in another. Draw it as it prints, and turn it back for its analysis:
|
|
1550
1602
|
`"rotate"` (degrees about x, then y, then z, as JSCAD's `rotate`) then `"move"` (mm) put it in the problem's frame.
|
|
1551
1603
|
Both take expressions, so a variant can lie the part down:
|
package/bin/cad.mjs
CHANGED
|
@@ -18,12 +18,12 @@ import { valuesOf, why } from '../lib/explain.mjs';
|
|
|
18
18
|
import { errorData, near } from '../lib/errors.mjs';
|
|
19
19
|
import { schemaFindings } from '../lib/schema.mjs';
|
|
20
20
|
import { readJson } from '../lib/host.mjs';
|
|
21
|
-
import { optimised, readProblem, analysePart, picture, problemFile } from '../lib/optimise.mjs';
|
|
21
|
+
import { optimised, readProblem, analysePart, picture, problemFile, densitiesKey } from '../lib/optimise.mjs';
|
|
22
22
|
import { evaluate } from '../lib/rules.mjs';
|
|
23
23
|
import { setVariables, addToAssembly, fastenFromFitsEdit, parseValue, parseSetting, newProject, setProject, newAssembly, newObject, setInAssembly, removeFromAssembly, moveInAssembly } from '../lib/edit.mjs';
|
|
24
24
|
import { setAt } from '../lib/jsonedit.mjs';
|
|
25
25
|
import { threemf, slotOf } from '../lib/threemf.mjs';
|
|
26
|
-
import { liveView } from '../lib/live.mjs';
|
|
26
|
+
import { liveView, recorder, endOnly } from '../lib/live.mjs';
|
|
27
27
|
import { checkSets, drawSet, draftSet, draftPart, draftParts } from '../lib/sheet.mjs';
|
|
28
28
|
import { filaments, slots, linkTo, objectModel, assemblyModel, VIEW } from '../lib/links.mjs';
|
|
29
29
|
|
|
@@ -87,7 +87,10 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
87
87
|
assembly with a motor or gears: the drive turning them, cut across the shafts [--turns n]
|
|
88
88
|
cad optimise <project>/<problem> the stiffest layout for a problem in the project's problems/ (name:variant for a
|
|
89
89
|
variant): a picture in .preview/, the result kept for designs [--fresh] [--json]
|
|
90
|
-
[--watch [port]: a live view of it at http://127.0.0.1:8090/, with a stop button]
|
|
90
|
+
[--watch [port]: a live view of it at http://127.0.0.1:8090/, with a stop button];
|
|
91
|
+
each run is kept to watch again: <problem>-run.html in .preview/
|
|
92
|
+
cad preview <project>/problems/<problem> a problem's result and its run, step by step, as a page that needs no
|
|
93
|
+
server (or the run live, with --watch [port])
|
|
91
94
|
cad export <project>/<object> a 3MF for Bambu Studio in exports/ [--open: open it in Bambu Studio]
|
|
92
95
|
cad show <project>/<object> the model on display through your show target, with its rules [--ttl 10m]
|
|
93
96
|
cad link <project>/<object> links to open the model in a browser, and to download its STL or 3MF
|
|
@@ -231,7 +234,7 @@ const stiffOf = (c) => (c.moment ? c.torsion : c.stiffness);
|
|
|
231
234
|
const howFar = (c) => (c.moment ? `turns ${sig(c.angle * 180 / Math.PI)}° under ${sig(c.moment / 1000)} N·m, ${sig(c.torsion / 1000 * Math.PI / 180)} N·m a degree` : `moves ${sig(c.deflection)} mm along its load, ${sig(c.stiffness)} N/mm`);
|
|
232
235
|
// cad optimise: run a problem (with a progress line), then report it and draw it: a 2D layout as an SVG of its
|
|
233
236
|
// densities, a 3D one as the preview's views of its surface
|
|
234
|
-
async function optimiseProblem(ref) {
|
|
237
|
+
async function optimiseProblem(ref, { preview: previewing = false } = {}) {
|
|
235
238
|
const [project, name] = String(ref).split('/');
|
|
236
239
|
if (!project || !name) throw new Error('usage: cad optimise <project>/<problem>[:variant]');
|
|
237
240
|
const file = problemFile(project, name.split(':')[0]);
|
|
@@ -246,8 +249,10 @@ async function optimiseProblem(ref) {
|
|
|
246
249
|
const view = watch ? await liveView({ port: watch === true ? 8090 : Number(watch), title: `cad optimise ${ref}` }) : null;
|
|
247
250
|
if (view) say(`watching at ${view.url}`);
|
|
248
251
|
let r;
|
|
252
|
+
const rec = recorder(); // each step kept, so the run can be watched again (cad preview <project>/problems/<name>)
|
|
249
253
|
try {
|
|
250
254
|
r = await optimised(project, name, { fresh: !!opt('fresh') || !!view, onStep: (s) => {
|
|
255
|
+
rec.step(s);
|
|
251
256
|
if (live) process.stderr.write(`\r\x1b[Kstep ${s.step}/${s.steps} compliance ${s.compliance.toPrecision(5)} N·mm change ${s.change.toFixed(3)} sharpness ${s.beta}`);
|
|
252
257
|
if (view) { view.step(s); if (view.stopped()) throw new Error(`stopped from the live view at step ${s.step}`); }
|
|
253
258
|
} });
|
|
@@ -269,19 +274,28 @@ async function optimiseProblem(ref) {
|
|
|
269
274
|
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
270
275
|
fs.writeFileSync(out, picture(r, { title: r.title, lines }));
|
|
271
276
|
}
|
|
277
|
+
// The run, to watch again: kept by the densities' key when it was recorded here, else its end alone
|
|
278
|
+
const done = `finished: ${r.steps} steps${r.converged ? '' : ', not settled'}`, kept = paths.cache('runs', `${densitiesKey(p.problem)}.html`);
|
|
279
|
+
if (rec.steps()) { fs.mkdirSync(path.dirname(kept), { recursive: true }); fs.writeFileSync(kept, rec.page(`cad optimise ${ref}`, done)); }
|
|
280
|
+
const run = paths.preview(project, `${name.replace(':', '-')}-run.html`), recorded = fs.existsSync(kept);
|
|
281
|
+
fs.mkdirSync(path.dirname(run), { recursive: true });
|
|
282
|
+
fs.writeFileSync(run, recorded ? fs.readFileSync(kept, 'utf8') : endOnly(`cad optimise ${ref}`, r, `${done} (its steps weren't recorded: run it again with --fresh to watch them)`));
|
|
272
283
|
if (opt('json')) return console.log(JSON.stringify((({ density, history, mesh, ...x }) => x)(r), null, 2));
|
|
273
284
|
console.log(`${r.title}${r.cached ? ' (cached)' : ` (${fmt(r.seconds)} s)`}`);
|
|
274
285
|
for (const c of r.cases) console.log(` ${c.name}: ${howFar(c)}`);
|
|
275
286
|
if (r.mechanism) console.log(` the output moves ${sig(r.mechanism.travel)} mm its way for ${sig(r.mechanism.input)} mm of push: an advantage of ${sig(r.mechanism.advantage)}`);
|
|
276
|
-
if (r.stress) console.log(` peak stress ${sig(r.stress.peak)} MPa, the limit ${sig(r.stress.limit)} MPa${r.stress.
|
|
287
|
+
if (r.stress && r.mechanism) console.log(` peak stress ${sig(r.stress.peak)} MPa at its input force${r.stress.strain != null ? ` (strain ${sig(r.stress.strain * 100)}%)` : ''}, the limit ${sig(r.stress.limit)} MPa${r.stress.strainLimit != null ? ` (${sig(r.stress.strainLimit * 100)}%)` : ''}: it reaches the limit at ${sig(r.stress.force)} N of push, its output then ${sig(r.stress.travel)} mm along`);
|
|
288
|
+
else if (r.stress) console.log(` peak stress ${sig(r.stress.peak)} MPa, the limit ${sig(r.stress.limit)} MPa${r.stress.peak > r.stress.limit * 1.02 ? ': over it (raise the volume, ease the limit, or use a smaller cell)' : ''}`);
|
|
277
289
|
if (r.dim === 3) console.log(` ${fmt(r.volume * 100)}% of the space filled: ${fmt(r.solid / 1000)} cm³ (${fmt(r.solid / 1000 * (p.material.density || 0))} g of ${p.material.name})${r.overhang ? `, printable built ${r.overhang}` : ''}`);
|
|
278
290
|
else console.log(` ${fmt(r.volume * 100)}% of the space filled, outline ${fmt(r.area)} mm² (${fmt(r.area * r.thickness / 1000)} cm³ before bosses and holes are made exact)`);
|
|
291
|
+
if (r.reduced) console.log(` ${r.reduced.before} triangles reduced to ${r.reduced.after} (${fmt(r.reduced.after / r.reduced.before * 100)}%), the surface kept within ${fmt(r.reduced.tolerance)} mm`);
|
|
279
292
|
console.log(` ${cells} cells of ${fmt(r.grid.h)} mm, ${r.steps} steps${r.converged ? ', settled' : ': stopped before it settled (raise steps)'}`);
|
|
280
293
|
if (r.process) console.log(` ${processLine(r)}`);
|
|
281
294
|
if (r.symmetry || r.extrude) console.log(` ${[r.symmetry?.mirror ? `mirrored across ${[...r.symmetry.mirror].join(' and ')}` : '', r.symmetry?.turns ? `the same each ${r.symmetry.turns === 4 ? 'quarter' : 'half'} turn about ${r.symmetry.axis || 'z'}` : '', r.extrude ? `one section along ${r.extrude}` : ''].filter(Boolean).join(', ')}`);
|
|
282
295
|
if (r.grey > 0.1) console.log(` warning: ${greyLine(r)}`);
|
|
283
296
|
if (r.voids?.length) { console.log(` error: ${voidsLine(r)}`); process.exitCode = 1; }
|
|
284
297
|
console.log(out);
|
|
298
|
+
if (previewing) console.log(`${run}\n ${recorded ? `the run, step by step: open it to watch it again (${r.steps} steps)` : 'the run\'s end only: its steps weren\'t recorded (cad preview --fresh runs it again and records them)'}`);
|
|
285
299
|
}
|
|
286
300
|
// How a milled or cast result is made, and its undercuts (none, unless an avoid region or the space's own shape sits
|
|
287
301
|
// behind material: the optimiser keeps every cell as solid as those on its way out, but can't fill a cell it mustn't)
|
|
@@ -527,6 +541,9 @@ async function main() {
|
|
|
527
541
|
if (cmd === 'add') return editAssembly(pos[1], pos[2]);
|
|
528
542
|
if (cmd === 'remove' || cmd === 'move') return removeOrMove(cmd, ref, pos[2]);
|
|
529
543
|
if (cmd === 'optimise' || cmd === 'optimize') return await optimiseProblem(ref);
|
|
544
|
+
// A problem file's preview: its result drawn, and its run to watch again (or live, with --watch)
|
|
545
|
+
const problemRef = /^(?:projects[\\/])?([^\\/]+)[\\/]problems[\\/]([^\\/:]+?)(?:\.json)?(:[^\\/]+)?$/.exec(ref || '');
|
|
546
|
+
if (cmd === 'preview' && problemRef) return await optimiseProblem(`${problemRef[1]}/${problemRef[2]}${problemRef[3] || ''}`, { preview: true });
|
|
530
547
|
if (isAssembly(ref)) return assembly(cmd, ref);
|
|
531
548
|
const [base, at] = ref.split('@');
|
|
532
549
|
const d = at ? materialise(locate(base), at) : locate(ref), set = sets();
|
|
@@ -763,6 +780,16 @@ async function explainValue(ref) {
|
|
|
763
780
|
const where = n.via ? ` (${n.object})` : '';
|
|
764
781
|
console.log(`${pad}${n.name} = ${fmt(n.value)}${n.unit ? ` ${n.unit}` : ''}${n.expr ? ` = ${n.expr}` : ''}${where}${n.seen ? ' (above)' : ''}${about}`);
|
|
765
782
|
if (!n.seen && n.rule && !pad) console.log(` ${n.rule}`);
|
|
783
|
+
if (n.problem) { // the result a problem variable picks, and what it is made from
|
|
784
|
+
const q = n.problem, vals = Object.entries(q.variables);
|
|
785
|
+
console.log(`${pad} optimised from ${q.file}: ${q.title}, ${q.material}${q.set ? `, with ${Object.entries(q.set).map(([k, v]) => `${k} = ${v}`).join(', ')}` : ''}`);
|
|
786
|
+
console.log(`${pad} rule sets: ${q.uses.join(', ')}`);
|
|
787
|
+
if (vals.length) console.log(`${pad} its values: ${vals.map(([k, v]) => `${k} = ${typeof v === 'number' ? fmt(v) : v}`).join(', ')}`);
|
|
788
|
+
if (q.parts.length) console.log(`${pad} parts read: ${q.parts.join(', ')}`);
|
|
789
|
+
if (q.anchors.length) console.log(`${pad} anchors read: ${q.anchors.map((a) => `${a.anchor} at (${a.at.map(fmt).join(', ')})`).join(', ')}`);
|
|
790
|
+
console.log(`${pad} filter ${fmt(q.filter.value)} mm: ${q.filter.from}`);
|
|
791
|
+
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`);
|
|
792
|
+
}
|
|
766
793
|
for (const c of n.reads || []) line(c, `${pad} `);
|
|
767
794
|
};
|
|
768
795
|
line(tree, '');
|
package/lib/explain.mjs
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
// What an object's numbers are, and why: `cad values` and `cad why`. A value's explanation is the tree of names its
|
|
2
2
|
// expression reads, down to the rules (each with its kind and source), following other objects' values into their own
|
|
3
3
|
// designs (link.l = keyboard.link_l, explained in the keyboard).
|
|
4
|
+
import path from 'node:path';
|
|
4
5
|
import { locate, build, isObjectRef } from './design.mjs';
|
|
6
|
+
import { WS, paths } from './workspace.mjs';
|
|
7
|
+
import { host } from './host.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What an optimised result is made from, for a problem variable: the problem file, its title and material, the rule
|
|
11
|
+
* sets it uses, its own values, the parts and anchors of other designs it reads, where its filter came from, and the
|
|
12
|
+
* file its densities are kept in (made, or not yet). Change any of these and the result is made again; nothing else.
|
|
13
|
+
* @param {string} project @param {string} ref the problem, name or name:variant
|
|
14
|
+
*/
|
|
15
|
+
export async function problemInputs(project, ref) {
|
|
16
|
+
const { readProblem, densitiesKey } = await import('./optimise.mjs'), r = await readProblem(project, ref);
|
|
17
|
+
const kept = paths.cache('densities', `${densitiesKey(r.problem)}.json`);
|
|
18
|
+
return { problem: ref, file: path.relative(WS, r.file).split(path.sep).join('/'), title: r.title, material: r.material.name, ...r.inputs,
|
|
19
|
+
densities: path.relative(WS, kept).split(path.sep).join('/'), made: host.exists(kept) };
|
|
20
|
+
}
|
|
5
21
|
|
|
6
22
|
/**
|
|
7
23
|
* An object's own variables, resolved: name, value, unit, expression and rule (all of them, or the names given).
|
|
@@ -34,6 +50,8 @@ export async function why(ref, name, { depth = 12 } = {}) {
|
|
|
34
50
|
const from = set && (b.object.uses || []).find((u) => isObjectRef(u) && u.split('/').pop().split(/[:@]/)[0] === set);
|
|
35
51
|
if (from && d > 0) return { ...(await node(from.split(/[:@]/)[0], rest, d - 1)), via: `${r}:${n}` };
|
|
36
52
|
out.reads = d > 0 ? await Promise.all((b.deps?.[n] || []).map((m) => node(r, m, d - 1))) : [];
|
|
53
|
+
// A problem variable: the optimised result it picks, and what that is made from
|
|
54
|
+
if (b.object.variables?.[n]?.type === 'problem' && e.value && e.value !== 'none') out.problem = await problemInputs(r.split('/')[0], e.value);
|
|
37
55
|
return out;
|
|
38
56
|
};
|
|
39
57
|
return node(ref, name, depth);
|
package/lib/fittings.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import crypto from 'node:crypto';
|
|
|
9
9
|
import * as frames from '@rulecad/frames';
|
|
10
10
|
const { bracketModel, bracket, plateModel, plate } = frames;
|
|
11
11
|
import { host } from './host.mjs';
|
|
12
|
-
import { paths } from './workspace.mjs';
|
|
12
|
+
import { paths, RULE_DIRS } from './workspace.mjs';
|
|
13
13
|
import { named } from './parts.mjs';
|
|
14
14
|
import { givenFor } from './frames.mjs';
|
|
15
15
|
import { peekRuleSet } from './rules.mjs';
|
|
@@ -77,7 +77,25 @@ export function plasticNamed(raw, where = 'the project') {
|
|
|
77
77
|
let set = null; try { set = peekRuleSet(m); } catch {}
|
|
78
78
|
const lacks = ['strength', 'modulus', 'density'].filter((k) => !(typeof set?.rules?.[k]?.value === 'number'));
|
|
79
79
|
if (set && !lacks.length) return set;
|
|
80
|
-
|
|
80
|
+
const have = plastics().join(', ');
|
|
81
|
+
throw new Error(`${where}: its material is ${JSON.stringify(raw)}, and printed fittings are sized from their plastic's strength, modulus and density: ${set ? `rules/${m}.json gives no ${lacks.join(', ')}` : `the kit and this workspace have rule sets for ${have}, and there is no rules/${m}.json`}. Give rules/${m}.json with all three, or set the material to one of ${have}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The plastics a project can name: the rule sets (the workspace's rules/, then the kit's) that give strength, modulus,
|
|
86
|
+
* density and modulus_z, the modulus across a print's layers, which only a printed plastic's set gives.
|
|
87
|
+
* @returns {string[]} their names, sorted
|
|
88
|
+
*/
|
|
89
|
+
export function plastics() {
|
|
90
|
+
const out = new Set();
|
|
91
|
+
for (const d of RULE_DIRS) {
|
|
92
|
+
let files = []; try { files = fs.readdirSync(d).filter((f) => f.endsWith('.json')); } catch { continue; }
|
|
93
|
+
for (const f of files) {
|
|
94
|
+
let r; try { r = JSON.parse(fs.readFileSync(path.join(d, f), 'utf8')).rules; } catch { continue; }
|
|
95
|
+
if (['strength', 'modulus', 'density', 'modulus_z'].every((k) => typeof r?.[k]?.value === 'number')) out.add(f.slice(0, -5));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return [...out].sort();
|
|
81
99
|
}
|
|
82
100
|
|
|
83
101
|
/**
|