@rulecad/cad 0.7.44 → 0.7.46
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/EXAMPLES.md +253 -0
- package/README.md +2 -1
- package/bin/cad.mjs +11 -0
- package/lib/motors.mjs +136 -3
- package/lib/motorsvg.mjs +73 -0
- package/lib/preview.mjs +3 -1
- package/package.json +1 -1
package/EXAMPLES.md
CHANGED
|
@@ -976,6 +976,259 @@ The check says which motor it is and how far a step moves (`0.0879° a step`, or
|
|
|
976
976
|
on the pinion's axis, the force reaching the slide against the 1 N it has to push and how many times over, how fast the
|
|
977
977
|
slide moves, and that the slide holds with the power off: the 28BYJ-48's own gearbox friction, far more than the load can
|
|
978
978
|
turn it back with. The torque's line ends `(rests on community figures: measure it)`, because that's what its torque is.
|
|
979
|
+
`motor.mount` bends the rail under the motor by FE, held where its feet are screwed on: the shaft's tip moves a few
|
|
980
|
+
thousandths of a millimetre against the pinion's seat on the rail, far inside the 0.2 mm the pinion is drawn with. A NEMA 17 hung from a 2 mm PLA plate would
|
|
981
|
+
fail the same check, and say how thick the plate would need to be.
|
|
982
|
+
|
|
983
|
+
### The spool winder, driven
|
|
984
|
+
|
|
985
|
+
The winder from chapter 9 with an N20 gear motor where the crank was, so it winds at a steady speed. The motor turns
|
|
986
|
+
the sun now, and the slow part is the carrier: four turns of the motor's shaft for one of the spool's. So the spool
|
|
987
|
+
moves onto the carrier. What changes:
|
|
988
|
+
|
|
989
|
+
- The case loses its axle pin. The motor hangs under the hub on its two M1.6 screws, and three ears reach out past the
|
|
990
|
+
ring for feet tall enough to stand it over the motor.
|
|
991
|
+
- The sun takes the motor's D-shaft with `v.motors.bore`, and keeps its 8 mm shaft, which the spool now turns on.
|
|
992
|
+
- The carrier and the spool are one part, printed upside down: the outer cheek on the bed, the drum, a 45° cone out
|
|
993
|
+
to the carrier's plate (the spool's inner cheek, printed without supports), and the planets' pins on top. The drum
|
|
994
|
+
is hollow, open on the bed, under a roof that closes in at 45°.
|
|
995
|
+
- The handle goes. The ring and the planets are the hand winder's.
|
|
996
|
+
|
|
997
|
+
The N20's figures are Pololu's, for its 100:1 gearbox. Unbranded N20s look the same and vary widely: treat a cheap
|
|
998
|
+
one's torque as about half until it has been measured.
|
|
999
|
+
|
|
1000
|
+
```json projects/home/objects/winder-base.json
|
|
1001
|
+
{
|
|
1002
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1003
|
+
"name": "winder-base",
|
|
1004
|
+
"title": "Winder base for an N20",
|
|
1005
|
+
"version": "0.1.0",
|
|
1006
|
+
"uses": ["x1c"],
|
|
1007
|
+
"engine": "manifold",
|
|
1008
|
+
"variables": {
|
|
1009
|
+
"radius": { "value": 33, "unit": "mm", "rule": "The ring's rim: as the hand winder's case" },
|
|
1010
|
+
"rim": { "value": "x1c.line * 14", "unit": "mm", "rule": "The rim under the ring's, wide enough for its push pins" },
|
|
1011
|
+
"snap": { "value": 2, "unit": "mm", "rule": "Two push pins hold the ring still: their shafts" },
|
|
1012
|
+
"snap_lip": { "value": 0.3, "unit": "mm", "rule": "The barb's lip, clicking over the floor of the ring's counterbore" },
|
|
1013
|
+
"snap_back": { "value": 90, "unit": "deg", "rule": "A square back: it holds for good" },
|
|
1014
|
+
"snap_at": { "value": 30.6, "unit": "mm", "rule": "Halfway across the ring's rim, between its roots and its outside" },
|
|
1015
|
+
"snap_length": { "value": 4, "unit": "mm", "rule": "Up the ring's 6 mm rim to its 2 mm counterbore" },
|
|
1016
|
+
"flange": { "value": 2, "unit": "mm", "rule": "A push pin's foot flange, buried in the rim" },
|
|
1017
|
+
"hub": { "value": 14, "unit": "mm", "rule": "Round the N20's face: its two M1.6 holes 9 mm apart, with a wall outside them" },
|
|
1018
|
+
"spoke": { "value": "x1c.line * 12", "unit": "mm", "rule": "Three spokes from the hub to the rim" },
|
|
1019
|
+
"spokes": { "value": 3, "rule": "Three: it stands without rocking" },
|
|
1020
|
+
"t": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Base, fifteen layers" },
|
|
1021
|
+
"ear_at": { "value": 38, "unit": "mm", "rule": "A foot's screw, outside the ring (33 mm) by a screw head's radius and a little" },
|
|
1022
|
+
"ear": { "value": 10, "unit": "mm", "rule": "An ear's width, round its screw" },
|
|
1023
|
+
"hole": { "value": "3 + x1c.hole_comp + x1c.fit * 2", "unit": "mm", "rule": "M3 clearance for a foot's screw" }
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
```
|
|
1027
|
+
|
|
1028
|
+
```js projects/home/objects/winder-base.js
|
|
1029
|
+
// The hand winder's case with the motor under it: the axle pin goes, the hub takes the N20's face and screws, and three
|
|
1030
|
+
// ears reach out past the ring, a quarter turn round from the spokes, for the feet that stand it over the motor.
|
|
1031
|
+
import jscad from '@jscad/modeling'
|
|
1032
|
+
const { cylinder, cuboid } = jscad.primitives
|
|
1033
|
+
const { rotateZ, translate } = jscad.transforms
|
|
1034
|
+
|
|
1035
|
+
export function main (v) {
|
|
1036
|
+
const motor = v.motors.motorModel('n20')
|
|
1037
|
+
const rim = v.ops.subtract(cylinder({ radius: v.radius, height: v.t, center: [0, 0, v.t / 2] }), cylinder({ radius: v.radius - v.rim, height: v.t, center: [0, 0, v.t / 2] }))
|
|
1038
|
+
const turn = (k) => (2 * Math.PI * k) / v.spokes
|
|
1039
|
+
const spokes = Array.from({ length: v.spokes }, (_, k) => rotateZ(turn(k), cuboid({ size: [v.radius - v.rim / 2, v.spoke, v.t], center: [(v.radius - v.rim / 2) / 2, 0, v.t / 2] })))
|
|
1040
|
+
const ears = Array.from({ length: v.spokes }, (_, k) => rotateZ(turn(k) + Math.PI / 2, v.ops.union(
|
|
1041
|
+
cuboid({ size: [v.ear_at - v.radius + v.rim, v.ear, v.t], center: [(v.ear_at + v.radius - v.rim) / 2, 0, v.t / 2] }),
|
|
1042
|
+
cylinder({ radius: v.ear / 2, height: v.t, center: [v.ear_at, 0, v.t / 2] }))))
|
|
1043
|
+
const holes = Array.from({ length: v.spokes }, (_, k) => rotateZ(turn(k) + Math.PI / 2, cylinder({ radius: v.hole / 2, height: v.t * 2, center: [v.ear_at, 0, v.t / 2] })))
|
|
1044
|
+
const snaps = [0, Math.PI].map((a) => translate([v.snap_at * Math.cos(a), v.snap_at * Math.sin(a), v.t - v.flange], v.flexures.snapPin({ diameter: v.snap, length: v.snap_length, lip: v.snap_lip, back: v.snap_back }, v.ops)))
|
|
1045
|
+
const body = v.ops.union(rim, cylinder({ radius: v.hub / 2, height: v.t, center: [0, 0, v.t / 2] }), ...spokes, ...ears, ...snaps)
|
|
1046
|
+
return v.ops.subtract(body, v.motors.mount(motor, { plate: v.t, screw: 'M1.6' }, v.ops), ...holes)
|
|
1047
|
+
}
|
|
1048
|
+
```
|
|
1049
|
+
|
|
1050
|
+
```json projects/home/objects/winder-foot.json
|
|
1051
|
+
{
|
|
1052
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1053
|
+
"name": "winder-foot",
|
|
1054
|
+
"title": "Winder foot",
|
|
1055
|
+
"version": "0.1.0",
|
|
1056
|
+
"uses": ["x1c"],
|
|
1057
|
+
"variables": {
|
|
1058
|
+
"height": { "value": 32, "unit": "mm", "rule": "Under the motor: its 25 mm, its terminals, and room for the wires to bend" },
|
|
1059
|
+
"size": { "value": 10, "unit": "mm", "rule": "As wide as the base's ear" },
|
|
1060
|
+
"hole": { "value": 2.9, "unit": "mm", "rule": "M3 screw, self-tapped into the plastic" },
|
|
1061
|
+
"depth": { "value": 12, "unit": "mm", "rule": "Plenty for an M3 × 16 through the 3 mm ear" }
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
```
|
|
1065
|
+
|
|
1066
|
+
```js projects/home/objects/winder-foot.js
|
|
1067
|
+
// A foot under each of the base's ears, screwed on from above.
|
|
1068
|
+
import jscad from '@jscad/modeling'
|
|
1069
|
+
const { cylinder } = jscad.primitives
|
|
1070
|
+
|
|
1071
|
+
export function main (v) {
|
|
1072
|
+
const block = cylinder({ radius: v.size / 2, height: v.height, center: [0, 0, v.height / 2] })
|
|
1073
|
+
return v.ops.subtract(block, cylinder({ radius: v.hole / 2, height: v.depth, center: [0, 0, v.height - v.depth / 2] }))
|
|
1074
|
+
}
|
|
1075
|
+
```
|
|
1076
|
+
|
|
1077
|
+
The sun's bore runs right through it, with the flat only as far as the motor's shaft reaches: 10 mm of shaft, less
|
|
1078
|
+
the base and the gap under the sun.
|
|
1079
|
+
|
|
1080
|
+
```json projects/home/objects/winder-drive.json
|
|
1081
|
+
{
|
|
1082
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1083
|
+
"name": "winder-drive",
|
|
1084
|
+
"title": "Winder sun on the motor",
|
|
1085
|
+
"version": "0.1.0",
|
|
1086
|
+
"uses": ["x1c"],
|
|
1087
|
+
"engine": "manifold",
|
|
1088
|
+
"anchors": { "axis": { "at": [0, 0, 0], "axis": [0, 0, 1] } },
|
|
1089
|
+
"variables": {
|
|
1090
|
+
"module": { "value": 1, "unit": "mm", "rule": "As the ring" },
|
|
1091
|
+
"teeth": { "value": 18, "rule": "From planetary()" },
|
|
1092
|
+
"width": { "value": "x1c.layer * 30", "unit": "mm", "rule": "As the ring" },
|
|
1093
|
+
"shaft": { "value": 8, "unit": "mm", "rule": "The reel turns on it, inside the sun's roots" },
|
|
1094
|
+
"shaft_height": { "value": 12, "unit": "mm", "rule": "Up through the reel's plate and into its cone" },
|
|
1095
|
+
"tip": { "value": 6.6, "unit": "mm", "rule": "Where the N20's shaft ends, from the sun's underside: 10 mm of shaft less the 3 mm base and the 0.4 mm gap" }
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
```
|
|
1099
|
+
|
|
1100
|
+
```js projects/home/objects/winder-drive.js
|
|
1101
|
+
// The sun with the N20's D-shaft in it, and the 8 mm shaft above that carries the reel.
|
|
1102
|
+
import jscad from '@jscad/modeling'
|
|
1103
|
+
const { cylinder } = jscad.primitives
|
|
1104
|
+
|
|
1105
|
+
export function main (v) {
|
|
1106
|
+
const motor = v.motors.motorModel('n20')
|
|
1107
|
+
const gear = v.gears.spur({ module: v.module, teeth: v.teeth, width: v.width })
|
|
1108
|
+
const shaft = cylinder({ radius: v.shaft / 2, height: v.shaft_height, center: [0, 0, v.width + v.shaft_height / 2] })
|
|
1109
|
+
return v.ops.subtract(v.ops.union(gear, shaft), v.motors.bore(motor, { depth: v.width + v.shaft_height, tip: v.tip }, v.ops))
|
|
1110
|
+
}
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
```json projects/home/objects/winder-reel.json
|
|
1114
|
+
{
|
|
1115
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1116
|
+
"name": "winder-reel",
|
|
1117
|
+
"title": "Winder reel and carrier",
|
|
1118
|
+
"version": "0.1.0",
|
|
1119
|
+
"uses": ["x1c"],
|
|
1120
|
+
"engine": "manifold",
|
|
1121
|
+
"anchors": {
|
|
1122
|
+
"axis": { "at": [0, 0, "base"], "axis": [0, 0, -1] },
|
|
1123
|
+
"p0": { "at": ["a", 0, "base + t + drop"], "axis": [0, 0, -1] },
|
|
1124
|
+
"p1": { "at": ["0 - a / 2", "a * 0.8660254", "base + t + drop"], "axis": [0, 0, -1] },
|
|
1125
|
+
"p2": { "at": ["0 - a / 2", "0 - a * 0.8660254", "base + t + drop"], "axis": [0, 0, -1] }
|
|
1126
|
+
},
|
|
1127
|
+
"variables": {
|
|
1128
|
+
"a": { "value": 18, "unit": "mm", "rule": "Sun to planet: m (S + P) / 2" },
|
|
1129
|
+
"drop": { "value": "6 + x1c.layer * 2", "unit": "mm", "rule": "A planet's width and two layers' gap above it" },
|
|
1130
|
+
"radius": { "value": 22, "unit": "mm", "rule": "The carrier's plate: past the planets' pins (18 mm out, 1.5 mm round) by four lines" },
|
|
1131
|
+
"t": { "value": "x1c.layer * 15", "unit": "mm", "rule": "The plate, fifteen layers" },
|
|
1132
|
+
"hole": { "value": 9, "unit": "mm", "rule": "Round the sun's 8 mm shaft, which it turns on" },
|
|
1133
|
+
"pin": { "value": 3, "unit": "mm", "rule": "The planets' axles" },
|
|
1134
|
+
"planets": { "value": 3, "rule": "From planetary(): three planets" },
|
|
1135
|
+
"drum": { "value": 24, "unit": "mm", "rule": "The spool's core: a strap bends round it easily" },
|
|
1136
|
+
"wall": { "value": "x1c.line * 4", "unit": "mm", "rule": "The drum's wall: four lines" },
|
|
1137
|
+
"length": { "value": 16, "unit": "mm", "rule": "A 15 mm strap and a millimetre" },
|
|
1138
|
+
"cheek": { "value": 40, "unit": "mm", "rule": "The outer cheek: a few turns of strap" },
|
|
1139
|
+
"cheek_t": { "value": "x1c.layer * 6", "unit": "mm", "rule": "Six layers, on the bed" },
|
|
1140
|
+
"base": { "value": "cheek_t + length + radius - drum / 2", "unit": "mm", "rule": "The plate's far face: the cheek, the drum, and a 45° cone out to the plate" }
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
```
|
|
1144
|
+
|
|
1145
|
+
```js projects/home/objects/winder-reel.js
|
|
1146
|
+
// The carrier and the spool in one part, printed upside down: the outer cheek on the bed, the drum, a 45° cone out to
|
|
1147
|
+
// the carrier's plate, and the planets' pins standing up from it. The assembly turns it over.
|
|
1148
|
+
import jscad from '@jscad/modeling'
|
|
1149
|
+
const { cylinder, cylinderElliptic } = jscad.primitives
|
|
1150
|
+
|
|
1151
|
+
export function main (v) {
|
|
1152
|
+
const cone = v.base - v.cheek_t - v.length
|
|
1153
|
+
const cheek = cylinder({ radius: v.cheek / 2, height: v.cheek_t, center: [0, 0, v.cheek_t / 2] })
|
|
1154
|
+
const drum = cylinder({ radius: v.drum / 2, height: v.length, center: [0, 0, v.cheek_t + v.length / 2] })
|
|
1155
|
+
const flare = cylinderElliptic({ height: cone, startRadius: [v.drum / 2, v.drum / 2], endRadius: [v.radius, v.radius], center: [0, 0, v.cheek_t + v.length + cone / 2] })
|
|
1156
|
+
const plate = cylinder({ radius: v.radius, height: v.t, center: [0, 0, v.base + v.t / 2] })
|
|
1157
|
+
const third = (2 * Math.PI) / v.planets
|
|
1158
|
+
const pins = Array.from({ length: v.planets }, (_, k) => cylinder({ radius: v.pin / 2, height: v.drop, center: [v.a * Math.cos(k * third), v.a * Math.sin(k * third), v.base + v.t + v.drop / 2] }))
|
|
1159
|
+
const hole = cylinder({ radius: v.hole / 2, height: v.base + v.t, center: [0, 0, (v.base + v.t) / 2] })
|
|
1160
|
+
// hollow inside the drum, open on the bed, its roof closing in at 45° to the bore so it prints without supports
|
|
1161
|
+
const inside = v.drum / 2 - v.wall, roof = inside - v.hole / 2, deep = v.cheek_t + v.length
|
|
1162
|
+
const hollow = v.ops.union(cylinder({ radius: inside, height: deep, center: [0, 0, deep / 2] }),
|
|
1163
|
+
cylinderElliptic({ height: roof, startRadius: [inside, inside], endRadius: [v.hole / 2, v.hole / 2], center: [0, 0, deep + roof / 2] }))
|
|
1164
|
+
return v.ops.subtract(v.ops.union(cheek, drum, flare, plate, ...pins), hole, hollow)
|
|
1165
|
+
}
|
|
1166
|
+
```
|
|
1167
|
+
|
|
1168
|
+
The motor drives the sun, and the planetary takes the rest: `"drive": "sun"`. The load is the strap: 10 N at the
|
|
1169
|
+
full spool's 20 mm radius, 0.2 N m on the reel. With the catalogue's 100:1 gearbox the check warns, 0.301 N m against
|
|
1170
|
+
0.2 N m, 1.5 times over. Pololu sells the same motor at 150:1, and `"set": { "ratio": 150 }` scales the torque and
|
|
1171
|
+
speed to it.
|
|
1172
|
+
|
|
1173
|
+
```json projects/home/assemblies/winder-driven.json
|
|
1174
|
+
{
|
|
1175
|
+
"title": "Motorised spool winder",
|
|
1176
|
+
"kind": "fit",
|
|
1177
|
+
"items": [
|
|
1178
|
+
{ "id": "base", "object": "winder-base" },
|
|
1179
|
+
{ "id": "foot_a", "object": "winder-foot", "at": [0, "base.ear_at", "0 - foot_a.height"] },
|
|
1180
|
+
{ "id": "foot_b", "object": "winder-foot", "at": ["0 - base.ear_at * 0.8660254", "0 - base.ear_at / 2", "0 - foot_b.height"] },
|
|
1181
|
+
{ "id": "foot_c", "object": "winder-foot", "at": ["base.ear_at * 0.8660254", "0 - base.ear_at / 2", "0 - foot_c.height"] },
|
|
1182
|
+
{ "id": "drive", "motor": { "model": "n20", "set": { "ratio": 150 }, "drives": "sun", "screw": "M1.6" } },
|
|
1183
|
+
{ "id": "ring", "object": "winder-ring", "at": [0, 0, "base.t"] },
|
|
1184
|
+
{ "id": "sun", "object": "winder-drive" },
|
|
1185
|
+
{ "id": "reel", "object": "winder-reel" },
|
|
1186
|
+
{ "id": "p0", "object": "winder-gear" },
|
|
1187
|
+
{ "id": "p1", "object": "winder-gear" },
|
|
1188
|
+
{ "id": "p2", "object": "winder-gear" }
|
|
1189
|
+
],
|
|
1190
|
+
"joints": [
|
|
1191
|
+
{ "id": "sun", "type": "revolute", "parent": { "item": "base", "at": [0, 0, "base.t + 0.4"], "axis": [0, 0, 1] }, "child": "sun.axis", "label": "Motor" },
|
|
1192
|
+
{ "id": "reel", "type": "revolute", "parent": { "item": "base", "at": [0, 0, "base.t + 0.8 + ring.width + reel.t"], "axis": [0, 0, 1] }, "child": "reel.axis", "min": -180, "max": 180 },
|
|
1193
|
+
{ "id": "p0", "type": "revolute", "parent": "reel.p0", "child": "p0.axis", "min": -3000, "max": 3000 },
|
|
1194
|
+
{ "id": "p1", "type": "revolute", "parent": "reel.p1", "child": "p1.axis", "min": -3000, "max": 3000 },
|
|
1195
|
+
{ "id": "p2", "type": "revolute", "parent": "reel.p2", "child": "p2.axis", "min": -3000, "max": 3000 }
|
|
1196
|
+
],
|
|
1197
|
+
"planetary": [
|
|
1198
|
+
{ "sun": "sun", "carrier": "reel", "ring": "ring", "planets": ["p0", "p1", "p2"], "drive": "sun",
|
|
1199
|
+
"module": "ring.module", "teeth": ["sun.teeth", "p0.teeth", "ring.teeth"] }
|
|
1200
|
+
],
|
|
1201
|
+
"fits": [
|
|
1202
|
+
{ "a": "ring", "b": "base", "fastens": true, "note": "The ring held still on the base by its two push pins" },
|
|
1203
|
+
{ "a": "drive", "b": "base", "fastens": true, "min": 0, "note": "The motor, on its two M1.6 screws" },
|
|
1204
|
+
{ "a": "drive", "b": "sun", "shaft": true, "note": "The motor's shaft in the sun" },
|
|
1205
|
+
{ "a": "foot_a", "b": "base", "fastens": true, "min": 0, "note": "A foot, screwed on" },
|
|
1206
|
+
{ "a": "foot_b", "b": "base", "fastens": true, "min": 0, "note": "A foot, screwed on" },
|
|
1207
|
+
{ "a": "foot_c", "b": "base", "fastens": true, "min": 0, "note": "A foot, screwed on" }
|
|
1208
|
+
],
|
|
1209
|
+
"loads": [{ "joint": "reel", "torque": 0.2, "note": "A strap pulled with 10 N at the full spool's 20 mm radius" }],
|
|
1210
|
+
"poses": { "rest": { "sun": 0 } }
|
|
1211
|
+
}
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
```sh
|
|
1215
|
+
npx cad check home/winder-driven # warns: nothing says whether it holds with the power off
|
|
1216
|
+
npx cad check home/winder-driven --sweep --steps 12 # warns, as above
|
|
1217
|
+
```
|
|
1218
|
+
|
|
1219
|
+
The check says the sun drives the carrier at a quarter of its speed, the shaft has 6.6 mm of its flat in the sun's
|
|
1220
|
+
bore, and the motor gives `0.45 N m there against 0.2 N m needed, 2.25 times over (rests on derived figures)`: scaled
|
|
1221
|
+
from the 100:1 gearbox's, so measure it. It takes a DC motor's working speed as half its free speed: the reel at
|
|
1222
|
+
about 26 rpm, a turn in 2.3 s, about 2 m of strap a minute onto the bare drum. `npx cad preview home/winder-driven`
|
|
1223
|
+
draws the motor's curve beside the picture, with that point on it: against the 0.2 N m load alone it would run nearer
|
|
1224
|
+
40 rpm. Printed, it's 51 g in ten parts, the reel 19 g of it.
|
|
1225
|
+
|
|
1226
|
+
It warns that nothing says whether the spool holds with the power off. It doesn't: an N20's spur gearbox can be turned
|
|
1227
|
+
back from its shaft, and the planetary is no help, since a pull on the reel turns the motor four times as fast the
|
|
1228
|
+
easy way. A ratchet on the reel holds it: the strap tensioner in `examples/bench/projects/gears` has one. Draw it on,
|
|
1229
|
+
give the reel's joint `"brake": "the ratchet"`, and the check passes it. Print the winder and report two things: how
|
|
1230
|
+
fast it winds against a known weight, and whether the spool runs back when the power goes. They become the N20's
|
|
1231
|
+
measured figures.
|
|
979
1232
|
|
|
980
1233
|
## 11. A robot joint: a stepper through a compound planetary
|
|
981
1234
|
|
package/README.md
CHANGED
|
@@ -417,9 +417,10 @@ An item can be a motor instead of a printed object: `{ "id": "drive", "motor": {
|
|
|
417
417
|
- A compound planetary is a `planetary` with `"output": { "ring", "planet", "teeth" }`: a second ring on the planets' second step, following them in phase.
|
|
418
418
|
- `motor.torque`: what reaches the joint through the gears, against the load: a fail under 1 times, a warning under the margin. It says what its figures rest on. `motor.speed`: how fast it moves and how long its range takes. Stages pass on `stageEfficiency` of the power (0.95 a mesh, an estimate).
|
|
419
419
|
- `motor.holds`: with the power on (holding torque, or stall torque) and off (detent torque, a built-in gearbox's friction, a worm that locks, gears under 50% efficient, or `"brake": "a ratchet and pawl"` on the joint). Dropping with the power off is a warning: it may be what you want.
|
|
420
|
-
- `motor.mount`: the part a motor is fastened to (a `fastens` fit), read as drawn: how thick it is at the screw holes against the screws' size, and the screws' bearing on the plastic under the motor's full torque.
|
|
420
|
+
- `motor.mount`: the part a motor is fastened to (a `fastens` fit), read as drawn: how thick it is at the screw holes against the screws' size, and the screws' bearing on the plastic under the motor's full torque. Then the whole part bent, by FE on the part as drawn (cubes, two across the plate at the screws): the motor's weight at its centre, along `gravity` in the pose it's checked in, and its full torque (the larger of its working and holding torque), both carried into the plate where the screws clamp it. The part is held at the joint that carries it, if one does; else where it meets the printed parts it's fastened to that sit below it; failing both, on its lowest face. It reports how far the shaft's tip moves (against the driven joint's seat, where that is on the same part, since the two move together), against the printer's `fit` clearance (or the motor's `"deflection"` in mm), and the peak stress against the material's `strength`; under 2 times either fails, and says what fixes it: the plate thickness that would do (bending goes with its cube), ribs, or how much stiffer a material would have to be. Cells this coarse read a plate 10 to 20% stiff, and a cell's stress is read at its centre, so the peak is scaled up to the surface; it's an estimate, said as one. Kept in `.cache/mount`.
|
|
421
421
|
- `motor.heat`: the motor's case against the softening point of the material the project prints in. Too hot says the current to set the driver to.
|
|
422
422
|
- A `"shaft": true` fit (or `"press"`) between a motor and what it drives reads the bore from the part as drawn: that it's on the shaft (`shaft.seat`), that its flat is there (`shaft.flat`; the shaft turns to meet it, so where the flat faces doesn't matter), how much of the flat it grips (`shaft.grip`), and, pressed on, the hoop stress in the hub (`shaft.hoop`).
|
|
423
|
+
- `cad preview` of an assembly with a motor draws each one at work beside the picture, as SVG: `<assembly>-<motor>-curve.svg`, its torque against speed at the output with the load and the working speed marked, and `<assembly>-<motor>-train.svg`, the torque from its shaft through each stage to the joint with the load, against what the load needs there, and whether it holds with the power on and off. The numbers are the check's.
|
|
423
424
|
|
|
424
425
|
### Building it
|
|
425
426
|
|
package/bin/cad.mjs
CHANGED
|
@@ -679,6 +679,17 @@ async function assembly(cmd, ref) {
|
|
|
679
679
|
const size = (await import('@rulecad/printcheck')).bounds(s.triangles).size.map((n) => fmt(n)).join(' × ');
|
|
680
680
|
const faint = [...new Set(s.parts.filter((p) => p.role !== 'part').map((p) => `${p.object || p.item}${p.role === 'support' ? ' supports' : ''}`))]; // each kind once
|
|
681
681
|
await preview([...s.parts, ...wireTubesOf(s)], { title, meta: `${size} mm · ${versions}${faint.length ? ` · faint: ${faint.join(', ')}` : ''}`, out, explode: !!opt('explode') });
|
|
682
|
+
// each motor at work beside it: its curve with the working point, and the torque through its train (said before
|
|
683
|
+
// the picture, which stays the last line, for whatever reads it)
|
|
684
|
+
if (s.motion?.drives?.length && !pose && !opt('explode')) {
|
|
685
|
+
const { motorWork, workCurve, trainSvg } = await import('../lib/motorsvg.mjs');
|
|
686
|
+
for (const w of motorWork(s)) {
|
|
687
|
+
for (const [kind, svg] of [['curve', workCurve(w)], ['train', trainSvg(w)]]) {
|
|
688
|
+
const file = paths.preview(s.project, `${s.name}-${w.id}-${kind}.svg`);
|
|
689
|
+
fs.writeFileSync(file, svg); console.log(file);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
682
693
|
return console.log(out);
|
|
683
694
|
}
|
|
684
695
|
if (cmd === 'export') {
|
package/lib/motors.mjs
CHANGED
|
@@ -7,6 +7,13 @@ import { motorModel, motorParts, mountModel, performance } from '@rulecad/motors
|
|
|
7
7
|
import { stageEfficiency } from '@rulecad/gears';
|
|
8
8
|
import { named } from './parts.mjs';
|
|
9
9
|
import { referenceBuilt } from './bought.mjs';
|
|
10
|
+
import crypto from 'node:crypto';
|
|
11
|
+
import { grid as makeGrid, analyse, positions } from '@rulecad/fea';
|
|
12
|
+
import { threadsBackend } from '@rulecad/fea/threads';
|
|
13
|
+
import { host } from './host.mjs';
|
|
14
|
+
import { paths, printerOf } from './workspace.mjs';
|
|
15
|
+
import { peekRuleSet } from './rules.mjs';
|
|
16
|
+
import { solidFill } from './optimise.mjs';
|
|
10
17
|
|
|
11
18
|
const require = createRequire(import.meta.url);
|
|
12
19
|
const n3 = (x, d = 3) => String(Number(x.toFixed(d)));
|
|
@@ -194,7 +201,7 @@ export function motorChecks(s, f, helpers, materialName) {
|
|
|
194
201
|
const slideRate = main.x.type === 'prismatic' ? (speedOut * 360 * main.t.slide) / 60 : null, span = slideRate ? main.x.dofs[0][1] - main.x.dofs[0][0] : 0, time = slideRate ? span / slideRate : 60 / speedOut; // along a slide's travel, or a turn
|
|
195
202
|
f('info', `${main.x.id} moves at ${slideRate ? `${n3(slideRate, 2)} mm/s` : `${n3(speedOut, 2)} rpm`} with ${d.id} at ${n3(motorSpeed, 1)} rpm: ${slideRate ? 'its whole range' : 'a turn'} in ${n3(time, 1)} s`, null, { code: 'motor.speed', at: at(main.x), values: { rpm: speedOut, time } });
|
|
196
203
|
}
|
|
197
|
-
mountCheck(s, d, f, W, avail, materialName);
|
|
204
|
+
mountCheck(s, d, f, W, avail, materialName, { worlds, mul });
|
|
198
205
|
// Does it hold?
|
|
199
206
|
const fig = (k) => m.figures[k]?.value, kt = m.type === 'brushless' ? 60 / (2 * Math.PI * fig('kv')) : 0;
|
|
200
207
|
const on = atCurrent(m, d.spec, fig('holding_torque') ?? fig('stall_torque') ?? (kt ? kt * fig('rated_current') : 0)), off_ = fig('detent_torque') ?? fig('friction_torque') ?? null, brake = lines.map((l) => motion.joints.find((x) => x.id === l.x.id)?.brake).find(Boolean) ?? motion.joints.find((x) => x.id === d.joint)?.brake;
|
|
@@ -216,8 +223,8 @@ export function motorChecks(s, f, helpers, materialName) {
|
|
|
216
223
|
}
|
|
217
224
|
|
|
218
225
|
// The part a motor is fastened to, under the motor's full torque as a reaction at its screws: how thick it is at the
|
|
219
|
-
// holes (read from the part as drawn),
|
|
220
|
-
function mountCheck(s, d, f, W, avail, materialName) {
|
|
226
|
+
// holes (read from the part as drawn), the screws' bearing on the plastic, and how far the whole part bends (mountBends).
|
|
227
|
+
function mountCheck(s, d, f, W, avail, materialName, frame) {
|
|
221
228
|
const m = d.model, top = (n) => String(n).split(/[.@]/)[0], fit = s.fits.find((x) => x.fastens && [top(x.a), top(x.b)].includes(d.id));
|
|
222
229
|
if (!fit || !m.mount.holes.length) return;
|
|
223
230
|
const other = top(fit.a) === d.id ? top(fit.b) : top(fit.a), parts = s.parts.filter((p) => p.item === other || p.leaf === other);
|
|
@@ -230,6 +237,132 @@ function mountCheck(s, d, f, W, avail, materialName) {
|
|
|
230
237
|
const here = mountModel(m, { plate: +plate.toFixed(2), ...(d.spec.screw ? { screw: d.spec.screw } : {}) }), mat = material(materialName) || material('pla'), radius = Math.max(...m.mount.holes.map(([x, y]) => Math.hypot(x, y))), each = avail / (m.mount.holes.length * radius / 1000), bearing = each / (hd * t), margin = mat.strength / bearing;
|
|
231
238
|
for (const x of here.findings) f(x.level, `${d.id} on ${other}: ${x.text}`, x.level === 'pass' ? null : `${d.id}: ${x.code.split('.')[1]}`, { code: 'motor.mount' });
|
|
232
239
|
f(margin < 2 ? 'fail' : 'pass', `${d.id} on ${other}: ${n3(plate, 2)} mm of plate at the screws, each taking ${n3(each, 1)} N against the torque (bearing ${n3(bearing, 1)} MPa, ${n3(margin, 0)} times under ${mat.name.toUpperCase()}'s ${mat.strength} MPa)`, margin < 2 ? `${d.id}: screws pull through` : null, { code: 'motor.mount', values: { plate, bearing, margin } });
|
|
240
|
+
mountBends(s, d, f, W, avail, mat, { other, parts, inv, plate, hd, ...frame });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ---------- the mount, bent ----------
|
|
244
|
+
// The part as a whole under the motor: its weight (gravity as the assembly has it, in the pose it's checked in) at its
|
|
245
|
+
// centre and its full torque about the shaft, both carried into the part where the screws clamp it, by FE on the part as
|
|
246
|
+
// drawn (cubes, two across the plate at the screws). The part is held where it meets the printed parts it's fastened to,
|
|
247
|
+
// or at the joint it turns on; failing both, where it stands (its lowest face). Reported: how far the shaft's tip moves,
|
|
248
|
+
// against the printer's fit clearance (what the parts it drives are drawn with), and the peak stress against the
|
|
249
|
+
// material's strength. Kept in .cache, like the other FE checks.
|
|
250
|
+
const sub3 = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]], add3 = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
251
|
+
const len3 = (a) => Math.hypot(a[0], a[1], a[2]);
|
|
252
|
+
function box3(pts) { const lo = [Infinity, Infinity, Infinity], hi = [-Infinity, -Infinity, -Infinity]; for (const p of pts) for (let k = 0; k < 3; k++) { if (p[k] < lo[k]) lo[k] = p[k]; if (p[k] > hi[k]) hi[k] = p[k]; } return { lo, hi }; }
|
|
253
|
+
// A small dense solve (Gaussian elimination, partial pivoting); a pivot near nothing is held at a hair, not divided by
|
|
254
|
+
function solveSmall(A, b) {
|
|
255
|
+
const n = b.length, M = A.map((r, i) => [...r, b[i]]), big = Math.max(1e-30, ...A.map((r, i) => Math.abs(r[i])));
|
|
256
|
+
for (let c = 0; c < n; c++) {
|
|
257
|
+
let p = c; for (let r = c + 1; r < n; r++) if (Math.abs(M[r][c]) > Math.abs(M[p][c])) p = r;
|
|
258
|
+
[M[c], M[p]] = [M[p], M[c]]; if (Math.abs(M[c][c]) < 1e-12 * big) M[c][c] = 1e-12 * big;
|
|
259
|
+
for (let r = 0; r < n; r++) if (r !== c) { const k = M[r][c] / M[c][c]; for (let q = c; q <= n; q++) M[r][q] -= k * M[c][q]; }
|
|
260
|
+
}
|
|
261
|
+
return M.map((r, i) => r[n] / r[i]);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The FE itself, in the motor's frame (the mounting face at z = 0, the shaft along z). tris: the part; holes: the screws'
|
|
266
|
+
* [x, y]; hole: their diameter; held: boxes ({ lo, hi }) and balls ({ at, r }) where the part is held, or null for its
|
|
267
|
+
* lowest face along `down`; weight: N at `centre`, along `down`; torque: N mm about z; tip: the shaft's tip.
|
|
268
|
+
* @returns {{ deflection: number, stress: number, atHoles: boolean, cell: number, across: number, held: string } | { missing: string }}
|
|
269
|
+
*/
|
|
270
|
+
export function mountFE({ tris, holes, hole, plate, side, held, down, weight, centre, torque, tip, ref = null, E, nu, budget = 9000 }) {
|
|
271
|
+
const key = crypto.createHash('sha256').update(JSON.stringify([3, tris, holes, hole, plate, side, held, down, weight, centre, torque, tip, ref, E, nu, budget])).digest('hex').slice(0, 24), file = paths.cache('mount', `${key}.json`);
|
|
272
|
+
if (!process.env.CAD_NO_CACHE && host.exists(file)) return JSON.parse(host.readText(file));
|
|
273
|
+
const { lo, hi } = box3(tris.flat()), span = sub3(hi, lo);
|
|
274
|
+
let cell = Math.max(0.4, plate / 2);
|
|
275
|
+
const count = (h) => span.reduce((t, x) => t * Math.max(1, Math.ceil(x / h)), 1);
|
|
276
|
+
while (count(cell) > budget) cell *= 1.1;
|
|
277
|
+
const n = span.map((x) => Math.max(1, Math.ceil(x / cell))), gr = { nx: n[0], ny: n[1], nz: n[2], h: cell };
|
|
278
|
+
const density = solidFill(tris, gr, lo), g = makeGrid(gr), at = positions(g), pos = (id) => add3(lo, at[id]), onPart = new Uint8Array(g.nodes);
|
|
279
|
+
for (let e = 0; e < density.length; e++) if (density[e] >= 0.5) for (let k = 0; k < 8; k++) onPart[g.edof[e * 24 + 3 * k] / 3] = 1;
|
|
280
|
+
// Clamped: the plate round each screw, under its head (about twice the hole across), through the plate's thickness
|
|
281
|
+
const grip = hole / 2 + Math.max(hole / 2, 1.5 * cell), clamp = [], hold = [];
|
|
282
|
+
const inHeld = (p) => held.some((b) => (b.r != null ? len3(sub3(p, b.at)) <= Math.max(b.r, 2.5 * cell) : p.every((x, k) => x >= b.lo[k] - cell && x <= b.hi[k] + cell)));
|
|
283
|
+
let lowest = Infinity; if (!held) for (const t of tris) for (const p of t) lowest = Math.min(lowest, -(p[0] * down[0] + p[1] * down[1] + p[2] * down[2]));
|
|
284
|
+
for (let id = 0; id < g.nodes; id++) {
|
|
285
|
+
if (!onPart[id]) continue;
|
|
286
|
+
const p = pos(id), z = p[2] * side; // (the screws' clamp first: a part held all over its face is still loaded at them)
|
|
287
|
+
if (z >= -cell && z <= plate + cell && holes.some(([x, y]) => Math.hypot(p[0] - x, p[1] - y) <= grip)) clamp.push(id);
|
|
288
|
+
else if (held ? inHeld(p) : -(p[0] * down[0] + p[1] * down[1] + p[2] * down[2]) <= lowest + cell * 0.75) hold.push(id);
|
|
289
|
+
}
|
|
290
|
+
const heldBy = !held ? 'on its lowest face' : held.some((b) => b.r != null) ? 'at the joint that carries it' : 'where it is fastened';
|
|
291
|
+
if (!hold.length) return { missing: `nothing of it is held ${heldBy}` };
|
|
292
|
+
if (!clamp.length) return { missing: 'the screws are where it is held', cell };
|
|
293
|
+
// The motor's weight and torque, shared over the clamped nodes as a rigid body would put them there
|
|
294
|
+
const P = clamp.map(pos), c = P.reduce((t, p) => add3(t, p), [0, 0, 0]).map((x) => x / P.length), R = P.map((p) => sub3(p, c));
|
|
295
|
+
const J = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]; for (const r of R) { const rr = r[0] * r[0] + r[1] * r[1] + r[2] * r[2]; for (let a = 0; a < 3; a++) for (let b = 0; b < 3; b++) J[a][b] += (a === b ? rr : 0) - r[a] * r[b]; }
|
|
296
|
+
const Fw = down.map((x) => x * weight), arm = sub3(centre, c), Mw = cross(arm, Fw);
|
|
297
|
+
const loads = [1, -1].map((sign) => {
|
|
298
|
+
const M = [Mw[0], Mw[1], Mw[2] + sign * torque], w = solveSmall(J, M), out = new Float64Array(g.dofs);
|
|
299
|
+
clamp.forEach((id, i) => { const t = cross(w, R[i]); for (let k = 0; k < 3; k++) out[3 * id + k] = Fw[k] / clamp.length + t[k]; });
|
|
300
|
+
return out;
|
|
301
|
+
});
|
|
302
|
+
const fixed = new Uint8Array(g.dofs); for (const id of hold) for (let k = 0; k < 3; k++) fixed[3 * id + k] = 1;
|
|
303
|
+
let a; try { a = analyse({ grid: g, density, material: { E, nu }, fixed, loads, backend: threadsBackend }); } catch (e) { return { missing: e.code === 'fea.unheld' ? `it isn't held still ${heldBy}` : e.message, cell }; }
|
|
304
|
+
// The motor moves as a rigid body with the clamped plate: the best fit of a shift and a small turn, at the shaft's tip
|
|
305
|
+
// Where the driven joint stands on this same part, the shaft is measured against the part there (they move together)
|
|
306
|
+
let base = null;
|
|
307
|
+
if (ref) { let best = Infinity; for (let id = 0; id < g.nodes; id++) if (onPart[id]) best = Math.min(best, len3(sub3(pos(id), ref))); base = []; for (let id = 0; id < g.nodes; id++) if (onPart[id] && len3(sub3(pos(id), ref)) <= best + cell) base.push(id); }
|
|
308
|
+
const rigid = (u) => {
|
|
309
|
+
const A = Array.from({ length: 6 }, () => new Array(6).fill(0)), b = new Array(6).fill(0);
|
|
310
|
+
clamp.forEach((id, i) => {
|
|
311
|
+
const [x, y, z] = R[i], rows = [[1, 0, 0, 0, z, -y], [0, 1, 0, -z, 0, x], [0, 0, 1, y, -x, 0]]; // u = t + θ × r
|
|
312
|
+
rows.forEach((row, k) => { for (let p = 0; p < 6; p++) { b[p] += row[p] * u[3 * id + k]; for (let q = 0; q < 6; q++) A[p][q] += row[p] * row[q]; } });
|
|
313
|
+
});
|
|
314
|
+
const s6 = solveSmall(A, b), moved = add3(s6.slice(0, 3), cross(s6.slice(3), sub3(tip, c)));
|
|
315
|
+
return len3(base ? sub3(moved, [0, 1, 2].map((q) => base.reduce((t, id) => t + u[3 * id + q], 0) / base.length)) : moved);
|
|
316
|
+
};
|
|
317
|
+
const deflection = Math.max(...a.u.map(rigid));
|
|
318
|
+
// A cell's stress is read at its centre, inside the surface: across k cells, bending reads (k - 1) / k of the surface's
|
|
319
|
+
const across = Math.max(2, Math.round(plate / cell)), lift = across / (across - 1);
|
|
320
|
+
let stress = 0, atHoles = false;
|
|
321
|
+
for (const st of a.stress) for (let e = 0; e < density.length; e++) {
|
|
322
|
+
if (density[e] < 0.5 || st[e] * lift <= stress) continue;
|
|
323
|
+
const p = add3(lo, [((e % n[0]) + 0.5) * cell, ((Math.floor(e / n[0]) % n[1]) + 0.5) * cell, (Math.floor(e / (n[0] * n[1])) + 0.5) * cell]);
|
|
324
|
+
stress = st[e] * lift; atHoles = holes.some(([x, y]) => Math.hypot(p[0] - x, p[1] - y) <= grip + cell);
|
|
325
|
+
}
|
|
326
|
+
const out = { deflection, relative: !!base, stress, atHoles, cell, across, held: heldBy, cells: g.cells };
|
|
327
|
+
host.writeText(file, JSON.stringify(out)); return out;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function mountBends(s, d, f, W, avail, mat, { other, parts, inv, plate, hd, worlds, mul }) {
|
|
331
|
+
const m = d.model, top = (x) => String(x).split(/[.@]/)[0], motion = s.motion, ids = motion.items.map((x) => x[0]);
|
|
332
|
+
if (!(mat?.modulus > 0) || !(mat?.strength > 0)) return;
|
|
333
|
+
const tris = parts.filter((p) => p.role !== 'support').flatMap((p) => p.triangles.map((t) => t.map(inv)));
|
|
334
|
+
// Where it's held: at the joint it hangs from, if it's carried by one (fixed to a link, or turning on a joint); else at
|
|
335
|
+
// the printed parts it's fastened to that sit below it (along gravity), not the motor nor anything bought
|
|
336
|
+
const g = motion.gravity || [0, 0, -1], gl = Math.hypot(...g) || 1, down = [0, 1, 2].map((r) => (W[r] * g[0] + W[4 + r] * g[1] + W[8 + r] * g[2]) / gl);
|
|
337
|
+
const k = ids.indexOf(other), from = motion.joints.find((j) => j.child === k), boxes = [];
|
|
338
|
+
if (from && worlds) boxes.push({ at: inv(axisOf(motion, worlds, from, mul).O), r: 8 });
|
|
339
|
+
else {
|
|
340
|
+
const motors = new Set((motion.drives || []).map((x) => x.id)), mine = box3(tris.flat()), depth = (b) => [0, 1, 2].reduce((t, q) => t + ((b.lo[q] + b.hi[q]) / 2) * down[q], 0);
|
|
341
|
+
for (const x of s.fits) {
|
|
342
|
+
if (!x.fastens || ![top(x.a), top(x.b)].includes(other)) continue;
|
|
343
|
+
const them = top(x.a) === other ? top(x.b) : top(x.a); if (them === d.id || motors.has(them)) continue;
|
|
344
|
+
const theirs = s.parts.filter((p) => (p.item === them || p.leaf === them) && p.role !== 'reference' && p.role !== 'support');
|
|
345
|
+
const b = theirs.length && box3(theirs.flatMap((p) => p.triangles.flat().map(inv)));
|
|
346
|
+
if (b && depth(b) > depth(mine)) boxes.push(b);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const fig = (x) => m.figures[x]?.value, hold = atCurrent(m, d.spec, fig('holding_torque') ?? fig('stall_torque') ?? 0), T = Math.max(avail, hold); // N m: the most it can put on its screws
|
|
350
|
+
const side = m.mount.side, centre = [m.body.centre[0], m.body.centre[1], (-side * m.body.length) / 2], tip = m.anchors.tip?.origin ?? [0, 0, m.shaft.tip];
|
|
351
|
+
const driven = motion.joints.find((j) => j.id === d.joint), ref = driven && driven.parent === k && worlds ? inv(axisOf(motion, worlds, driven, mul).O) : null;
|
|
352
|
+
const fe = mountFE({ tris, holes: m.mount.holes, hole: hd, plate, side, held: boxes.length ? boxes : null, down, weight: (m.mass ?? 0) * G, centre, torque: T * 1000, tip, ref, E: mat.modulus, nu: mat.poisson ?? 0.36 });
|
|
353
|
+
const S = rowsAt(W, tip), refs = { item: d.id, part: other }, name = mat.name.toUpperCase();
|
|
354
|
+
if (fe.missing) return f('warn', `${d.id} on ${other}: couldn't bend the part under the motor: ${fe.missing}. Fasten it to what holds it (a "fastens" fit)`, `${d.id}: mount not solved`, { code: 'motor.mount', at: S, refs });
|
|
355
|
+
let limit = 0.2; try { limit = d.spec.deflection != null ? s.num(d.spec.deflection) : peekRuleSet(printerOf(s.project)).rules.fit?.value ?? 0.2; } catch {}
|
|
356
|
+
const bend = limit / Math.max(fe.deflection, 1e-9), strong = mat.strength / Math.max(fe.stress, 1e-9), margin = Math.min(bend, strong), K = 2, bad = margin < K;
|
|
357
|
+
const where = fe.atHoles ? 'at the screw holes' : 'in the part, away from the screws';
|
|
358
|
+
const how = `FE on ${n3(fe.cell, 2)} mm cubes, ${fe.across} across the plate, held ${fe.held}; an estimate: cells this coarse read a plate 10 to 20% stiffer than it is`;
|
|
359
|
+
const said = `${d.id} on ${other}: under the motor's ${n3((m.mass ?? 0) * 1000, 0)} g and ${n3(T, 3)} N m, the shaft's tip moves ${n3(fe.deflection, 3)} mm${fe.relative ? ` against ${d.joint}'s seat on ${other}` : ''}, ${bend >= 1 ? `${n3(bend, 1)} times inside` : `${n3(1 / bend, 1)} times`} the ${n3(limit, 2)} mm fit the parts it drives are drawn with, and the stress peaks at ${n3(fe.stress, 2)} MPa ${where}, ${strong >= 1 ? `${n3(strong, 1)} times under` : `${n3(1 / strong, 1)} times`} ${name}'s ${mat.strength} MPa (${how})`;
|
|
360
|
+
let fix = '';
|
|
361
|
+
if (bad) {
|
|
362
|
+
const grow = Math.max(bend < K ? Math.cbrt(K / bend) : 1, strong < K ? Math.sqrt(K / strong) : 1), want = Math.ceil(plate * grow * 5) / 5; // bending goes with the cube of the thickness, stress with its square
|
|
363
|
+
fix = `. A plate about ${n3(want, 1)} mm thick where it bends (${n3(plate, 2)} mm at the screws now), or ribs under it, or a stiffer material (${bend < K ? `${n3((K / bend), 1)} times ${name}'s ${mat.modulus} MPa modulus` : `${n3((mat.strength * K) / strong, 0)} MPa strength or more`}), or hold it closer to the motor`;
|
|
364
|
+
}
|
|
365
|
+
f(bad ? 'fail' : 'pass', said + fix, bad ? `${d.id}: mount ${bend < strong ? 'bends' : 'overstressed'} ${n3(margin, 1)}×` : null, { code: 'motor.mount', at: S, refs, values: { deflection: fe.deflection, relative: fe.relative, limit, stress: fe.stress, strength: mat.strength, margin, cell: fe.cell, held: fe.held } });
|
|
233
366
|
}
|
|
234
367
|
|
|
235
368
|
// A "shaft" fit: a motor's shaft in the bore of a part. Reads the bore from the part as drawn: a slice across the
|
package/lib/motorsvg.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// A motor at work, in 2D, beside an assembly's preview: its curve with the working point marked, and the torque
|
|
2
|
+
// through its train, a bar for each stage, against what the load needs there. The numbers are the check's own.
|
|
3
|
+
import { mul, jointValues, placeItems } from '@rulecad/model-link';
|
|
4
|
+
import { curve } from '@rulecad/motors/diagram';
|
|
5
|
+
import { motorChecks, trainFrom } from './motors.mjs';
|
|
6
|
+
import { materialOf } from './list.mjs';
|
|
7
|
+
|
|
8
|
+
const esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<');
|
|
9
|
+
const fig = (x, d = 3) => String(+Number(x).toPrecision(d));
|
|
10
|
+
const FONT = 'font-family="system-ui, sans-serif"';
|
|
11
|
+
const wrap = (text, n) => text.split(' ').reduce((lines, word) => { const last = lines[lines.length - 1]; if (last && (last + ' ' + word).length <= n) lines[lines.length - 1] = `${last} ${word}`; else lines.push(word); return lines; }, []);
|
|
12
|
+
|
|
13
|
+
// What each motor does, from the check: its joint, the train to the load, the torque there, its speed, whether it holds
|
|
14
|
+
export function motorWork(s) {
|
|
15
|
+
const found = [], helpers = { placeItems, jointValues, mul };
|
|
16
|
+
motorChecks(s, (level, text, card, extra = {}) => found.push({ level, text, ...extra }), helpers, materialOf(s.project));
|
|
17
|
+
const out = [];
|
|
18
|
+
let mine = null;
|
|
19
|
+
for (const x of found) {
|
|
20
|
+
if (x.code === 'motor.model') { mine = { id: x.refs?.item, findings: [] }; out.push(mine); continue; }
|
|
21
|
+
if (mine) mine.findings.push(x);
|
|
22
|
+
}
|
|
23
|
+
return out.map(({ id, findings }) => {
|
|
24
|
+
const d = (s.motion?.drives || []).find((x) => x.id === id), torque = findings.find((x) => x.code === 'motor.torque' && x.values);
|
|
25
|
+
if (!d || !torque) return null;
|
|
26
|
+
const joint = torque.refs.joint, t = trainFrom(s.motion, joint), speed = findings.find((x) => x.code === 'motor.speed' && x.values);
|
|
27
|
+
return { id, drive: d, joint, train: t, ...torque.values, level: torque.level, rpm: speed?.values.rpm ?? null,
|
|
28
|
+
holds: findings.filter((x) => x.code === 'motor.holds').map((x) => ({ level: x.level, text: x.text })) };
|
|
29
|
+
}).filter(Boolean);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The motor's curve at its output, the load and the working speed marked
|
|
33
|
+
export function workCurve(w) {
|
|
34
|
+
const slide = w.train.slide != null;
|
|
35
|
+
return curve(w.drive.model, { ratio: w.train.ratio, efficiency: w.train.efficiency, ...(w.rpm != null ? { at: { speed: w.rpm, ...(slide ? {} : { load: w.needed }) } } : {}) });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The torque through the train: from the motor's shaft, stage by stage, to the joint with the load; the load's need
|
|
39
|
+
// carried back through the same stages, so each bar shows the margin where it is
|
|
40
|
+
export function trainSvg(w, { title = '' } = {}) {
|
|
41
|
+
const stages = [...w.train.stages].reverse(), slide = w.train.slide != null; // trainFrom walks from the load back to the motor
|
|
42
|
+
const atMotor = w.available / (w.train.ratio * w.train.efficiency), rows = [{ name: `${w.id}'s shaft`, have: atMotor, kind: 'the motor' }];
|
|
43
|
+
let have = atMotor;
|
|
44
|
+
for (const [k, st] of stages.entries()) {
|
|
45
|
+
const last = k === stages.length - 1;
|
|
46
|
+
if (slide && last) rows.push({ name: st.joint, have: w.available, kind: `${st.kind}, ${fig(st.efficiency * 100, 2)}%`, unit: 'N' });
|
|
47
|
+
else { have *= (1 / Math.abs(st.ratio)) * st.efficiency; rows.push({ name: st.joint, have, kind: `${st.kind} ${fig(1 / Math.abs(st.ratio))}:1, ${fig(st.efficiency * 100, 2)}%` }); }
|
|
48
|
+
}
|
|
49
|
+
// the need, carried back from the load through the same stages: the same margin at every one
|
|
50
|
+
for (const r of rows) r.need = w.margin > 0 && Number.isFinite(w.margin) ? r.have / w.margin : null;
|
|
51
|
+
const width = 720, rowH = 46, top = 64, L = 200, R = width - 150;
|
|
52
|
+
const scale = (r) => (R - L) / Math.max(r.have, r.need ?? 0, 1e-9) / 1.08; // each bar on its own scale: the margin is what reads
|
|
53
|
+
const out = [`<rect width="100%" height="100%" fill="#fff"/>`,
|
|
54
|
+
`<text x="24" y="28" font-size="15" ${FONT} fill="#1a1a1a">${esc(title || `${w.id} into ${w.joint}: the torque through the train`)}</text>`,
|
|
55
|
+
`<text x="24" y="48" font-size="11" ${FONT} fill="#888">each stage: what reaches it (blue) against what the load needs there (red), with the margin</text>`];
|
|
56
|
+
rows.forEach((r, i) => {
|
|
57
|
+
const y = top + i * rowH, k = scale(r), u = r.unit || 'N m';
|
|
58
|
+
out.push(`<text x="24" y="${y + 18}" font-size="13" ${FONT} fill="#1a1a1a">${esc(r.name)}</text><text x="24" y="${y + 33}" font-size="11" ${FONT} fill="#888">${esc(r.kind)}</text>`);
|
|
59
|
+
out.push(`<rect x="${L}" y="${y + 8}" width="${fig(r.have * k, 4)}" height="20" fill="#2266cc"/>`);
|
|
60
|
+
if (r.need != null) out.push(`<line x1="${fig(L + r.need * k, 4)}" x2="${fig(L + r.need * k, 4)}" y1="${y + 2}" y2="${y + 34}" stroke="#cc3322" stroke-width="2.4"/>`);
|
|
61
|
+
out.push(`<text x="${R + 10}" y="${y + 18}" font-size="12" ${FONT} fill="#1a1a1a">${fig(r.have)} ${u}</text>`);
|
|
62
|
+
if (r.need) out.push(`<text x="${R + 10}" y="${y + 33}" font-size="11" ${FONT} fill="${r.have / r.need < 1 ? '#cc3322' : '#555'}">${fig(r.have / r.need, 3)}× the ${fig(r.need)}</text>`);
|
|
63
|
+
});
|
|
64
|
+
// whether it holds, power on and off, each line wrapped to the drawing's width
|
|
65
|
+
let y = top + rows.length * rowH + 18;
|
|
66
|
+
for (const h of w.holds) {
|
|
67
|
+
const colour = h.level === 'pass' ? '#2a7a2a' : h.level === 'fail' ? '#cc3322' : '#b06a00', lines = wrap(`${h.level === 'pass' ? '✓' : h.level === 'fail' ? '✗' : '!'} ${h.text}`, 104);
|
|
68
|
+
for (const l of lines) { out.push(`<text x="24" y="${y}" font-size="12" ${FONT} fill="${colour}">${esc(l)}</text>`); y += 17; }
|
|
69
|
+
y += 4;
|
|
70
|
+
}
|
|
71
|
+
const height = y + 8;
|
|
72
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}">${out.join('')}</svg>\n`;
|
|
73
|
+
}
|
package/lib/preview.mjs
CHANGED
|
@@ -55,7 +55,9 @@ async function shoot(server, out, { width = 1800, height = 1200 } = {}) {
|
|
|
55
55
|
});
|
|
56
56
|
} finally {
|
|
57
57
|
server.close();
|
|
58
|
-
|
|
58
|
+
// Chrome's helpers can still be writing to its profile as it exits (macOS: "Directory not empty"): try a few
|
|
59
|
+
// times, and leave it in the temporary folder rather than fail a picture that was made
|
|
60
|
+
try { fs.rmSync(profile, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 }); } catch { /* the OS clears it */ }
|
|
59
61
|
}
|
|
60
62
|
return out;
|
|
61
63
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.46",
|
|
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": {
|