@rulecad/cad 0.7.37 → 0.7.40
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 +423 -1
- package/README.md +14 -0
- package/bin/cad.mjs +31 -1
- package/lib/assembly.mjs +40 -11
- package/lib/design.mjs +4 -3
- package/lib/motors.mjs +265 -0
- package/lib/sandbox-hooks.mjs +2 -2
- package/lib/sandbox-run.mjs +2 -1
- package/lib/sandbox.mjs +1 -1
- package/lib/sheet.mjs +136 -0
- package/package.json +5 -4
- package/schemas/assembly.schema.json +6 -0
- package/schemas/rules.schema.json +3 -0
package/EXAMPLES.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[The tutorial](TUTORIAL.md) ends with a wall hook checked against its screw. These examples carry on from there, one
|
|
4
4
|
for each thing the [README](README.md) describes after that: parts, variants and releases, joints and poses, a model
|
|
5
|
-
from elsewhere, an optimised part, a board, a mechanism printed flat, gears, and a
|
|
5
|
+
from elsewhere, an optimised part, a board, a mechanism printed flat, gears, a gearbox, a motor, and a robot joint. Each is a few files and the commands to run
|
|
6
6
|
them. The tests write every file here and run every command, so what you read is what works.
|
|
7
7
|
|
|
8
8
|
They start from a workspace `npm create rulecad my-designs` makes, as the tutorial does, and run in order: later
|
|
@@ -819,3 +819,425 @@ The check says `the carrier drives the sun and the planets (the ring held): 4 tu
|
|
|
819
819
|
carrier, the same way`, and each planet's centre distance and contact ratio. The sweep turns the crank from −180° to
|
|
820
820
|
180°, the sun four times as far, and looks for anything that touches. Move a planet's anchor off its 120° and the
|
|
821
821
|
check fails it: it can't mesh with the sun and the ring at once there.
|
|
822
|
+
|
|
823
|
+
## 10. A motor: the focus slider, driven
|
|
824
|
+
|
|
825
|
+
The same slide, with a 28BYJ-48 geared stepper in place of the knob: 5 V, a few pounds to buy, slow and strong. A motor in an
|
|
826
|
+
assembly is an item with `"motor"`, drawn from `@rulecad/motors`, bought and not printed. Its shaft turns the joint it
|
|
827
|
+
drives, the viewer's slider moves in the motor's steps, and `loads` say what it has to do. Its figures come with their
|
|
828
|
+
kinds: the 28BYJ-48's torque varies between makers, and the check says what its answer rests on.
|
|
829
|
+
|
|
830
|
+
The pinion takes the motor's shaft, two flats and all, with `v.motors.bore`. The motor sits under the plate, shaft up
|
|
831
|
+
through it, so its body needs room below: two feet stand the rail up.
|
|
832
|
+
|
|
833
|
+
```json projects/home/objects/drive-pinion.json
|
|
834
|
+
{
|
|
835
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
836
|
+
"name": "drive-pinion",
|
|
837
|
+
"title": "Motor pinion",
|
|
838
|
+
"version": "0.1.0",
|
|
839
|
+
"uses": ["x1c"],
|
|
840
|
+
"engine": "manifold",
|
|
841
|
+
"anchors": { "axis": { "at": [0, 0, "0 - gap"], "axis": [0, 0, 1] } },
|
|
842
|
+
"variables": {
|
|
843
|
+
"module": { "value": 1, "unit": "mm", "rule": "As the rack" },
|
|
844
|
+
"teeth": { "value": 14, "rule": "As the knob's pinion" },
|
|
845
|
+
"shift": { "value": 0.2, "rule": "14 teeth need at least 0.19" },
|
|
846
|
+
"width": { "value": "x1c.layer * 30", "unit": "mm", "rule": "The rack's width" },
|
|
847
|
+
"gap": { "value": "x1c.layer + 0.1", "unit": "mm", "rule": "Clear of the plate" },
|
|
848
|
+
"tip": { "value": 5.1, "unit": "mm", "rule": "Where the shaft's tip is from the pinion's underside: 10 mm of shaft less the 4.6 mm plate and the gap" }
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
```
|
|
852
|
+
|
|
853
|
+
```js projects/home/objects/drive-pinion.js
|
|
854
|
+
// A pinion with the motor's shaft in it: the flats of the bore run only as far as the shaft's flats do.
|
|
855
|
+
export function main (v) {
|
|
856
|
+
const motor = v.motors.motorModel('28byj48')
|
|
857
|
+
return v.ops.subtract(v.gears.spur({ module: v.module, teeth: v.teeth, shift: v.shift, width: v.width }), v.motors.bore(motor, { depth: v.width, tip: v.tip }, v.ops))
|
|
858
|
+
}
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
```json projects/home/objects/drive-rail.json
|
|
862
|
+
{
|
|
863
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
864
|
+
"name": "drive-rail",
|
|
865
|
+
"title": "Motor rail",
|
|
866
|
+
"version": "0.1.0",
|
|
867
|
+
"uses": ["x1c"],
|
|
868
|
+
"engine": "manifold",
|
|
869
|
+
"anchors": {
|
|
870
|
+
"axle": { "at": [0, "centre", "thick"], "axis": [0, 0, 1] },
|
|
871
|
+
"track": { "at": ["start", 0, "thick"], "axis": [1, 0, 0] }
|
|
872
|
+
},
|
|
873
|
+
"variables": {
|
|
874
|
+
"centre": { "value": 7.2, "unit": "mm", "rule": "The pinion's axis above the rack's pitch line: m z / 2 + x m" },
|
|
875
|
+
"length": { "value": 120, "unit": "mm", "rule": "The rack and its travel" },
|
|
876
|
+
"start": { "value": -37.7, "unit": "mm", "rule": "The rack's middle under the pinion at rest" },
|
|
877
|
+
"thick": { "value": "x1c.layer * 23", "unit": "mm", "rule": "23 layers: the motor's boss pocket, and enough for its M3 screws" },
|
|
878
|
+
"y0": { "value": -14.5, "unit": "mm", "rule": "Past the motor's near ear" },
|
|
879
|
+
"y1": { "value": 29, "unit": "mm", "rule": "Past its far ear, 17.5 mm off the axis" },
|
|
880
|
+
"plate": { "value": 26, "unit": "mm", "rule": "Wide enough round the motor's boss and its ears" },
|
|
881
|
+
"guide_y": { "value": "0 - 5.45 - x1c.line / 2", "unit": "mm", "rule": "Behind the rack's back, half a line clear" },
|
|
882
|
+
"guide": { "value": "x1c.line * 4", "unit": "mm", "rule": "The guide wall: four lines" },
|
|
883
|
+
"guide_height": { "value": "x1c.layer * 20", "unit": "mm", "rule": "Most of the rack's width" },
|
|
884
|
+
"hole": { "value": 3.5, "unit": "mm", "rule": "M3 clearance, for the feet" },
|
|
885
|
+
"foot_x": { "value": 52, "unit": "mm", "rule": "Each foot's screw, from the middle" },
|
|
886
|
+
"foot_y": { "value": -11, "unit": "mm", "rule": "On the strip, behind the guide" }
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
```js projects/home/objects/drive-rail.js
|
|
892
|
+
// The rail: a strip under the rack, a plate for the motor (turned 90° on its shaft, so its ears clear the rack), a wall
|
|
893
|
+
// behind the rack, and the motor's own cuts.
|
|
894
|
+
import jscad from '@jscad/modeling'
|
|
895
|
+
const { cuboid, cylinder } = jscad.primitives
|
|
896
|
+
const { translate, rotateZ } = jscad.transforms
|
|
897
|
+
|
|
898
|
+
export function main (v) {
|
|
899
|
+
const motor = v.motors.motorModel('28byj48')
|
|
900
|
+
const strip = cuboid({ size: [v.length, 12, v.thick], center: [0, v.y0 + 6, v.thick / 2] })
|
|
901
|
+
const seat = cuboid({ size: [v.plate, v.y1 - v.y0, v.thick], center: [8, (v.y0 + v.y1) / 2, v.thick / 2] })
|
|
902
|
+
const guide = cuboid({ size: [v.length, v.guide, v.guide_height], center: [0, v.guide_y - v.guide / 2, v.thick + v.guide_height / 2] })
|
|
903
|
+
const cuts = translate([0, v.centre, 0], rotateZ(Math.PI / 2, v.motors.mount(motor, { plate: v.thick, screw: 'M3' }, v.ops)))
|
|
904
|
+
const screws = [1, -1].map((s) => cylinder({ radius: v.hole / 2, height: v.thick + 2, center: [s * v.foot_x, v.foot_y, v.thick / 2] }))
|
|
905
|
+
return v.ops.subtract(v.ops.union(strip, seat, guide), cuts, screws)
|
|
906
|
+
}
|
|
907
|
+
```
|
|
908
|
+
|
|
909
|
+
```json projects/home/objects/drive-foot.json
|
|
910
|
+
{
|
|
911
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
912
|
+
"name": "drive-foot",
|
|
913
|
+
"title": "Rail foot",
|
|
914
|
+
"version": "0.1.0",
|
|
915
|
+
"uses": ["x1c"],
|
|
916
|
+
"variables": {
|
|
917
|
+
"height": { "value": 21, "unit": "mm", "rule": "Under the motor: its 19 mm can and 2 mm to the table" },
|
|
918
|
+
"size": { "value": 12, "unit": "mm", "rule": "As wide as the strip" },
|
|
919
|
+
"long": { "value": 28, "unit": "mm", "rule": "Across the strip's end, for a stance that doesn't rock" },
|
|
920
|
+
"hole": { "value": 2.9, "unit": "mm", "rule": "M3 screw, self-tapped into the plastic" },
|
|
921
|
+
"depth": { "value": 12, "unit": "mm", "rule": "Plenty for an M3 × 16" }
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
```js projects/home/objects/drive-foot.js
|
|
927
|
+
// A foot: a block under each end of the rail, screwed on from above.
|
|
928
|
+
import jscad from '@jscad/modeling'
|
|
929
|
+
const { cuboid, cylinder } = jscad.primitives
|
|
930
|
+
const { subtract } = jscad.booleans
|
|
931
|
+
|
|
932
|
+
export function main (v) {
|
|
933
|
+
const block = cuboid({ size: [v.size, v.long, v.height], center: [0, 0, v.height / 2] })
|
|
934
|
+
return subtract(block, cylinder({ radius: v.hole / 2, height: v.depth, center: [0, 0, v.height - v.depth / 2] }))
|
|
935
|
+
}
|
|
936
|
+
```
|
|
937
|
+
|
|
938
|
+
The assembly says the motor drives the pinion's joint, the slide follows by its `mesh`, and the load is a force on the
|
|
939
|
+
slide: a 200 g camera on a rail with the friction of plastic on plastic, about 1 N. The `shaft` fit reads the bore from
|
|
940
|
+
the pinion as drawn. `duty` says the motor runs a fifth of the time, since a focus stack is mostly standing still.
|
|
941
|
+
|
|
942
|
+
```json projects/home/assemblies/driven.json
|
|
943
|
+
{
|
|
944
|
+
"title": "Motorised focus slider",
|
|
945
|
+
"kind": "fit",
|
|
946
|
+
"items": [
|
|
947
|
+
{ "id": "rail", "object": "drive-rail" },
|
|
948
|
+
{ "id": "foot_a", "object": "drive-foot", "at": ["0 - rail.foot_x", "rail.foot_y", "0 - foot_a.height"] },
|
|
949
|
+
{ "id": "foot_b", "object": "drive-foot", "at": ["rail.foot_x", "rail.foot_y", "0 - foot_b.height"] },
|
|
950
|
+
{ "id": "drive", "motor": { "model": "28byj48", "drives": "pinion", "duty": 0.2, "screw": "M3" }, "at": [0, "rail.centre", 0], "rotate": [0, 0, 90] },
|
|
951
|
+
{ "id": "gear", "object": "drive-pinion" },
|
|
952
|
+
{ "id": "rack", "object": "rack" }
|
|
953
|
+
],
|
|
954
|
+
"joints": [
|
|
955
|
+
{ "id": "pinion", "type": "revolute", "parent": "rail.axle", "child": "gear.axis", "label": "Motor" },
|
|
956
|
+
{ "id": "slide", "type": "prismatic", "parent": "rail.track", "child": "rack.slide", "min": -100, "max": 100,
|
|
957
|
+
"mesh": { "with": "pinion", "module": "gear.module", "teeth": ["gear.teeth", "rack.teeth"], "shift": ["gear.shift", 0] } }
|
|
958
|
+
],
|
|
959
|
+
"fits": [
|
|
960
|
+
{ "a": "foot_a", "b": "rail", "fastens": true, "min": 0, "note": "A foot, screwed on" },
|
|
961
|
+
{ "a": "foot_b", "b": "rail", "fastens": true, "min": 0, "note": "A foot, screwed on" },
|
|
962
|
+
{ "a": "drive", "b": "rail", "fastens": true, "min": 0, "note": "The motor, on its two ears" },
|
|
963
|
+
{ "a": "drive", "b": "gear", "shaft": true, "note": "The motor's shaft in the pinion" }
|
|
964
|
+
],
|
|
965
|
+
"loads": [{ "joint": "slide", "force": 1, "note": "A 200 g camera sliding, plastic on plastic" }],
|
|
966
|
+
"poses": { "home": { "pinion": 0 } }
|
|
967
|
+
}
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
```sh
|
|
971
|
+
npx cad check home/driven
|
|
972
|
+
npx cad check home/driven --sweep --steps 12
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
The check says which motor it is and how far a step moves (`0.0879° a step`, or 0.0107 mm of slide), that its shaft is
|
|
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
|
+
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
|
+
turn it back with. The torque's line ends `(rests on community figures: measure it)`, because that's what its torque is.
|
|
979
|
+
|
|
980
|
+
## 11. A robot joint: a stepper through a compound planetary
|
|
981
|
+
|
|
982
|
+
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
|
|
983
|
+
gearbox is a compound planetary: two rings a few teeth apart, one held and one the output, with stepped planets (18 teeth on the
|
|
984
|
+
held ring and the sun, 21 on the output ring). `compoundPlanetary` found the teeth; three planets of 18/21, a sun of 18,
|
|
985
|
+
rings of 54 and 57. The planets are held by the sun and the two rings: there's no carrier to print, and the assembly's
|
|
986
|
+
`carrier` is a speck that's only there to carry the planets' joints. At 38:1 the gearbox is under half efficient, so
|
|
987
|
+
the load can't turn it backwards: the joint holds with the power off.
|
|
988
|
+
|
|
989
|
+
```json projects/home/objects/joint-housing.json
|
|
990
|
+
{
|
|
991
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
992
|
+
"name": "joint-housing",
|
|
993
|
+
"title": "Joint housing and fixed ring",
|
|
994
|
+
"version": "0.1.0",
|
|
995
|
+
"uses": ["x1c"],
|
|
996
|
+
"engine": "manifold",
|
|
997
|
+
"anchors": { "axis": { "at": [0, 0, "plate"], "axis": [0, 0, 1] } },
|
|
998
|
+
"variables": {
|
|
999
|
+
"plate": { "value": 5, "unit": "mm", "rule": "Enough for M3 screws into a NEMA 17 (1.5 × their size)" },
|
|
1000
|
+
"width": { "value": 8, "unit": "mm", "rule": "The fixed ring's face: strong enough for the motor's whole torque" },
|
|
1001
|
+
"rim": { "value": 62, "unit": "mm", "rule": "Round the 54-tooth ring, three lines and more of wall" },
|
|
1002
|
+
"module": { "value": 1, "unit": "mm", "rule": "The gears'" },
|
|
1003
|
+
"teeth": { "value": 54, "rule": "The held ring" },
|
|
1004
|
+
"post_r": { "value": 37, "unit": "mm", "rule": "Three posts outside the output ring's 33 mm" },
|
|
1005
|
+
"post": { "value": 7, "unit": "mm", "rule": "Each post's diameter" },
|
|
1006
|
+
"post_height": { "value": 19.7, "unit": "mm", "rule": "From the plate to under the clips, just over the output ring" },
|
|
1007
|
+
"pilot": { "value": 2.9, "unit": "mm", "rule": "An M3 screw, self-tapped" },
|
|
1008
|
+
"pilot_depth": { "value": 8, "unit": "mm", "rule": "For an M3 × 10" }
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
```
|
|
1012
|
+
|
|
1013
|
+
```js projects/home/objects/joint-housing.js
|
|
1014
|
+
// A motor plate with the fixed ring standing on it. The motor bolts underneath, its shaft up through the middle.
|
|
1015
|
+
import jscad from '@jscad/modeling'
|
|
1016
|
+
const { cylinder } = jscad.primitives
|
|
1017
|
+
const { translate } = jscad.transforms
|
|
1018
|
+
|
|
1019
|
+
export function main (v) {
|
|
1020
|
+
const motor = v.motors.motorModel('nema17')
|
|
1021
|
+
const plate = cylinder({ radius: v.rim / 2, height: v.plate, center: [0, 0, v.plate / 2], segments: 96 })
|
|
1022
|
+
const ring = translate([0, 0, v.plate], v.gears.internal({ module: v.module, teeth: v.teeth, width: v.width, rim: v.rim }))
|
|
1023
|
+
const at = (a) => [v.post_r * Math.cos(a), v.post_r * Math.sin(a)]
|
|
1024
|
+
const angles = [Math.PI / 6, (5 * Math.PI) / 6, (3 * Math.PI) / 2]
|
|
1025
|
+
const lobes = angles.map((a) => cylinder({ radius: v.post, height: v.plate, center: [...at(a), v.plate / 2], segments: 32 }))
|
|
1026
|
+
const posts = angles.map((a) => cylinder({ radius: v.post / 2, height: v.post_height + v.plate, center: [...at(a), (v.post_height + v.plate) / 2], segments: 32 }))
|
|
1027
|
+
const arms = angles.map((a) => jscad.transforms.rotateZ(a, jscad.primitives.cuboid({ size: [v.post_r - v.rim / 2 + 2, v.post, v.plate], center: [(v.post_r + v.rim / 2 - 2) / 2, 0, v.plate / 2] })))
|
|
1028
|
+
const pilots = angles.map((a) => cylinder({ radius: v.pilot / 2, height: v.pilot_depth, center: [...at(a), v.plate + v.post_height - v.pilot_depth / 2], segments: 24 }))
|
|
1029
|
+
return v.ops.subtract(v.ops.union(plate, ring, lobes, posts, arms), v.motors.mount(motor, { plate: v.plate, counterbore: true }, v.ops), pilots)
|
|
1030
|
+
}
|
|
1031
|
+
```
|
|
1032
|
+
|
|
1033
|
+
```json projects/home/objects/joint-sun.json
|
|
1034
|
+
{
|
|
1035
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1036
|
+
"name": "joint-sun",
|
|
1037
|
+
"title": "Sun gear on the motor's shaft",
|
|
1038
|
+
"version": "0.1.0",
|
|
1039
|
+
"uses": ["x1c"],
|
|
1040
|
+
"engine": "manifold",
|
|
1041
|
+
"anchors": { "axis": { "at": [0, 0, "0 - gap"], "axis": [0, 0, 1] } },
|
|
1042
|
+
"variables": {
|
|
1043
|
+
"gap": { "value": 0.3, "unit": "mm", "rule": "Clear of the motor plate" },
|
|
1044
|
+
"module": { "value": 1, "unit": "mm", "rule": "The gears'" },
|
|
1045
|
+
"teeth": { "value": 18, "rule": "As the planets' first step" },
|
|
1046
|
+
"width": { "value": 8, "unit": "mm", "rule": "The first stage" },
|
|
1047
|
+
"hub": { "value": 12, "unit": "mm", "rule": "A hub above the teeth, inside the planets' second step" },
|
|
1048
|
+
"tall": { "value": 16, "unit": "mm", "rule": "Up through both stages, so 12 mm of the shaft's flat is gripped" },
|
|
1049
|
+
"tip": { "value": 18.7, "unit": "mm", "rule": "Where the shaft's 24 mm tip is from the sun's underside, 5.3 mm above the mounting face" }
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
```
|
|
1053
|
+
|
|
1054
|
+
```js projects/home/objects/joint-sun.js
|
|
1055
|
+
// The sun with a hub above it, up through both stages, for grip on the shaft's flat.
|
|
1056
|
+
import jscad from '@jscad/modeling'
|
|
1057
|
+
const { cylinder } = jscad.primitives
|
|
1058
|
+
|
|
1059
|
+
export function main (v) {
|
|
1060
|
+
const motor = v.motors.motorModel('nema17')
|
|
1061
|
+
const gear = v.gears.spur({ module: v.module, teeth: v.teeth, width: v.width })
|
|
1062
|
+
const hub = cylinder({ radius: v.hub / 2, height: v.tall, center: [0, 0, v.tall / 2], segments: 64 })
|
|
1063
|
+
return v.ops.subtract(v.ops.union(gear, hub), v.motors.bore(motor, { depth: v.tall, tip: v.tip }, v.ops))
|
|
1064
|
+
}
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
```json projects/home/objects/joint-planet.json
|
|
1068
|
+
{
|
|
1069
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1070
|
+
"name": "joint-planet",
|
|
1071
|
+
"title": "Stepped planet",
|
|
1072
|
+
"version": "0.1.0",
|
|
1073
|
+
"uses": ["x1c"],
|
|
1074
|
+
"engine": "manifold",
|
|
1075
|
+
"anchors": { "axis": { "at": [0, 0, "0 - gap"], "axis": [0, 0, 1] } },
|
|
1076
|
+
"variables": {
|
|
1077
|
+
"gap": { "value": 0.3, "unit": "mm", "rule": "Clear of the motor plate" },
|
|
1078
|
+
"module": { "value": 1, "unit": "mm", "rule": "The gears'" },
|
|
1079
|
+
"low": { "value": 18, "rule": "On the sun and the held ring" },
|
|
1080
|
+
"high": { "value": 21, "rule": "On the output ring" },
|
|
1081
|
+
"width": { "value": 8, "unit": "mm", "rule": "Each stage" }
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
```
|
|
1085
|
+
|
|
1086
|
+
```js projects/home/objects/joint-planet.js
|
|
1087
|
+
// A planet in two steps, in one piece, printed with the wider step on the bed.
|
|
1088
|
+
import jscad from '@jscad/modeling'
|
|
1089
|
+
const { translate } = jscad.transforms
|
|
1090
|
+
|
|
1091
|
+
export function main (v) {
|
|
1092
|
+
const low = v.gears.spur({ module: v.module, teeth: v.low, width: v.width })
|
|
1093
|
+
const high = translate([0, 0, v.width], v.gears.spur({ module: v.module, teeth: v.high, width: v.width }))
|
|
1094
|
+
return v.ops.union(low, high)
|
|
1095
|
+
}
|
|
1096
|
+
```
|
|
1097
|
+
|
|
1098
|
+
```json projects/home/objects/joint-output.json
|
|
1099
|
+
{
|
|
1100
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1101
|
+
"name": "joint-output",
|
|
1102
|
+
"title": "Output ring and flange",
|
|
1103
|
+
"version": "0.1.0",
|
|
1104
|
+
"uses": ["x1c"],
|
|
1105
|
+
"engine": "manifold",
|
|
1106
|
+
"anchors": { "axis": { "at": [0, 0, "top + width"], "axis": [0, 0, -1] }, "tip": { "at": [150, 0, "top + width"], "axis": [0, 0, -1] } },
|
|
1107
|
+
"variables": {
|
|
1108
|
+
"top": { "value": 3, "unit": "mm", "rule": "The flange, printed on the bed" },
|
|
1109
|
+
"width": { "value": 8, "unit": "mm", "rule": "The output ring's face" },
|
|
1110
|
+
"rim": { "value": 66, "unit": "mm", "rule": "Round the 57-tooth ring" },
|
|
1111
|
+
"module": { "value": 1, "unit": "mm", "rule": "The gears'" },
|
|
1112
|
+
"teeth": { "value": 57, "rule": "The output ring" },
|
|
1113
|
+
"hole": { "value": 3.5, "unit": "mm", "rule": "M3 clearance, on a 40 mm circle, for the arm" },
|
|
1114
|
+
"middle": { "value": 15, "unit": "mm", "rule": "A hole in the middle for the motor's shaft to come up in" },
|
|
1115
|
+
"bolt": { "value": 20, "unit": "mm", "rule": "Radius of the arm's bolt circle" }
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
```
|
|
1119
|
+
|
|
1120
|
+
```js projects/home/objects/joint-output.js
|
|
1121
|
+
// The output ring, drawn as it prints: its flange on the bed, the teeth standing on it; it goes on upside down.
|
|
1122
|
+
import jscad from '@jscad/modeling'
|
|
1123
|
+
const { cylinder } = jscad.primitives
|
|
1124
|
+
const { translate } = jscad.transforms
|
|
1125
|
+
|
|
1126
|
+
export function main (v) {
|
|
1127
|
+
const flange = cylinder({ radius: v.rim / 2, height: v.top, center: [0, 0, v.top / 2], segments: 96 })
|
|
1128
|
+
const ring = translate([0, 0, v.top], v.gears.internal({ module: v.module, teeth: v.teeth, width: v.width, rim: v.rim }))
|
|
1129
|
+
const holes = [0, 1, 2, 3].map((k) => cylinder({ radius: v.hole / 2, height: v.top + 1, center: [v.bolt * Math.cos(k * Math.PI / 2), v.bolt * Math.sin(k * Math.PI / 2), v.top / 2], segments: 24 }))
|
|
1130
|
+
const middle = cylinder({ radius: v.middle / 2, height: v.top + 1, center: [0, 0, v.top / 2], segments: 48 })
|
|
1131
|
+
return v.ops.subtract(v.ops.union(flange, ring), holes, middle)
|
|
1132
|
+
}
|
|
1133
|
+
```
|
|
1134
|
+
|
|
1135
|
+
Three clips on three posts keep the output ring from lifting off. It turns under them with 0.3 mm to spare.
|
|
1136
|
+
|
|
1137
|
+
```json projects/home/objects/joint-clip.json
|
|
1138
|
+
{
|
|
1139
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1140
|
+
"name": "joint-clip",
|
|
1141
|
+
"title": "Retaining clip",
|
|
1142
|
+
"version": "0.1.0",
|
|
1143
|
+
"uses": ["x1c"],
|
|
1144
|
+
"variables": {
|
|
1145
|
+
"reach": { "value": 6, "unit": "mm", "rule": "In over the flange's edge, 4 mm" },
|
|
1146
|
+
"back": { "value": 4, "unit": "mm", "rule": "Round the post" },
|
|
1147
|
+
"wide": { "value": 8, "unit": "mm", "rule": "As wide as the post and a little" },
|
|
1148
|
+
"thick": { "value": 3, "unit": "mm", "rule": "Fifteen layers" },
|
|
1149
|
+
"hole": { "value": 3.5, "unit": "mm", "rule": "M3 clearance" }
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
```
|
|
1153
|
+
|
|
1154
|
+
```js projects/home/objects/joint-clip.js
|
|
1155
|
+
// A flat tab screwed to a post, its nose over the flange.
|
|
1156
|
+
import jscad from '@jscad/modeling'
|
|
1157
|
+
const { cuboid, cylinder } = jscad.primitives
|
|
1158
|
+
const { subtract } = jscad.booleans
|
|
1159
|
+
|
|
1160
|
+
export function main (v) {
|
|
1161
|
+
const tab = cuboid({ size: [v.reach + v.back, v.wide, v.thick], center: [(v.back - v.reach) / 2, 0, v.thick / 2] })
|
|
1162
|
+
return subtract(tab, cylinder({ radius: v.hole / 2, height: v.thick + 1, center: [0, 0, v.thick / 2], segments: 24 }))
|
|
1163
|
+
}
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
```json projects/home/objects/joint-speck.json
|
|
1167
|
+
{
|
|
1168
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
1169
|
+
"name": "joint-speck",
|
|
1170
|
+
"title": "Carrier (not printed)",
|
|
1171
|
+
"version": "0.1.0",
|
|
1172
|
+
"role": "reference",
|
|
1173
|
+
"anchors": {
|
|
1174
|
+
"axis": { "at": [0, 0, 0], "axis": [0, 0, 1] },
|
|
1175
|
+
"a": { "at": [18, 0, 0], "axis": [0, 0, 1] },
|
|
1176
|
+
"b": { "at": ["0 - 9", "18 * sind(120)", 0], "axis": [0, 0, 1] },
|
|
1177
|
+
"c": { "at": ["0 - 9", "0 - 18 * sind(120)", 0], "axis": [0, 0, 1] }
|
|
1178
|
+
},
|
|
1179
|
+
"variables": { "r": { "value": 0.2, "unit": "mm", "rule": "A speck, so the planets' joints have something to hang from" } }
|
|
1180
|
+
}
|
|
1181
|
+
```
|
|
1182
|
+
|
|
1183
|
+
```js projects/home/objects/joint-speck.js
|
|
1184
|
+
// Nothing is printed here: the planets ride on the sun and the rings. A mark for the planets' joints to be on.
|
|
1185
|
+
import jscad from '@jscad/modeling'
|
|
1186
|
+
const { sphere } = jscad.primitives
|
|
1187
|
+
|
|
1188
|
+
export function main (v) { return sphere({ radius: v.r, center: [0, 0, 60] }) }
|
|
1189
|
+
```
|
|
1190
|
+
|
|
1191
|
+
The joint's load is a mass on the output. The check finds the worst angle by running the motor through its range.
|
|
1192
|
+
|
|
1193
|
+
```json projects/home/assemblies/shoulder.json
|
|
1194
|
+
{
|
|
1195
|
+
"title": "Robot shoulder",
|
|
1196
|
+
"kind": "fit",
|
|
1197
|
+
"gravity": [0, -1, 0],
|
|
1198
|
+
"items": [
|
|
1199
|
+
{ "id": "housing", "object": "joint-housing" },
|
|
1200
|
+
{ "id": "motor", "motor": { "model": "nema17", "drives": "drive", "speed": 300, "duty": 0.3 } },
|
|
1201
|
+
{ "id": "sun", "object": "joint-sun" },
|
|
1202
|
+
{ "id": "carrier", "object": "joint-speck" },
|
|
1203
|
+
{ "id": "p1", "object": "joint-planet" },
|
|
1204
|
+
{ "id": "p2", "object": "joint-planet" },
|
|
1205
|
+
{ "id": "p3", "object": "joint-planet" },
|
|
1206
|
+
{ "id": "output", "object": "joint-output" },
|
|
1207
|
+
{ "id": "clip1", "object": "joint-clip", "at": ["37 * cosd(30)", "37 * sind(30)", 24.7], "rotate": [0, 0, 30] },
|
|
1208
|
+
{ "id": "clip2", "object": "joint-clip", "at": ["37 * cosd(150)", "37 * sind(150)", 24.7], "rotate": [0, 0, 150] },
|
|
1209
|
+
{ "id": "clip3", "object": "joint-clip", "at": [0, -37, 24.7], "rotate": [0, 0, 270] }
|
|
1210
|
+
],
|
|
1211
|
+
"joints": [
|
|
1212
|
+
{ "id": "drive", "type": "revolute", "parent": "housing.axis", "child": "sun.axis", "label": "Motor" },
|
|
1213
|
+
{ "id": "turn", "type": "revolute", "parent": "housing.axis", "child": "carrier.axis" },
|
|
1214
|
+
{ "id": "s1", "type": "revolute", "parent": "carrier.a", "child": "p1.axis" },
|
|
1215
|
+
{ "id": "s2", "type": "revolute", "parent": "carrier.b", "child": "p2.axis" },
|
|
1216
|
+
{ "id": "s3", "type": "revolute", "parent": "carrier.c", "child": "p3.axis" },
|
|
1217
|
+
{ "id": "out", "type": "revolute", "parent": { "at": [0, 0, 13.4], "axis": [0, 0, 1] }, "child": "output.axis" }
|
|
1218
|
+
],
|
|
1219
|
+
"planetary": [{ "sun": "sun", "carrier": "carrier", "ring": "housing", "planets": ["p1", "p2", "p3"], "drive": "sun", "module": 1, "teeth": [18, 18, 54], "output": { "ring": "output", "planet": 21, "teeth": 57 } }],
|
|
1220
|
+
"fits": [
|
|
1221
|
+
{ "a": "motor", "b": "housing", "fastens": true, "min": 0, "note": "The motor, on its four screws" },
|
|
1222
|
+
{ "a": "clip1", "b": "housing", "fastens": true, "min": 0, "note": "A clip, screwed on" },
|
|
1223
|
+
{ "a": "clip2", "b": "housing", "fastens": true, "min": 0, "note": "A clip, screwed on" },
|
|
1224
|
+
{ "a": "clip3", "b": "housing", "fastens": true, "min": 0, "note": "A clip, screwed on" },
|
|
1225
|
+
{ "a": "motor", "b": "sun", "shaft": true, "note": "The motor's shaft in the sun" }
|
|
1226
|
+
],
|
|
1227
|
+
"loads": [{ "mass": 0.5, "at": "output.tip", "note": "500 g at 150 mm: a forearm" }],
|
|
1228
|
+
"poses": { "home": { "drive": 0 } }
|
|
1229
|
+
}
|
|
1230
|
+
```
|
|
1231
|
+
|
|
1232
|
+
```sh
|
|
1233
|
+
npx cad check home/shoulder
|
|
1234
|
+
```
|
|
1235
|
+
|
|
1236
|
+
The check says the output ring turns 1/38 of the motor's turn, the other way; that 7.44 N m reaches the joint at 300 rpm
|
|
1237
|
+
against the 0.735 N m it needs at its worst, ten times over; that it turns a full turn in 7.6 s at that speed; and
|
|
1238
|
+
that the gears, under 50% efficient, hold it with the power off. `npx cad check home/shoulder --sweep --steps 24` turns the
|
|
1239
|
+
motor all the way round and finds no teeth touching, and neither do the output ring's steps.
|
|
1240
|
+
|
|
1241
|
+
Ten times over is more margin than the job needs, but the gearbox is the size it is for what the motor could do to it, not
|
|
1242
|
+
the arm: stalled against a stop, the 7.44 N m at the output puts 33 MPa on the planets' top teeth (`strength`, the Lewis
|
|
1243
|
+
equation, for teeth 8 mm wide), against PLA's 39. Give that a home switch, or a smaller current.
|
package/README.md
CHANGED
|
@@ -153,6 +153,7 @@ own copy anywhere and name it in `viewUrl`.
|
|
|
153
153
|
`notchHinge`, `bistable`, `livingHinge` as shapes, each with a `<name>Model(shape, { E })` giving its stiffness and the
|
|
154
154
|
strain at a travel, and `printable(shape, printer, material, model)` for how it prints. Drawn flat: bending along y,
|
|
155
155
|
width up z, so a flexure bends within its layers.
|
|
156
|
+
- `v.motors`: motors (`@rulecad/motors`): `motorModel`, `mount` and `bore` for the holes a part needs round a motor and its shaft, `performance` for its torque and speed. In an assembly a motor is an item (see Motors).
|
|
156
157
|
- `v.gears`: gears (`@rulecad/gears`): `spur`, `rack` and `internal` as shapes, from a module and teeth, each with its
|
|
157
158
|
model (`gearModel`, `rackModel`, `internalModel`) and `printable(model, printer, width)`. Drawn flat: the axis up z,
|
|
158
159
|
the first tooth on +x, the face on the bed. Two gears in an assembly mesh with a joint's `mesh` (see Joints).
|
|
@@ -404,6 +405,19 @@ then y, then z, as `rotate` does.
|
|
|
404
405
|
and a quick look for parts pushed into each other when you let a slider go. The quick look can miss parts that cross
|
|
405
406
|
without a corner going in, so `--sweep` is the real check.
|
|
406
407
|
|
|
408
|
+
### Motors
|
|
409
|
+
|
|
410
|
+
An item can be a motor instead of a printed object: `{ "id": "drive", "motor": { "model": "nema17", "drives": "elbow" }, "at": […], "rotate": […] }`. It comes from `@rulecad/motors`, is bought and not printed (a reference, in the assembly but never on a plate), and its anchors (`shaft`, `tip`, `face`, `horn`, `hole1` …) work in joints like any other. `set` changes a figure (`{ "holding_torque": { "value": 0.5, "kind": "measured", "source": "…" } }`), `speed` is the motor's speed (rpm), `margin` how many times over the torque must be (2 by default), `duty` the share of the time it runs.
|
|
411
|
+
|
|
412
|
+
- `"drives"`: the joint it turns, a revolute. The viewer's slider moves in a stepper's steps; a servo brings its range. Whatever follows that joint through a `mesh` or a `planetary` moves with it. `motor.axis` fails if its shaft isn't on the joint's axis.
|
|
413
|
+
- `"loads"` at the top of the assembly say what it has to do: `{ "joint": "elbow", "torque": 0.5 }` (N m), `{ "joint": "slide", "force": 12 }` (N), or `{ "mass": 0.2, "at": "forearm.tip" }` (kg, a mass carried at an anchor, whose torque at each joint comes from where the pose puts it; the check runs the motor through its range and reports the worst). `"gravity": [0, -1, 0]` says which way is down, if not `-z`.
|
|
414
|
+
- A compound planetary is a `planetary` with `"output": { "ring", "planet", "teeth" }`: a second ring on the planets' second step, following them in phase.
|
|
415
|
+
- `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).
|
|
416
|
+
- `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.
|
|
417
|
+
- `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
|
+
- `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
|
+
- 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`).
|
|
420
|
+
|
|
407
421
|
## Optimised parts
|
|
408
422
|
|
|
409
423
|
`cad optimise` finds the stiffest layout of a flat part: where to put a fixed amount of material so the part bends
|
package/bin/cad.mjs
CHANGED
|
@@ -24,6 +24,7 @@ import { setVariables, addToAssembly, parseValue } from '../lib/edit.mjs';
|
|
|
24
24
|
import { setAt } from '../lib/jsonedit.mjs';
|
|
25
25
|
import { threemf, slotOf } from '../lib/threemf.mjs';
|
|
26
26
|
import { liveView } from '../lib/live.mjs';
|
|
27
|
+
import { checkSets, drawSet, draftSet } from '../lib/sheet.mjs';
|
|
27
28
|
import { filaments, slots, linkTo, objectModel, assemblyModel, VIEW } from '../lib/links.mjs';
|
|
28
29
|
|
|
29
30
|
// What the print file asks of the AMS: which filament each kind of part prints in
|
|
@@ -46,6 +47,9 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
46
47
|
cad agents AGENTS.md: how an AI agent should design in this workspace
|
|
47
48
|
cad trust allow what this workspace's cad.config.json asks (no sandbox, its own targets)
|
|
48
49
|
cad rules <project>/<object> every variable: value, the rule behind it, its source
|
|
50
|
+
cad rules check [set …] rule sets held to what makes them traceable (exit 1 on a failure) [--json]
|
|
51
|
+
cad rules draw <set> a dimension drawing of what a set says a part mounts by, <set>.svg, to compare with its datasheet [--out file]
|
|
52
|
+
cad rules draft <name> --from <file.pdf> the figures in a datasheet's text, into rules/<name>.json for you to name and check (all kind estimate)
|
|
49
53
|
cad values <project>/<object> [names…] the object's variables, resolved [--json]
|
|
50
54
|
cad set <project>/<object> name=value … change variables, keeping the file's layout [--unit, --rule, --label, --new to add one]
|
|
51
55
|
cad add fit|joint|item|loop|pose <project>/<assembly> --a … --b … --min … add to an assembly, keeping its layout
|
|
@@ -104,7 +108,7 @@ const COMMANDS = ['new', 'import-kle', 'clone', 'agents', 'trust', 'rules', 'val
|
|
|
104
108
|
const OPTIONS = ['all', 'along', 'at', 'bump', 'depth', 'dry-run', 'explode', 'force', 'fresh', 'json', 'licence', 'license', 'long', 'm', 'material', 'md', 'name', 'new',
|
|
105
109
|
'no-models', 'no-pictures', 'no-rules', 'note', 'open', 'part', 'place', 'pose', 'progress', 'push', 'result', 'rules', 'samples', 'set', 'short', 'source', 'steps',
|
|
106
110
|
'sweep', 'tol', 'trailer', 'ttl', 'version', 'watch', 'line',
|
|
107
|
-
'unit', 'rule', 'label', // cad set
|
|
111
|
+
'unit', 'rule', 'label', 'from', 'out', // cad set, cad rules
|
|
108
112
|
'a', 'b', 'min', 'max', 'poses', 'id', 'type', 'parent', 'child', 'follow', 'value', 'ratio', 'object', 'assembly', 'variant', 'rotate']; // cad add
|
|
109
113
|
// What a command takes, where that isn't <project>/<object>
|
|
110
114
|
const USAGE = { add: 'fit|joint|item|loop|pose <project>/<assembly> --key value …', why: '<project>/<object>.<variable>', set: '<project>/<object> name=value …',
|
|
@@ -311,6 +315,30 @@ async function analyses(b, d, tag) {
|
|
|
311
315
|
return all;
|
|
312
316
|
}
|
|
313
317
|
|
|
318
|
+
// cad rules check / draw / draft: rule sets themselves, not a design's use of them
|
|
319
|
+
function ruleSheets(what, names) {
|
|
320
|
+
if (what === 'check') {
|
|
321
|
+
const results = checkSets(names), bad = results.filter((r) => r.findings.length);
|
|
322
|
+
if (opt('json')) console.log(JSON.stringify(results.map((r) => ({ name: r.name, findings: r.findings })), null, 2));
|
|
323
|
+
else {
|
|
324
|
+
for (const r of bad) { console.log(`${r.name}: ${r.findings.length} to fix`); for (const x of r.findings) console.log(` FAIL ${x.text} (${x.code})`); }
|
|
325
|
+
console.log(`${results.length - bad.length} of ${results.length} rule sets pass`);
|
|
326
|
+
}
|
|
327
|
+
process.exitCode = bad.length ? 1 : 0;
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const name = names[0];
|
|
331
|
+
if (!name) throw new Error(`usage: cad rules ${what} <set>${what === 'draft' ? ' --from <file.pdf>' : ''}`);
|
|
332
|
+
if (what === 'draw') { const to = opt('out') || `${name}.svg`; fs.writeFileSync(to, drawSet(name)); return console.log(`drew ${to}: compare it with the datasheet`); }
|
|
333
|
+
if (!opt('from')) throw new Error('usage: cad rules draft <name> --from <file.pdf>');
|
|
334
|
+
const { set, found } = draftSet(name, opt('from'));
|
|
335
|
+
if (!found) return console.log(`no figures in ${opt('from')}'s text: it's probably a picture of a drawing, so read it by eye and write rules/${name}.json by hand`);
|
|
336
|
+
const to = path.join(paths.rules ? paths.rules() : path.join(WS, 'rules'), `${name}.json`);
|
|
337
|
+
if (fs.existsSync(to) && !opt('force')) throw new Error(`${path.relative(WS, to)} already exists (--force replaces it)`);
|
|
338
|
+
fs.mkdirSync(path.dirname(to), { recursive: true }); fs.writeFileSync(to, JSON.stringify(set, null, 2) + '\n');
|
|
339
|
+
return console.log(`${found} figures in ${path.relative(WS, to)}, every one an estimate: name them from the vocabulary, check them against the datasheet, then cad rules check ${name}`);
|
|
340
|
+
}
|
|
341
|
+
|
|
314
342
|
async function main() {
|
|
315
343
|
const first = args[0], pos = positional(), [cmd = first, ref] = pos; // names first or options first: cad check --json keyboard/case
|
|
316
344
|
if (!first || ['help', '--help', '-h'].includes(first)) return console.log(HELP);
|
|
@@ -337,6 +365,8 @@ async function main() {
|
|
|
337
365
|
return console.log(`made projects/${project}/objects/${name}.{js,json}`);
|
|
338
366
|
}
|
|
339
367
|
|
|
368
|
+
if (cmd === 'rules' && ['check', 'draw', 'draft'].includes(ref)) return ruleSheets(ref, pos.slice(2));
|
|
369
|
+
|
|
340
370
|
if (cmd === 'trust') { // this workspace may do what its cad.config.json asks (designs outside the sandbox, its own targets)
|
|
341
371
|
const what = asks();
|
|
342
372
|
if (!what.length) return console.log('this workspace asks for nothing outside the sandbox: nothing to trust');
|