@rulecad/cad 0.7.43 → 0.7.45
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 +250 -0
- package/README.md +4 -0
- package/bin/cad.mjs +13 -2
- package/lib/links.mjs +15 -1
- package/lib/motorsvg.mjs +73 -0
- package/lib/preview.mjs +3 -1
- package/package.json +2 -2
package/EXAMPLES.md
CHANGED
|
@@ -977,6 +977,256 @@ on the pinion's axis, the force reaching the slide against the 1 N it has to pus
|
|
|
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
979
|
|
|
980
|
+
### The spool winder, driven
|
|
981
|
+
|
|
982
|
+
The winder from chapter 9 with an N20 gear motor where the crank was, so it winds at a steady speed. The motor turns
|
|
983
|
+
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
|
|
984
|
+
moves onto the carrier. What changes:
|
|
985
|
+
|
|
986
|
+
- 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
|
|
987
|
+
ring for feet tall enough to stand it over the motor.
|
|
988
|
+
- The sun takes the motor's D-shaft with `v.motors.bore`, and keeps its 8 mm shaft, which the spool now turns on.
|
|
989
|
+
- The carrier and the spool are one part, printed upside down: the outer cheek on the bed, the drum, a 45° cone out
|
|
990
|
+
to the carrier's plate (the spool's inner cheek, printed without supports), and the planets' pins on top. The drum
|
|
991
|
+
is hollow, open on the bed, under a roof that closes in at 45°.
|
|
992
|
+
- The handle goes. The ring and the planets are the hand winder's.
|
|
993
|
+
|
|
994
|
+
The N20's figures are Pololu's, for its 100:1 gearbox. Unbranded N20s look the same and vary widely: treat a cheap
|
|
995
|
+
one's torque as about half until it has been measured.
|
|
996
|
+
|
|
997
|
+
```json projects/home/objects/winder-base.json
|
|
998
|
+
{
|
|
999
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1000
|
+
"name": "winder-base",
|
|
1001
|
+
"title": "Winder base for an N20",
|
|
1002
|
+
"version": "0.1.0",
|
|
1003
|
+
"uses": ["x1c"],
|
|
1004
|
+
"engine": "manifold",
|
|
1005
|
+
"variables": {
|
|
1006
|
+
"radius": { "value": 33, "unit": "mm", "rule": "The ring's rim: as the hand winder's case" },
|
|
1007
|
+
"rim": { "value": "x1c.line * 14", "unit": "mm", "rule": "The rim under the ring's, wide enough for its push pins" },
|
|
1008
|
+
"snap": { "value": 2, "unit": "mm", "rule": "Two push pins hold the ring still: their shafts" },
|
|
1009
|
+
"snap_lip": { "value": 0.3, "unit": "mm", "rule": "The barb's lip, clicking over the floor of the ring's counterbore" },
|
|
1010
|
+
"snap_back": { "value": 90, "unit": "deg", "rule": "A square back: it holds for good" },
|
|
1011
|
+
"snap_at": { "value": 30.6, "unit": "mm", "rule": "Halfway across the ring's rim, between its roots and its outside" },
|
|
1012
|
+
"snap_length": { "value": 4, "unit": "mm", "rule": "Up the ring's 6 mm rim to its 2 mm counterbore" },
|
|
1013
|
+
"flange": { "value": 2, "unit": "mm", "rule": "A push pin's foot flange, buried in the rim" },
|
|
1014
|
+
"hub": { "value": 14, "unit": "mm", "rule": "Round the N20's face: its two M1.6 holes 9 mm apart, with a wall outside them" },
|
|
1015
|
+
"spoke": { "value": "x1c.line * 12", "unit": "mm", "rule": "Three spokes from the hub to the rim" },
|
|
1016
|
+
"spokes": { "value": 3, "rule": "Three: it stands without rocking" },
|
|
1017
|
+
"t": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Base, fifteen layers" },
|
|
1018
|
+
"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" },
|
|
1019
|
+
"ear": { "value": 10, "unit": "mm", "rule": "An ear's width, round its screw" },
|
|
1020
|
+
"hole": { "value": "3 + x1c.hole_comp + x1c.fit * 2", "unit": "mm", "rule": "M3 clearance for a foot's screw" }
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
```
|
|
1024
|
+
|
|
1025
|
+
```js projects/home/objects/winder-base.js
|
|
1026
|
+
// 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
|
|
1027
|
+
// ears reach out past the ring, a quarter turn round from the spokes, for the feet that stand it over the motor.
|
|
1028
|
+
import jscad from '@jscad/modeling'
|
|
1029
|
+
const { cylinder, cuboid } = jscad.primitives
|
|
1030
|
+
const { rotateZ, translate } = jscad.transforms
|
|
1031
|
+
|
|
1032
|
+
export function main (v) {
|
|
1033
|
+
const motor = v.motors.motorModel('n20')
|
|
1034
|
+
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] }))
|
|
1035
|
+
const turn = (k) => (2 * Math.PI * k) / v.spokes
|
|
1036
|
+
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] })))
|
|
1037
|
+
const ears = Array.from({ length: v.spokes }, (_, k) => rotateZ(turn(k) + Math.PI / 2, v.ops.union(
|
|
1038
|
+
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] }),
|
|
1039
|
+
cylinder({ radius: v.ear / 2, height: v.t, center: [v.ear_at, 0, v.t / 2] }))))
|
|
1040
|
+
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] })))
|
|
1041
|
+
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)))
|
|
1042
|
+
const body = v.ops.union(rim, cylinder({ radius: v.hub / 2, height: v.t, center: [0, 0, v.t / 2] }), ...spokes, ...ears, ...snaps)
|
|
1043
|
+
return v.ops.subtract(body, v.motors.mount(motor, { plate: v.t, screw: 'M1.6' }, v.ops), ...holes)
|
|
1044
|
+
}
|
|
1045
|
+
```
|
|
1046
|
+
|
|
1047
|
+
```json projects/home/objects/winder-foot.json
|
|
1048
|
+
{
|
|
1049
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1050
|
+
"name": "winder-foot",
|
|
1051
|
+
"title": "Winder foot",
|
|
1052
|
+
"version": "0.1.0",
|
|
1053
|
+
"uses": ["x1c"],
|
|
1054
|
+
"variables": {
|
|
1055
|
+
"height": { "value": 32, "unit": "mm", "rule": "Under the motor: its 25 mm, its terminals, and room for the wires to bend" },
|
|
1056
|
+
"size": { "value": 10, "unit": "mm", "rule": "As wide as the base's ear" },
|
|
1057
|
+
"hole": { "value": 2.9, "unit": "mm", "rule": "M3 screw, self-tapped into the plastic" },
|
|
1058
|
+
"depth": { "value": 12, "unit": "mm", "rule": "Plenty for an M3 × 16 through the 3 mm ear" }
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
```
|
|
1062
|
+
|
|
1063
|
+
```js projects/home/objects/winder-foot.js
|
|
1064
|
+
// A foot under each of the base's ears, screwed on from above.
|
|
1065
|
+
import jscad from '@jscad/modeling'
|
|
1066
|
+
const { cylinder } = jscad.primitives
|
|
1067
|
+
|
|
1068
|
+
export function main (v) {
|
|
1069
|
+
const block = cylinder({ radius: v.size / 2, height: v.height, center: [0, 0, v.height / 2] })
|
|
1070
|
+
return v.ops.subtract(block, cylinder({ radius: v.hole / 2, height: v.depth, center: [0, 0, v.height - v.depth / 2] }))
|
|
1071
|
+
}
|
|
1072
|
+
```
|
|
1073
|
+
|
|
1074
|
+
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
|
|
1075
|
+
the base and the gap under the sun.
|
|
1076
|
+
|
|
1077
|
+
```json projects/home/objects/winder-drive.json
|
|
1078
|
+
{
|
|
1079
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1080
|
+
"name": "winder-drive",
|
|
1081
|
+
"title": "Winder sun on the motor",
|
|
1082
|
+
"version": "0.1.0",
|
|
1083
|
+
"uses": ["x1c"],
|
|
1084
|
+
"engine": "manifold",
|
|
1085
|
+
"anchors": { "axis": { "at": [0, 0, 0], "axis": [0, 0, 1] } },
|
|
1086
|
+
"variables": {
|
|
1087
|
+
"module": { "value": 1, "unit": "mm", "rule": "As the ring" },
|
|
1088
|
+
"teeth": { "value": 18, "rule": "From planetary()" },
|
|
1089
|
+
"width": { "value": "x1c.layer * 30", "unit": "mm", "rule": "As the ring" },
|
|
1090
|
+
"shaft": { "value": 8, "unit": "mm", "rule": "The reel turns on it, inside the sun's roots" },
|
|
1091
|
+
"shaft_height": { "value": 12, "unit": "mm", "rule": "Up through the reel's plate and into its cone" },
|
|
1092
|
+
"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" }
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
```
|
|
1096
|
+
|
|
1097
|
+
```js projects/home/objects/winder-drive.js
|
|
1098
|
+
// The sun with the N20's D-shaft in it, and the 8 mm shaft above that carries the reel.
|
|
1099
|
+
import jscad from '@jscad/modeling'
|
|
1100
|
+
const { cylinder } = jscad.primitives
|
|
1101
|
+
|
|
1102
|
+
export function main (v) {
|
|
1103
|
+
const motor = v.motors.motorModel('n20')
|
|
1104
|
+
const gear = v.gears.spur({ module: v.module, teeth: v.teeth, width: v.width })
|
|
1105
|
+
const shaft = cylinder({ radius: v.shaft / 2, height: v.shaft_height, center: [0, 0, v.width + v.shaft_height / 2] })
|
|
1106
|
+
return v.ops.subtract(v.ops.union(gear, shaft), v.motors.bore(motor, { depth: v.width + v.shaft_height, tip: v.tip }, v.ops))
|
|
1107
|
+
}
|
|
1108
|
+
```
|
|
1109
|
+
|
|
1110
|
+
```json projects/home/objects/winder-reel.json
|
|
1111
|
+
{
|
|
1112
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1113
|
+
"name": "winder-reel",
|
|
1114
|
+
"title": "Winder reel and carrier",
|
|
1115
|
+
"version": "0.1.0",
|
|
1116
|
+
"uses": ["x1c"],
|
|
1117
|
+
"engine": "manifold",
|
|
1118
|
+
"anchors": {
|
|
1119
|
+
"axis": { "at": [0, 0, "base"], "axis": [0, 0, -1] },
|
|
1120
|
+
"p0": { "at": ["a", 0, "base + t + drop"], "axis": [0, 0, -1] },
|
|
1121
|
+
"p1": { "at": ["0 - a / 2", "a * 0.8660254", "base + t + drop"], "axis": [0, 0, -1] },
|
|
1122
|
+
"p2": { "at": ["0 - a / 2", "0 - a * 0.8660254", "base + t + drop"], "axis": [0, 0, -1] }
|
|
1123
|
+
},
|
|
1124
|
+
"variables": {
|
|
1125
|
+
"a": { "value": 18, "unit": "mm", "rule": "Sun to planet: m (S + P) / 2" },
|
|
1126
|
+
"drop": { "value": "6 + x1c.layer * 2", "unit": "mm", "rule": "A planet's width and two layers' gap above it" },
|
|
1127
|
+
"radius": { "value": 22, "unit": "mm", "rule": "The carrier's plate: past the planets' pins (18 mm out, 1.5 mm round) by four lines" },
|
|
1128
|
+
"t": { "value": "x1c.layer * 15", "unit": "mm", "rule": "The plate, fifteen layers" },
|
|
1129
|
+
"hole": { "value": 9, "unit": "mm", "rule": "Round the sun's 8 mm shaft, which it turns on" },
|
|
1130
|
+
"pin": { "value": 3, "unit": "mm", "rule": "The planets' axles" },
|
|
1131
|
+
"planets": { "value": 3, "rule": "From planetary(): three planets" },
|
|
1132
|
+
"drum": { "value": 24, "unit": "mm", "rule": "The spool's core: a strap bends round it easily" },
|
|
1133
|
+
"wall": { "value": "x1c.line * 4", "unit": "mm", "rule": "The drum's wall: four lines" },
|
|
1134
|
+
"length": { "value": 16, "unit": "mm", "rule": "A 15 mm strap and a millimetre" },
|
|
1135
|
+
"cheek": { "value": 40, "unit": "mm", "rule": "The outer cheek: a few turns of strap" },
|
|
1136
|
+
"cheek_t": { "value": "x1c.layer * 6", "unit": "mm", "rule": "Six layers, on the bed" },
|
|
1137
|
+
"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" }
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
```
|
|
1141
|
+
|
|
1142
|
+
```js projects/home/objects/winder-reel.js
|
|
1143
|
+
// The carrier and the spool in one part, printed upside down: the outer cheek on the bed, the drum, a 45° cone out to
|
|
1144
|
+
// the carrier's plate, and the planets' pins standing up from it. The assembly turns it over.
|
|
1145
|
+
import jscad from '@jscad/modeling'
|
|
1146
|
+
const { cylinder, cylinderElliptic } = jscad.primitives
|
|
1147
|
+
|
|
1148
|
+
export function main (v) {
|
|
1149
|
+
const cone = v.base - v.cheek_t - v.length
|
|
1150
|
+
const cheek = cylinder({ radius: v.cheek / 2, height: v.cheek_t, center: [0, 0, v.cheek_t / 2] })
|
|
1151
|
+
const drum = cylinder({ radius: v.drum / 2, height: v.length, center: [0, 0, v.cheek_t + v.length / 2] })
|
|
1152
|
+
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] })
|
|
1153
|
+
const plate = cylinder({ radius: v.radius, height: v.t, center: [0, 0, v.base + v.t / 2] })
|
|
1154
|
+
const third = (2 * Math.PI) / v.planets
|
|
1155
|
+
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] }))
|
|
1156
|
+
const hole = cylinder({ radius: v.hole / 2, height: v.base + v.t, center: [0, 0, (v.base + v.t) / 2] })
|
|
1157
|
+
// hollow inside the drum, open on the bed, its roof closing in at 45° to the bore so it prints without supports
|
|
1158
|
+
const inside = v.drum / 2 - v.wall, roof = inside - v.hole / 2, deep = v.cheek_t + v.length
|
|
1159
|
+
const hollow = v.ops.union(cylinder({ radius: inside, height: deep, center: [0, 0, deep / 2] }),
|
|
1160
|
+
cylinderElliptic({ height: roof, startRadius: [inside, inside], endRadius: [v.hole / 2, v.hole / 2], center: [0, 0, deep + roof / 2] }))
|
|
1161
|
+
return v.ops.subtract(v.ops.union(cheek, drum, flare, plate, ...pins), hole, hollow)
|
|
1162
|
+
}
|
|
1163
|
+
```
|
|
1164
|
+
|
|
1165
|
+
The motor drives the sun, and the planetary takes the rest: `"drive": "sun"`. The load is the strap: 10 N at the
|
|
1166
|
+
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
|
|
1167
|
+
0.2 N m, 1.5 times over. Pololu sells the same motor at 150:1, and `"set": { "ratio": 150 }` scales the torque and
|
|
1168
|
+
speed to it.
|
|
1169
|
+
|
|
1170
|
+
```json projects/home/assemblies/winder-driven.json
|
|
1171
|
+
{
|
|
1172
|
+
"title": "Motorised spool winder",
|
|
1173
|
+
"kind": "fit",
|
|
1174
|
+
"items": [
|
|
1175
|
+
{ "id": "base", "object": "winder-base" },
|
|
1176
|
+
{ "id": "foot_a", "object": "winder-foot", "at": [0, "base.ear_at", "0 - foot_a.height"] },
|
|
1177
|
+
{ "id": "foot_b", "object": "winder-foot", "at": ["0 - base.ear_at * 0.8660254", "0 - base.ear_at / 2", "0 - foot_b.height"] },
|
|
1178
|
+
{ "id": "foot_c", "object": "winder-foot", "at": ["base.ear_at * 0.8660254", "0 - base.ear_at / 2", "0 - foot_c.height"] },
|
|
1179
|
+
{ "id": "drive", "motor": { "model": "n20", "set": { "ratio": 150 }, "drives": "sun", "screw": "M1.6" } },
|
|
1180
|
+
{ "id": "ring", "object": "winder-ring", "at": [0, 0, "base.t"] },
|
|
1181
|
+
{ "id": "sun", "object": "winder-drive" },
|
|
1182
|
+
{ "id": "reel", "object": "winder-reel" },
|
|
1183
|
+
{ "id": "p0", "object": "winder-gear" },
|
|
1184
|
+
{ "id": "p1", "object": "winder-gear" },
|
|
1185
|
+
{ "id": "p2", "object": "winder-gear" }
|
|
1186
|
+
],
|
|
1187
|
+
"joints": [
|
|
1188
|
+
{ "id": "sun", "type": "revolute", "parent": { "item": "base", "at": [0, 0, "base.t + 0.4"], "axis": [0, 0, 1] }, "child": "sun.axis", "label": "Motor" },
|
|
1189
|
+
{ "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 },
|
|
1190
|
+
{ "id": "p0", "type": "revolute", "parent": "reel.p0", "child": "p0.axis", "min": -3000, "max": 3000 },
|
|
1191
|
+
{ "id": "p1", "type": "revolute", "parent": "reel.p1", "child": "p1.axis", "min": -3000, "max": 3000 },
|
|
1192
|
+
{ "id": "p2", "type": "revolute", "parent": "reel.p2", "child": "p2.axis", "min": -3000, "max": 3000 }
|
|
1193
|
+
],
|
|
1194
|
+
"planetary": [
|
|
1195
|
+
{ "sun": "sun", "carrier": "reel", "ring": "ring", "planets": ["p0", "p1", "p2"], "drive": "sun",
|
|
1196
|
+
"module": "ring.module", "teeth": ["sun.teeth", "p0.teeth", "ring.teeth"] }
|
|
1197
|
+
],
|
|
1198
|
+
"fits": [
|
|
1199
|
+
{ "a": "ring", "b": "base", "fastens": true, "note": "The ring held still on the base by its two push pins" },
|
|
1200
|
+
{ "a": "drive", "b": "base", "fastens": true, "min": 0, "note": "The motor, on its two M1.6 screws" },
|
|
1201
|
+
{ "a": "drive", "b": "sun", "shaft": true, "note": "The motor's shaft in the sun" },
|
|
1202
|
+
{ "a": "foot_a", "b": "base", "fastens": true, "min": 0, "note": "A foot, screwed on" },
|
|
1203
|
+
{ "a": "foot_b", "b": "base", "fastens": true, "min": 0, "note": "A foot, screwed on" },
|
|
1204
|
+
{ "a": "foot_c", "b": "base", "fastens": true, "min": 0, "note": "A foot, screwed on" }
|
|
1205
|
+
],
|
|
1206
|
+
"loads": [{ "joint": "reel", "torque": 0.2, "note": "A strap pulled with 10 N at the full spool's 20 mm radius" }],
|
|
1207
|
+
"poses": { "rest": { "sun": 0 } }
|
|
1208
|
+
}
|
|
1209
|
+
```
|
|
1210
|
+
|
|
1211
|
+
```sh
|
|
1212
|
+
npx cad check home/winder-driven # warns: nothing says whether it holds with the power off
|
|
1213
|
+
npx cad check home/winder-driven --sweep --steps 12 # warns, as above
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
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
|
|
1217
|
+
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
|
|
1218
|
+
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
|
|
1219
|
+
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`
|
|
1220
|
+
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
|
|
1221
|
+
40 rpm. Printed, it's 51 g in ten parts, the reel 19 g of it.
|
|
1222
|
+
|
|
1223
|
+
It warns that nothing says whether the spool holds with the power off. It doesn't: an N20's spur gearbox can be turned
|
|
1224
|
+
back from its shaft, and the planetary is no help, since a pull on the reel turns the motor four times as fast the
|
|
1225
|
+
easy way. A ratchet on the reel holds it: the strap tensioner in `examples/bench/projects/gears` has one. Draw it on,
|
|
1226
|
+
give the reel's joint `"brake": "the ratchet"`, and the check passes it. Print the winder and report two things: how
|
|
1227
|
+
fast it winds against a known weight, and whether the spool runs back when the power goes. They become the N20's
|
|
1228
|
+
measured figures.
|
|
1229
|
+
|
|
980
1230
|
## 11. A robot joint: a stepper through a compound planetary
|
|
981
1231
|
|
|
982
1232
|
A shoulder for a small desktop arm: a NEMA 17 turning a 38:1 gearbox on one axis, 500 g at 150 mm on the output. The
|
package/README.md
CHANGED
|
@@ -93,6 +93,9 @@ fragment, which never reaches the web host, so the public page can open private
|
|
|
93
93
|
which version it holds (`keyboard/keycap@0.1.0`, or `+changes` if it isn't a release). The page is `@rulecad/viewer`: host your
|
|
94
94
|
own copy anywhere and name it in `viewUrl`.
|
|
95
95
|
|
|
96
|
+
- **Circuit boards:** a board's link also carries its fab zip, the same one `cad export` writes (Gerbers, drill files,
|
|
97
|
+
parts list, placement; plotted by KiCad where the board needs it). The page offers it as **Download for JLCPCB**. A
|
|
98
|
+
board whose zip can't be made here (one that needs KiCad, without it) goes without, and `cad link` says why.
|
|
96
99
|
- **Rules:** a link carries the model's values and the rules they use (value, source, kind, date checked) for the
|
|
97
100
|
page's Rules panel; estimates are marked there. A rule set with `"private": true` stays out of links, and
|
|
98
101
|
`--no-rules` leaves the list out altogether. Anyone with a link can read what it carries.
|
|
@@ -417,6 +420,7 @@ An item can be a motor instead of a printed object: `{ "id": "drive", "motor": {
|
|
|
417
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. How far the whole part bends isn't checked yet.
|
|
418
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.
|
|
419
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.
|
|
420
424
|
|
|
421
425
|
### Building it
|
|
422
426
|
|
package/bin/cad.mjs
CHANGED
|
@@ -627,10 +627,10 @@ async function board(cmd, d, b, { title, version, tag }) {
|
|
|
627
627
|
// board and schematic beside it, and the matrix for firmware
|
|
628
628
|
const dir = paths.exports(d.project), { zip: zipOf } = await import('@rulecad/model-link');
|
|
629
629
|
fs.mkdirSync(dir, { recursive: true });
|
|
630
|
-
const fab = await pcb.fabFiles(b.circuit, d.name), zip = path.join(dir, `${name}-fab.zip`);
|
|
630
|
+
const fab = await pcb.fabFiles(b.circuit, d.name, { source: b.source }), zip = path.join(dir, `${name}-fab.zip`);
|
|
631
631
|
fs.writeFileSync(zip, await zipOf(Object.entries(fab)));
|
|
632
632
|
const written = [zip];
|
|
633
|
-
for (const [f, t] of Object.entries(await pcb.kicadFiles(b.circuit, name))) { fs.writeFileSync(path.join(dir, f), t); written.push(path.join(dir, f)); }
|
|
633
|
+
for (const [f, t] of Object.entries(await pcb.kicadFiles(b.circuit, name, { source: b.source }))) { fs.writeFileSync(path.join(dir, f), t); written.push(path.join(dir, f)); }
|
|
634
634
|
if (b.matrix) { const f = path.join(dir, `${name}-matrix.json`); fs.writeFileSync(f, JSON.stringify(b.matrix, null, 2) + '\n'); written.push(f); }
|
|
635
635
|
const done = [{ level: 'pass', text: `fab zip: ${Object.keys(fab).length} files (${Object.keys(fab).filter((f) => !/\.(csv|DRL)$/.test(f)).length} Gerber layers, 2 drill files, BOM, placement)` }];
|
|
636
636
|
if (opt('json')) return console.log(JSON.stringify({ object: `${d.project}/${d.name}`, version, files: written.map((f) => path.relative(WS, f)), findings: done }, null, 2));
|
|
@@ -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/links.mjs
CHANGED
|
@@ -49,10 +49,24 @@ export async function objectModel(b, { title, version, src, set, filaments: fil
|
|
|
49
49
|
rules: b.entries.filter((e) => e.show).map((e) => [e.label || e.name, fmt(e.value), e.unit || '']),
|
|
50
50
|
...sheet([[b.object.name, b.entries]], { noRules }),
|
|
51
51
|
...(b.circuit ? { views: await (await pcbEngine()).views(b.circuit) } : {}), // boards: the 2D board and schematic
|
|
52
|
+
...(b.circuit ? await fabOf([[b.object.name, version, b]]) : {}), // and the zip to order it with
|
|
52
53
|
...fromParts(b.parts.map((p) => ({ name: p.name, role: p.role, label: p.label, slot: slotOf(fil, p.filament), triangles: triangles(p.triangles) }))),
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
// Each board's fab zip (cad export's: Gerbers, drill files, BOM, placement), for the page to offer as a download. A
|
|
58
|
+
// board whose files can't be made here (one that needs KiCad, without it) goes without, and says why
|
|
59
|
+
async function fabOf(boards) {
|
|
60
|
+
const pcb = await pcbEngine(), { zip } = await import('@rulecad/model-link'), fab = [];
|
|
61
|
+
for (const [name, version, b] of boards) {
|
|
62
|
+
try {
|
|
63
|
+
const files = await pcb.fabFiles(b.circuit, name, { source: b.source });
|
|
64
|
+
fab.push({ name: `${name}${version ? `@${version}` : ''}-fab.zip`.replace(/[^\w@.+-]/g, '-'), zip: Buffer.from(await zip(Object.entries(files))).toString('base64') });
|
|
65
|
+
} catch (e) { console.error(` ${name}: no fab zip in the link (${String(e.message || e).split('\n')[0]})`); }
|
|
66
|
+
}
|
|
67
|
+
return fab.length ? { fab } : {};
|
|
68
|
+
}
|
|
69
|
+
|
|
56
70
|
/** A built assembly as a model: each shape once and placed (nine keys cost one keycap), its boards' views, its joints. */
|
|
57
71
|
export async function assemblyModel(s, { title, versions, filaments: fil = {}, noRules = false, steps }) {
|
|
58
72
|
const placed = shapes(s.parts), list = placed.shapes.length ? placed.place.map(([i, ...m], n) => { const p = placed.shapes[i].part; return { shape: i, role: p.role, label: p.object || p.label, slot: slotOf(fil, p.filament), triangles: triangles(placed.shapes[i].triangles), matrix: m, name: s.parts[n].name }; }) : [];
|
|
@@ -78,7 +92,7 @@ export async function assemblyModel(s, { title, versions, filaments: fil = {}, n
|
|
|
78
92
|
if (!boards.length) return {};
|
|
79
93
|
const pcb = await pcbEngine(), views = [];
|
|
80
94
|
for (const o of boards) for (const [n, svg] of await pcb.views(o.built.circuit)) views.push([boards.length > 1 ? `${o.objName} ${n}` : n, svg]);
|
|
81
|
-
return { views };
|
|
95
|
+
return { views, ...(await fabOf(boards.map((o) => [o.objName, o.version || o.built.object?.version, o.built]))) };
|
|
82
96
|
})()),
|
|
83
97
|
...fromShapes(list),
|
|
84
98
|
};
|
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.45",
|
|
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": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@rulecad/keyboard-layout": "^0.1.2",
|
|
62
62
|
"@rulecad/printcheck": "^0.3.0",
|
|
63
63
|
"@rulecad/fit": "^0.4.0",
|
|
64
|
-
"@rulecad/model-link": "^0.3.
|
|
64
|
+
"@rulecad/model-link": "^0.3.2",
|
|
65
65
|
"@rulecad/versions": "^0.1.0",
|
|
66
66
|
"@rulecad/shapes": "^0.4.4",
|
|
67
67
|
"@rulecad/rules": "^0.3.9",
|