create-rulecad 0.3.10 → 0.3.13

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.
Files changed (73) hide show
  1. package/README.md +16 -0
  2. package/index.mjs +62 -6
  3. package/machines/arm/projects/arm/assemblies/arm.json +103 -0
  4. package/machines/arm/projects/arm/drawings/test.svg +1 -0
  5. package/machines/arm/projects/arm/firmware/arm/arm.ino +149 -0
  6. package/machines/arm/projects/arm/objects/base.js +18 -0
  7. package/machines/arm/projects/arm/objects/base.json +41 -0
  8. package/machines/arm/projects/arm/objects/bridge.js +15 -0
  9. package/machines/arm/projects/arm/objects/bridge.json +32 -0
  10. package/machines/arm/projects/arm/objects/clip.js +9 -0
  11. package/machines/arm/projects/arm/objects/clip.json +20 -0
  12. package/machines/arm/projects/arm/objects/forearm.js +20 -0
  13. package/machines/arm/projects/arm/objects/forearm.json +44 -0
  14. package/machines/arm/projects/arm/objects/holder.js +23 -0
  15. package/machines/arm/projects/arm/objects/holder.json +50 -0
  16. package/machines/arm/projects/arm/objects/horn.js +9 -0
  17. package/machines/arm/projects/arm/objects/horn.json +17 -0
  18. package/machines/arm/projects/arm/objects/housing.js +22 -0
  19. package/machines/arm/projects/arm/objects/housing.json +39 -0
  20. package/machines/arm/projects/arm/objects/output.js +12 -0
  21. package/machines/arm/projects/arm/objects/output.json +28 -0
  22. package/machines/arm/projects/arm/objects/pen.js +9 -0
  23. package/machines/arm/projects/arm/objects/pen.json +17 -0
  24. package/machines/arm/projects/arm/objects/planet.js +9 -0
  25. package/machines/arm/projects/arm/objects/planet.json +20 -0
  26. package/machines/arm/projects/arm/objects/speck.js +5 -0
  27. package/machines/arm/projects/arm/objects/speck.json +17 -0
  28. package/machines/arm/projects/arm/objects/spindle.js +17 -0
  29. package/machines/arm/projects/arm/objects/spindle.json +34 -0
  30. package/machines/arm/projects/arm/objects/sun.js +10 -0
  31. package/machines/arm/projects/arm/objects/sun.json +22 -0
  32. package/machines/arm/projects/arm/objects/upper.js +34 -0
  33. package/machines/arm/projects/arm/objects/upper.json +73 -0
  34. package/machines/arm/projects/arm/project.json +19 -0
  35. package/machines/arm/projects/arm/send.mjs +70 -0
  36. package/machines/arm/rules/arm.json +44 -0
  37. package/machines/leg/projects/leg/assemblies/stand.json +101 -0
  38. package/machines/leg/projects/leg/objects/bridge.js +15 -0
  39. package/machines/leg/projects/leg/objects/bridge.json +32 -0
  40. package/machines/leg/projects/leg/objects/carriage.js +14 -0
  41. package/machines/leg/projects/leg/objects/carriage.json +34 -0
  42. package/machines/leg/projects/leg/objects/clip.js +9 -0
  43. package/machines/leg/projects/leg/objects/clip.json +20 -0
  44. package/machines/leg/projects/leg/objects/collar.js +11 -0
  45. package/machines/leg/projects/leg/objects/collar.json +19 -0
  46. package/machines/leg/projects/leg/objects/foot.js +11 -0
  47. package/machines/leg/projects/leg/objects/foot.json +21 -0
  48. package/machines/leg/projects/leg/objects/housing.js +22 -0
  49. package/machines/leg/projects/leg/objects/housing.json +39 -0
  50. package/machines/leg/projects/leg/objects/output.js +12 -0
  51. package/machines/leg/projects/leg/objects/output.json +28 -0
  52. package/machines/leg/projects/leg/objects/pad.js +14 -0
  53. package/machines/leg/projects/leg/objects/pad.json +27 -0
  54. package/machines/leg/projects/leg/objects/planet.js +9 -0
  55. package/machines/leg/projects/leg/objects/planet.json +20 -0
  56. package/machines/leg/projects/leg/objects/scale.js +5 -0
  57. package/machines/leg/projects/leg/objects/scale.json +15 -0
  58. package/machines/leg/projects/leg/objects/shin.js +17 -0
  59. package/machines/leg/projects/leg/objects/shin.json +35 -0
  60. package/machines/leg/projects/leg/objects/speck.js +5 -0
  61. package/machines/leg/projects/leg/objects/speck.json +17 -0
  62. package/machines/leg/projects/leg/objects/spindle.js +17 -0
  63. package/machines/leg/projects/leg/objects/spindle.json +34 -0
  64. package/machines/leg/projects/leg/objects/sun.js +10 -0
  65. package/machines/leg/projects/leg/objects/sun.json +22 -0
  66. package/machines/leg/projects/leg/objects/thigh.js +29 -0
  67. package/machines/leg/projects/leg/objects/thigh.json +53 -0
  68. package/machines/leg/projects/leg/objects/tie.js +10 -0
  69. package/machines/leg/projects/leg/objects/tie.json +19 -0
  70. package/machines/leg/projects/leg/project.json +21 -0
  71. package/machines/leg/rules/leg.json +42 -0
  72. package/package.json +6 -1
  73. package/template/AGENTS.md +27 -1
@@ -0,0 +1,23 @@
1
+ // All in one flat print: a fixed frame with the servo, two tapered leaves, the shuttle with the pen's bore and a lug for the horn.
2
+ import jscad from '@jscad/modeling'
3
+ const { cuboid, cylinder } = jscad.primitives
4
+ const { translate } = jscad.transforms
5
+
6
+ export function main (v) {
7
+ const f = v.flexures, material = f.flexureMaterial({ modulus: v.petg.modulus, strength: v.petg.strength, name: 'PETG' })
8
+ const leaf = { length: v.leaf_l, thickness: v.leaf_t, width: v.thick, gap: v.gap, taper: v.taper, fillet: v.fillet, shuttle: v.pen_x - v.block_x - v.leaf_l + v.pen_wall, base: v.block_x * 2 }
9
+ const model = f.parallelGuideModel(leaf, { E: v.petg.modulus })
10
+ for (const x of f.printable({ thickness: v.leaf_t, width: v.thick, travel: v.travel }, v.x1c, material, model)) if (x.level === 'fail') throw new Error(x.text)
11
+ const guide = translate([v.block_x, 0, 0], f.parallelGuide(leaf))
12
+ const block = cuboid({ size: [v.block_x * 2, v.shuttle * 2, v.thick], center: [0, 0, v.half] })
13
+ const frameBody = cuboid({ size: [v.frame_x + v.block_x, v.frame_top - v.frame_low, v.thick], center: [(v.frame_x - v.block_x) / 2, (v.frame_top + v.frame_low) / 2, v.half] })
14
+ const tail = cuboid({ size: [v.block_x * 2, v.frame_top - v.frame_low + v.shuttle * 2 - 1, v.thick], center: [0, (v.frame_top + v.frame_low + v.shuttle * 2) / 2 - 1 / 2 - 1, v.half] })
15
+ const shuttleBlock = cuboid({ size: [v.pen_x + v.pen_wall - v.block_x - v.leaf_l, v.shuttle * 2, v.thick], center: [v.block_x + v.leaf_l + (v.pen_x + v.pen_wall - v.block_x - v.leaf_l) / 2, 0, v.half] })
16
+ const tabBody = cuboid({ size: [v.lug_x1 - v.lug_x0, (0 - v.shuttle) - v.lug_y + 1, v.thick], center: [(v.lug_x0 + v.lug_x1) / 2, (v.lug_y + (0 - v.shuttle) + 1) / 2, v.half] })
17
+ const lug = cuboid({ size: [v.lug_x1 - v.lug_x0, v.lug_wide, v.lug_top - v.thick + 1], center: [(v.lug_x0 + v.lug_x1) / 2, v.lug_y + v.lug_wide / 2, v.thick + (v.lug_top - v.thick - 1) / 2] })
18
+ const bore = v.shapes.teardropHole({ d: v.pen_d, length: v.shuttle * 2 + 1, at: [v.pen_x, 0 - v.shuttle - 1 / 2, v.half], into: '+y', through: true })
19
+ const clamp = cylinder({ radius: v.clamp / 2, height: v.thick, center: [v.pen_x, 0, v.thick - v.half / 2], segments: v.segments })
20
+ const servo = translate([v.xh, v.yh, v.thick], v.motors.mount(v.motors.motorModel('sg90'), { plate: v.thick }, v.ops))
21
+ const holes = [-1, 1].map((s) => cylinder({ radius: v.bolt / 2, height: v.thick + 1, center: [s * v.bolt_y, 0, v.half], segments: v.segments }))
22
+ return v.ops.subtract(v.ops.union(guide, block, frameBody, tail, shuttleBlock, tabBody, lug), bore, clamp, servo, holes)
23
+ }
@@ -0,0 +1,50 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "holder",
4
+ "title": "Pen holder with lift",
5
+ "version": "0.1.0",
6
+ "uses": ["x1c", "arm", "petg", "m2", "m3"],
7
+ "engine": "manifold",
8
+ "material": "PETG",
9
+ "orientation": "Flat on the bed: the drawing's x and y are the bed's, the pen's axis along y. The leaves bend within their layers. PETG: it creeps less than PLA held bent",
10
+ "description": "A shuttle holding the pen on two tapered leaves: a parallel guide. Its spring is the pen's pressure; an SG90 on a stock horn lifts it. Drawn at rest, the leaves straight.",
11
+ "anchors": {
12
+ "mount": {"at": [0, 0, "half"], "axis": [0, 0, -1], "ref": [1, 0, 0]},
13
+ "tool": {"at": ["pen_x", "paper", "half"], "axis": [0, 1, 0], "ref": [1, 0, 0]},
14
+ "pen": {"at": ["pen_x", "paper - arm.press", "half"], "axis": [0, 1, 0], "ref": [1, 0, 0]},
15
+ "servo": {"at": ["xh", "yh", "thick"], "axis": [0, 0, 1], "ref": [1, 0, 0]},
16
+ "horn": {"at": ["xh", "yh", "thick + horn_at"], "axis": [0, 0, 1], "ref": [1, 0, 0]},
17
+ "cable": {"at": ["xh", "yh", 0], "axis": [0, 0, 1]}
18
+ },
19
+ "variables": {
20
+ "thick": {"value": 16, "unit": "mm", "rule": "The block's thickness, 80 layers, and the leaves' width", "interface": true},
21
+ "half": {"value": "thick / 2", "unit": "mm", "rule": "Half of it"},
22
+ "pen_x": {"value": 54, "unit": "mm", "rule": "From the bolts to the pen", "interface": true},
23
+ "paper": {"value": "0 - arm.fore_mid", "unit": "mm", "rule": "The paper, in this frame: the bench is the sheet's plane, the bolts are level with the forearm's middle"},
24
+ "pen_d": {"value": 10.4, "unit": "mm", "rule": "A 10 mm fineliner, 0.2 mm each side; set this to your pen"},
25
+ "pen_wall": {"value": 7, "unit": "mm", "rule": "The shuttle reaches this far past the pen each way"},
26
+ "leaf_t": {"value": "x1c.line * 2", "unit": "mm", "rule": "Two lines: stiff enough against pen drag, soft enough for the servo"},
27
+ "leaf_l": {"value": 38, "unit": "mm", "rule": "Long enough to keep the strain small at full lift", "label": "Leaf", "show": true},
28
+ "taper": {"value": 0.3, "rule": "Thickened toward both ends: the strain spread along the leaf"},
29
+ "fillet": {"value": "x1c.line * 3", "unit": "mm", "rule": "A round where each leaf meets its block: no square corner to yield at"},
30
+ "travel": {"value": 5, "unit": "mm", "rule": "1 mm below the paper at rest, to 4 mm above it lifted"},
31
+ "gap": {"value": 20, "unit": "mm", "rule": "Between the leaves: resists the pen's drag twisting the shuttle"},
32
+ "block_x": {"value": 8, "unit": "mm", "rule": "Half the bolt block's length along x"},
33
+ "shuttle": {"value": 14, "unit": "mm", "rule": "Half the shuttle's height along y"},
34
+ "bolt_y": {"value": 4, "unit": "mm", "rule": "Half the bolts' spacing along x"},
35
+ "bolt": {"value": "m3.clearance + x1c.hole_comp", "unit": "mm", "rule": "M3 clearance, through the block"},
36
+ "clamp": {"value": "m3.clearance - 0.6", "unit": "mm", "rule": "The pen's clamp screw, self-tapped through the shuttle's wall", "kind": "community"},
37
+ "lug_x0": {"value": 43, "unit": "mm", "rule": "The lug the horn lifts, its left edge"},
38
+ "lug_x1": {"value": 47.5, "unit": "mm", "rule": "Its right edge, clear of the pen"},
39
+ "lug_y": {"value": -22.2, "unit": "mm", "rule": "Its underside, a hair above the horn at rest"},
40
+ "horn_at": {"value": 13.3, "unit": "mm", "rule": "Horn seat above the tabs: the case's top and boss"},
41
+ "lug_top": {"value": "thick + horn_at + 2", "unit": "mm", "rule": "Up to the horn's top"},
42
+ "lug_wide": {"value": 4, "unit": "mm", "rule": "The lug's depth along y where it stands up: strong enough for 3 N"},
43
+ "xh": {"value": 30, "unit": "mm", "rule": "The servo's shaft, along x"},
44
+ "yh": {"value": -25, "unit": "mm", "rule": "The servo's shaft, along y"},
45
+ "frame_x": {"value": 41.4, "unit": "mm", "rule": "The servo frame's right edge"},
46
+ "frame_top": {"value": -16, "unit": "mm", "rule": "The frame's top edge, clear of the lower leaf's travel"},
47
+ "frame_low": {"value": -37, "unit": "mm", "rule": "The frame's bottom edge"},
48
+ "segments": {"value": 32, "rule": "Round enough"}
49
+ }
50
+ }
@@ -0,0 +1,9 @@
1
+ // The arm a servo comes with, pointing along x at rest.
2
+ import jscad from '@jscad/modeling'
3
+ const { cuboid, cylinder } = jscad.primitives
4
+
5
+ export function main (v) {
6
+ const arm = cuboid({ size: [v.reach, v.wide, v.thick], center: [v.reach / 2, 0, v.thick / 2] })
7
+ const hub = cylinder({ radius: v.hub / 2, height: v.thick, center: [0, 0, v.thick / 2], segments: v.segments })
8
+ return v.ops.union(arm, hub)
9
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "horn",
4
+ "title": "Servo horn (bought, comes with the SG90)",
5
+ "version": "0.1.0",
6
+ "role": "reference",
7
+ "anchors": {
8
+ "axis": {"at": [0, 0, 0], "axis": [0, 0, 1], "ref": [1, 0, 0]}
9
+ },
10
+ "variables": {
11
+ "reach": {"value": 18, "unit": "mm", "rule": "Axis to the arm's tip, a single-arm horn as sold, about: measure yours", "kind": "estimate", "source": "Measured on one horn: SG90 horns vary"},
12
+ "wide": {"value": 5, "unit": "mm", "rule": "The arm's width"},
13
+ "thick": {"value": 2, "unit": "mm", "rule": "The arm's thickness"},
14
+ "hub": {"value": 7, "unit": "mm", "rule": "Round the spline"},
15
+ "segments": {"value": 24, "rule": "Round enough"}
16
+ }
17
+ }
@@ -0,0 +1,22 @@
1
+ // The motor plate with the fixed ring and posts standing on it. The motor bolts underneath, its shaft up through the middle.
2
+ import jscad from '@jscad/modeling'
3
+ const { cylinder, cylinderElliptic } = jscad.primitives
4
+ const { translate } = jscad.transforms
5
+
6
+ export function main (v) {
7
+ const motor = v.motors.motorModel('17HS4401')
8
+ const at = (r, a) => [r * Math.cos(a), r * Math.sin(a)]
9
+ const posts = [v.p1, v.p2, v.p3].map((a) => a * v.rad), feet = [v.f1, v.f2, v.f3].map((a) => a * v.rad)
10
+ const plate = cylinder({ radius: v.rim / 2, height: v.plate, center: [0, 0, v.plate / 2], segments: v.ring_segments })
11
+ const ring = translate([0, 0, v.plate], v.gears.internal({ module: v.module, teeth: v.teeth, width: v.gear, rim: v.rim }))
12
+ const lobes = [...posts, ...feet].map((a) => cylinder({ radius: v.lobe / 2, height: v.plate, center: [...at(v.post_r, a), v.plate / 2], segments: v.segments }))
13
+ const joins = [...posts, ...feet].map((a) => jscad.transforms.rotateZ(a, jscad.primitives.cuboid({ size: [v.post_r - v.rim / 2 + 2, v.lobe, v.plate], center: [(v.post_r + v.rim / 2 - 2) / 2, 0, v.plate / 2] })))
14
+ const uprights = posts.map((a) => cylinder({ radius: v.post / 2, height: v.post_high + v.plate, center: [...at(v.post_r, a), (v.post_high + v.plate) / 2], segments: v.segments }))
15
+ const pilots = posts.map((a) => cylinder({ radius: v.pilot / 2, height: v.pilot_depth, center: [...at(v.post_r, a), v.plate + v.post_high - v.pilot_depth / 2], segments: v.segments }))
16
+ const screws = feet.map((a) => cylinder({ radius: v.screw / 2, height: v.plate + 1, center: [...at(v.column_r, a), v.plate / 2], segments: v.segments }))
17
+ const heads = feet.map((a) => cylinder({ radius: v.head / 2, height: v.head_depth, center: [...at(v.column_r, a), v.plate - v.head_depth / 2], segments: v.segments }))
18
+ // the pocket for the motor's boss would be bridged across: a 45° cone from its roof up through the plate needs no bridge
19
+ const hole = v.motors.mountModel(motor, { plate: v.plate, counterbore: true }), rise = v.plate - hole.pocketDepth
20
+ const roof = cylinderElliptic({ height: rise + 1, startRadius: [hole.pocket / 2, hole.pocket / 2], endRadius: [hole.pocket / 2 - rise - 1, hole.pocket / 2 - rise - 1], center: [0, 0, hole.pocketDepth + (rise + 1) / 2], segments: v.segments })
21
+ return v.ops.subtract(v.ops.union(plate, ring, lobes, joins, uprights), v.motors.mount(motor, { plate: v.plate, counterbore: true }, v.ops), pilots, screws, heads, roof)
22
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "housing",
4
+ "title": "Shoulder housing and fixed ring",
5
+ "version": "0.1.0",
6
+ "uses": ["x1c", "arm", "m3"],
7
+ "engine": "manifold",
8
+ "orientation": "The motor plate on the bed, the ring and posts up",
9
+ "anchors": {
10
+ "axis": {"at": [0, 0, "plate"], "axis": [0, 0, 1]},
11
+ "motor": {"at": [0, 0, 0], "axis": [0, 0, 1], "ref": [1, 0, 0]}
12
+ },
13
+ "variables": {
14
+ "plate": {"value": "arm.plate", "unit": "mm", "rule": "The motor plate", "interface": true},
15
+ "gear": {"value": "arm.gear", "unit": "mm", "rule": "The fixed ring's face: strong enough for the motor's whole torque"},
16
+ "rim": {"value": 62, "unit": "mm", "rule": "Round the 54-tooth ring, three lines and more of wall"},
17
+ "module": {"value": 1, "unit": "mm", "rule": "The gears'"},
18
+ "teeth": {"value": 54, "rule": "The fixed ring"},
19
+ "post_r": {"value": 37, "unit": "mm", "rule": "Three posts outside the output ring", "interface": true},
20
+ "post": {"value": 7, "unit": "mm", "rule": "Each post's diameter"},
21
+ "post_high": {"value": "arm.bridge_low - arm.face - plate", "unit": "mm", "rule": "From the plate to under the bridge", "interface": true},
22
+ "pilot": {"value": 2.9, "unit": "mm", "rule": "An M3 screw self-tapped", "kind": "community"},
23
+ "pilot_depth": {"value": 8, "unit": "mm", "rule": "For an M3 × 16 through the bridge"},
24
+ "column_r": {"value": 37, "unit": "mm", "rule": "Over the base's columns"},
25
+ "lobe": {"value": 12, "unit": "mm", "rule": "The plate reaches out over each column"},
26
+ "screw": {"value": "m3.clearance + x1c.hole_comp", "unit": "mm", "rule": "M3 clearance, down into the column"},
27
+ "head": {"value": "m3.head + 2 * x1c.fit + x1c.hole_comp", "unit": "mm", "rule": "The screw head's counterbore"},
28
+ "head_depth": {"value": "m3.head_height + x1c.layer", "unit": "mm", "rule": "A socket head's height, sunk"},
29
+ "segments": {"value": 64, "rule": "Round enough"},
30
+ "ring_segments": {"value": 96, "rule": "Smooth to the eye and to the gear"},
31
+ "rad": {"value": 0.017453293, "rule": "Radians in a degree"},
32
+ "p1": {"value": 30, "unit": "°", "rule": "First post"},
33
+ "p2": {"value": 150, "unit": "°", "rule": "Second post"},
34
+ "p3": {"value": 270, "unit": "°", "rule": "Third post"},
35
+ "f1": {"value": 90, "unit": "°", "rule": "First foot, over a column"},
36
+ "f2": {"value": 210, "unit": "°", "rule": "Second foot"},
37
+ "f3": {"value": 330, "unit": "°", "rule": "Third foot"}
38
+ }
39
+ }
@@ -0,0 +1,12 @@
1
+ // The output ring, drawn as it prints: its flange on the bed, the teeth standing on it; it goes on upside down.
2
+ import jscad from '@jscad/modeling'
3
+ const { cylinder } = jscad.primitives
4
+ const { translate } = jscad.transforms
5
+
6
+ export function main (v) {
7
+ const flange = cylinder({ radius: v.rim / 2, height: v.top, center: [0, 0, v.top / 2], segments: v.ring_segments })
8
+ const ring = translate([0, 0, v.top], v.gears.internal({ module: v.module, teeth: v.teeth, width: v.width, rim: v.rim }))
9
+ const holes = Array.from({ length: v.bolts }, (_, k) => cylinder({ radius: v.pilot / 2, height: v.top + 1, center: [v.bolt * Math.cos(k * v.quarter), v.bolt * Math.sin(k * v.quarter), v.top / 2], segments: v.segments }))
10
+ const middle = cylinder({ radius: v.middle / 2, height: v.top + 1, center: [0, 0, v.top / 2], segments: v.ring_segments })
11
+ return v.ops.subtract(v.ops.union(flange, ring), holes, middle)
12
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "output",
4
+ "title": "Output ring and flange",
5
+ "version": "0.1.0",
6
+ "uses": ["x1c", "arm", "m3"],
7
+ "engine": "manifold",
8
+ "orientation": "The flange on the bed, the teeth standing on it",
9
+ "description": "Printed flange down and fitted upside down: the same part on the shoulder and the elbow.",
10
+ "anchors": {
11
+ "axis": {"at": [0, 0, "top + width"], "axis": [0, 0, -1]},
12
+ "flange": {"at": [0, 0, 0], "axis": [0, 0, -1]}
13
+ },
14
+ "variables": {
15
+ "top": {"value": "arm.flange", "unit": "mm", "rule": "The flange, printed on the bed", "interface": true},
16
+ "width": {"value": "arm.gear", "unit": "mm", "rule": "The output ring's face"},
17
+ "rim": {"value": 66, "unit": "mm", "rule": "Round the 57-tooth ring"},
18
+ "module": {"value": 1, "unit": "mm", "rule": "The gears'"},
19
+ "teeth": {"value": 57, "rule": "The output ring"},
20
+ "pilot": {"value": 2.9, "unit": "mm", "rule": "An M3 screw self-tapped into the flange", "kind": "community"},
21
+ "middle": {"value": 15, "unit": "mm", "rule": "A hole in the middle for the motor's shaft to come up in"},
22
+ "bolt": {"value": 20, "unit": "mm", "rule": "Radius of the bolt circle", "interface": true},
23
+ "segments": {"value": 24, "rule": "Small holes"},
24
+ "ring_segments": {"value": 96, "rule": "Smooth to the eye and to the gear"},
25
+ "quarter": {"value": 1.57079633, "rule": "The bolts, a quarter turn apart, in radians"},
26
+ "bolts": {"value": 4, "rule": "Four"}
27
+ }
28
+ }
@@ -0,0 +1,9 @@
1
+ // A fineliner, drawn from a few measurements.
2
+ import jscad from '@jscad/modeling'
3
+ const { cylinder, cylinderElliptic } = jscad.primitives
4
+
5
+ export function main (v) {
6
+ const body = cylinder({ radius: v.d / 2, height: v.long - v.point, center: [0, 0, v.point + (v.long - v.point) / 2], segments: v.segments })
7
+ const cone = cylinderElliptic({ height: v.point, startRadius: [v.tip_d / 2, v.tip_d / 2], endRadius: [v.d / 2, v.d / 2], center: [0, 0, v.point / 2], segments: v.segments })
8
+ return v.ops.union(body, cone)
9
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "pen",
4
+ "title": "Pen (bought, a fineliner)",
5
+ "version": "0.1.0",
6
+ "role": "reference",
7
+ "anchors": {
8
+ "tip": {"at": [0, 0, 0], "axis": [0, 0, 1], "ref": [1, 0, 0]}
9
+ },
10
+ "variables": {
11
+ "d": {"value": 10, "unit": "mm", "rule": "A fineliner's body, about: measure yours and set the holder's bore"},
12
+ "long": {"value": 140, "unit": "mm", "rule": "Its length"},
13
+ "point": {"value": 15, "unit": "mm", "rule": "The tapered point"},
14
+ "tip_d": {"value": 2, "unit": "mm", "rule": "At the tip"},
15
+ "segments": {"value": 32, "rule": "Round enough"}
16
+ }
17
+ }
@@ -0,0 +1,9 @@
1
+ // A planet in two steps, in one piece, printed with the wider step on the bed.
2
+ import jscad from '@jscad/modeling'
3
+ const { translate } = jscad.transforms
4
+
5
+ export function main (v) {
6
+ const high = v.gears.spur({ module: v.module, teeth: v.high, width: v.width })
7
+ const low = translate([0, 0, v.width], v.gears.spur({ module: v.module, teeth: v.low, width: v.width, chamfer: v.low_chamfer }))
8
+ return v.ops.union(high, low)
9
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "planet",
4
+ "title": "Stepped planet",
5
+ "version": "0.1.0",
6
+ "uses": ["x1c"],
7
+ "engine": "manifold",
8
+ "orientation": "The wider step on the bed",
9
+ "anchors": {
10
+ "axis": {"at": [0, 0, "width * 2 + gap"], "axis": [0, 0, -1]}
11
+ },
12
+ "variables": {
13
+ "gap": {"value": 0.3, "unit": "mm", "rule": "Clear of the motor plate"},
14
+ "module": {"value": 1, "unit": "mm", "rule": "The gears'"},
15
+ "low": {"value": 18, "rule": "On the sun and the held ring"},
16
+ "high": {"value": 21, "rule": "On the output ring"},
17
+ "width": {"value": 8, "unit": "mm", "rule": "Each stage"},
18
+ "low_chamfer": {"value": 0.25, "unit": "mm", "rule": "The top step's tooth tips slanted in at their root, so they do not overhang the step below"}
19
+ }
20
+ }
@@ -0,0 +1,5 @@
1
+ // Nothing is printed here: the planets ride on the sun and the rings. A mark for the planets' joints to be on.
2
+ import jscad from '@jscad/modeling'
3
+ const { sphere } = jscad.primitives
4
+
5
+ export function main (v) { return sphere({ radius: v.r, center: [0, 0, v.far] }) }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "speck",
4
+ "title": "Carrier (not printed)",
5
+ "version": "0.1.0",
6
+ "role": "reference",
7
+ "anchors": {
8
+ "axis": {"at": [0, 0, 0], "axis": [0, 0, 1]},
9
+ "a": {"at": [18, 0, 0], "axis": [0, 0, 1]},
10
+ "b": {"at": ["0 - 9", "18 * sind(120)", 0], "axis": [0, 0, 1]},
11
+ "c": {"at": ["0 - 9", "0 - 18 * sind(120)", 0], "axis": [0, 0, 1]}
12
+ },
13
+ "variables": {
14
+ "r": {"value": 0.2, "unit": "mm", "rule": "A speck, so the planets' joints have something to hang from"},
15
+ "far": {"value": 110, "unit": "mm", "rule": "Out of the way, above the arm"}
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ // A disc on the output's flange and a shaft up through the bearing, a hexagon at its top for the arm.
2
+ import jscad from '@jscad/modeling'
3
+ const { cylinder } = jscad.primitives
4
+
5
+ export function main (v) {
6
+ const plate = cylinder({ radius: v.rim / 2, height: v.disc, center: [0, 0, v.disc / 2], segments: v.segments * 2 })
7
+ const top = v.collar_top + v.width
8
+ const shaft = cylinder({ radius: v.shaft / 2, height: top - 1, center: [0, 0, (top + 1) / 2], segments: v.segments * 2 })
9
+ const collar = v.shapes.shaftShoulder(v.shaft, { shoulder: v.shoulder, height: v.collar_top - v.disc, at: [0, 0, v.collar_top] })
10
+ const hex = cylinder({ radius: v.hex / 2 / v.cos30, height: v.hex_long, center: [0, 0, top + v.hex_long / 2], segments: v.hex_segments })
11
+ const screws = Array.from({ length: v.bolts }, (_, k) => {
12
+ const c = [v.bolt * Math.cos(k * v.quarter), v.bolt * Math.sin(k * v.quarter), v.disc]
13
+ return v.shapes.countersink({ hole: v.hole, head: v.head, length: v.disc + 1, at: c, into: '-z' })
14
+ })
15
+ const pilot = cylinder({ radius: v.pilot / 2, height: v.pilot_depth, center: [0, 0, top + v.hex_long - v.pilot_depth / 2], segments: v.segments })
16
+ return v.ops.subtract(v.ops.union(plate, shaft, collar, hex), screws, pilot)
17
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "spindle",
4
+ "title": "Spindle: disc and shaft",
5
+ "version": "0.1.0",
6
+ "uses": ["x1c", "arm", "m3"],
7
+ "engine": "manifold",
8
+ "orientation": "The disc on the bed, the shaft up, as it goes on",
9
+ "description": "The output's flange turns the spindle; the spindle's shaft runs in the 6800 and carries the upper arm on a hexagon at its top.",
10
+ "anchors": {
11
+ "down": {"at": [0, 0, 0], "axis": [0, 0, 1], "ref": [1, 0, 0]},
12
+ "seat": {"at": [0, 0, "collar_top + width"], "axis": [0, 0, 1], "ref": [1, 0, 0]}
13
+ },
14
+ "variables": {
15
+ "disc": {"value": "arm.disc", "unit": "mm", "rule": "Thick enough for a countersunk M3"},
16
+ "rim": {"value": 46, "unit": "mm", "rule": "Round the 40 mm bolt circle"},
17
+ "bolt": {"value": 20, "unit": "mm", "rule": "On the output's bolt circle"},
18
+ "hole": {"value": "m3.clearance + x1c.hole_comp", "unit": "mm", "rule": "M3 clearance"},
19
+ "head": {"value": "m3.head", "unit": "mm", "rule": "A countersunk head, flush with the disc so the bridge passes over"},
20
+ "shaft": {"value": "arm.bearing_bore - x1c.press", "unit": "mm", "rule": "A close slide into the bearing's bore, clamped end to end by the upper arm's screw"},
21
+ "width": {"value": "arm.bearing_width", "unit": "mm", "rule": "The bearing"},
22
+ "collar_top": {"value": "arm.bridge_low + arm.bridge - width - arm.output_top", "unit": "mm", "rule": "Where the inner race rests, above the disc's underside"},
23
+ "shoulder": {"value": 13, "unit": "mm", "rule": "Stops the inner race; clears the outer race"},
24
+ "hex": {"value": 8, "unit": "mm", "rule": "Hexagon across its flats: inside the bore, drives the upper arm"},
25
+ "hex_long": {"value": 5, "unit": "mm", "rule": "Into the arm's socket"},
26
+ "pilot": {"value": 2.9, "unit": "mm", "rule": "An M3 screw self-tapped", "kind": "community"},
27
+ "pilot_depth": {"value": 12, "unit": "mm", "rule": "For the arm's M3"},
28
+ "cos30": {"value": "cosd(30)", "rule": "A hexagon, across corners to across flats"},
29
+ "bolts": {"value": 4, "rule": "On the bolt circle"},
30
+ "quarter": {"value": 1.57079633, "rule": "A quarter turn in radians"},
31
+ "segments": {"value": 64, "rule": "Round enough"},
32
+ "hex_segments": {"value": 6, "rule": "A hexagon's sides"}
33
+ }
34
+ }
@@ -0,0 +1,10 @@
1
+ // The sun with a hub above it, up through both stages, for grip on the shaft's flat.
2
+ import jscad from '@jscad/modeling'
3
+ const { cylinder } = jscad.primitives
4
+
5
+ export function main (v) {
6
+ const motor = v.motors.motorModel('nema17')
7
+ const gear = v.gears.spur({ module: v.module, teeth: v.teeth, width: v.width })
8
+ const hub = cylinder({ radius: v.hub / 2, height: v.tall, center: [0, 0, v.tall / 2], segments: v.segments })
9
+ return v.ops.subtract(v.ops.union(gear, hub), v.motors.bore(motor, { depth: v.tall, tip: v.tip }, v.ops))
10
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "sun",
4
+ "title": "Sun gear on a motor's shaft",
5
+ "version": "0.1.0",
6
+ "uses": ["x1c"],
7
+ "engine": "manifold",
8
+ "orientation": "Gear down, the hub up",
9
+ "anchors": {
10
+ "axis": {"at": [0, 0, "0 - gap"], "axis": [0, 0, 1]}
11
+ },
12
+ "variables": {
13
+ "gap": {"value": 0.3, "unit": "mm", "rule": "Clear of the motor plate"},
14
+ "module": {"value": 1, "unit": "mm", "rule": "The gears'"},
15
+ "teeth": {"value": 18, "rule": "As the planets' first step"},
16
+ "width": {"value": 8, "unit": "mm", "rule": "The first stage"},
17
+ "hub": {"value": 12, "unit": "mm", "rule": "A hub above the teeth, inside the planets' second step"},
18
+ "tall": {"value": 16, "unit": "mm", "rule": "Up through both stages, so 12 mm of the shaft's flat is gripped"},
19
+ "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 (the elbow's plate is thicker: its sun sets this less)", "interface": true, "tweak": {"min": 10, "max": 24}},
20
+ "segments": {"value": 64, "rule": "Round enough"}
21
+ }
22
+ }
@@ -0,0 +1,34 @@
1
+ // The upper arm, drawn as it prints: its top face on the bed, the elbow's ring standing on it, the hub's socket opening
2
+ // upward. The elbow's NEMA 14 bolts on the bed side, its shaft up through the plate, as chapter 11's housing does.
3
+ import jscad from '@jscad/modeling'
4
+ const { cylinder, cylinderElliptic, cuboid, circle } = jscad.primitives
5
+ const { translate, rotateZ } = jscad.transforms
6
+ const { extrudeLinear } = jscad.extrusions
7
+ const { hull } = jscad.hulls
8
+
9
+ export function main (v) {
10
+ const motor = v.motors.motorModel('nema14')
11
+ const at = (r, a) => [v.long + r * Math.cos(a), r * Math.sin(a)]
12
+ const posts = [v.p1, v.p2, v.p3].map((a) => a * v.rad)
13
+ const round = (r, c) => translate([c, 0], circle({ radius: r, segments: v.segments }))
14
+ const neck = extrudeLinear({ height: v.thick }, hull(round(v.hub / 2, 0), round(v.neck / 2, v.long)))
15
+ const hub = cylinder({ radius: v.hub / 2, height: v.thick, center: [0, 0, v.thick / 2], segments: v.ring_segments })
16
+ const plate = cylinder({ radius: v.rim / 2, height: v.thick, center: [v.long, 0, v.thick / 2], segments: v.ring_segments })
17
+ const ring = translate([v.long, 0, v.thick], v.gears.internal({ module: v.module, teeth: v.teeth, width: v.gear, rim: v.rim }))
18
+ const lobes = posts.map((a) => cylinder({ radius: v.lobe / 2, height: v.thick, center: [...at(v.post_r, a), v.thick / 2], segments: v.segments }))
19
+ const joins = posts.map((a) => translate([v.long, 0, 0], rotateZ(a, cuboid({ size: [v.post_r - v.rim / 2 + 2, v.lobe, v.thick], center: [(v.post_r + v.rim / 2 - 2) / 2, 0, v.thick / 2] }))))
20
+ const uprights = posts.map((a) => cylinder({ radius: v.post / 2, height: v.clip_at, center: [...at(v.post_r, a), v.clip_at / 2], segments: v.segments }))
21
+ const pilots = posts.map((a) => cylinder({ radius: v.pilot / 2, height: v.pilot_depth, center: [...at(v.post_r, a), v.clip_at - v.pilot_depth / 2], segments: v.segments }))
22
+ const collar = cylinder({ radius: v.collar_d / 2, height: v.collar + 1, center: [0, 0, v.thick + (v.collar - 1) / 2], segments: v.segments })
23
+ const socket = cylinder({ radius: (v.hex + v.hex_fit) / 2 / v.cos30, height: v.hex_depth + 1, center: [0, 0, v.floor + (v.hex_depth + 1) / 2], segments: v.hex_segments })
24
+ const through = cylinder({ radius: v.screw / 2, height: v.floor + 1, center: [0, 0, (v.floor - 1) / 2], segments: v.segments })
25
+ const flag = cuboid({ size: [v.flag_wide, v.flag_thick, v.flag_h], center: [v.flag_r, 0, v.thick + v.flag_h / 2] })
26
+ const a = v.switch_a * v.rad
27
+ const switchPost = translate([v.switch_x, v.switch_y, 0], rotateZ(a, cuboid({ size: [v.post_w, v.post_d, v.thick + v.switch_high], center: [0, 0, (v.thick + v.switch_high) / 2] })))
28
+ const switchPilots = [-1, 1].map((s) => cylinder({ radius: v.switch_pilot / 2, height: v.switch_depth, center: [v.switch_x + s * v.switch_pitch / 2 * Math.cos(a), v.switch_y + s * v.switch_pitch / 2 * Math.sin(a), v.thick + v.switch_high - v.switch_depth / 2], segments: v.segments }))
29
+ const bands = [v.bias_1, v.bias_2].map((x) => cylinder({ radius: v.bias_d / 2, height: v.thick + 1, center: [x, 0, v.thick / 2], segments: v.segments }))
30
+ const hole = v.motors.mountModel(motor, { plate: v.thick, counterbore: true }), rise = v.thick - hole.pocketDepth
31
+ const roof = translate([v.long, 0, 0], cylinderElliptic({ height: rise + 1, startRadius: [hole.pocket / 2, hole.pocket / 2], endRadius: [hole.pocket / 2 - rise - 1, hole.pocket / 2 - rise - 1], center: [0, 0, hole.pocketDepth + (rise + 1) / 2], segments: v.segments }))
32
+ const mount = translate([v.long, 0, 0], v.motors.mount(motor, { plate: v.thick, counterbore: true }, v.ops))
33
+ return v.ops.subtract(v.ops.union(neck, hub, plate, ring, lobes, joins, uprights, collar, flag, switchPost), socket, through, pilots, switchPilots, bands, mount, roof)
34
+ }
@@ -0,0 +1,73 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "upper",
4
+ "title": "Upper arm",
5
+ "version": "0.1.0",
6
+ "uses": ["x1c", "arm", "m2", "m3"],
7
+ "engine": "manifold",
8
+ "orientation": "The arm's top face on the bed: the hub, the elbow's fixed ring and its posts all rise from the one flat face, and go on hanging down",
9
+ "description": "From the shoulder's hexagon to the elbow's motor. Printed as one part with the elbow's fixed ring, so the elbow's gearbox costs a sun, three planets and an output ring.",
10
+ "anchors": {
11
+ "hub": {"at": [0, 0, "thick + collar"], "axis": [0, 0, -1], "ref": [1, 0, 0]},
12
+ "elbow": {"at": ["long", 0, "thick"], "axis": [0, 0, 1], "ref": [1, 0, 0]},
13
+ "output": {"at": ["long", 0, "thick + gear + arm_gap"], "axis": [0, 0, 1], "ref": [1, 0, 0]},
14
+ "motor": {"at": ["long", 0, 0], "axis": [0, 0, 1], "ref": [1, 0, 0]},
15
+ "clip1": {"at": ["long + post_r * cosd(p1)", "post_r * sind(p1)", "clip_at"], "axis": [0, 0, 1], "ref": ["cosd(p1)", "sind(p1)", 0]},
16
+ "clip2": {"at": ["long + post_r * cosd(p2)", "post_r * sind(p2)", "clip_at"], "axis": [0, 0, 1], "ref": ["cosd(p2)", "sind(p2)", 0]},
17
+ "clip3": {"at": ["long + post_r * cosd(p3)", "post_r * sind(p3)", "clip_at"], "axis": [0, 0, 1], "ref": ["cosd(p3)", "sind(p3)", 0]},
18
+ "switch": {"at": ["long + (switch_r - switch_pitch / 2) * cosd(switch_a)", "(switch_r - switch_pitch / 2) * sind(switch_a)", "thick + switch_high + switch_half"], "axis": [0, 0, 1], "ref": ["cosd(switch_a)", "sind(switch_a)", 0]},
19
+ "flag": {"at": ["flag_r", 0, "thick + flag_h"], "axis": [0, 0, 1]},
20
+ "cable": {"at": ["long / 2", 0, 0], "axis": [0, 0, 1]}
21
+ },
22
+ "variables": {
23
+ "long": {"value": "arm.upper", "unit": "mm", "rule": "Shoulder to elbow", "label": "Upper arm", "show": true, "interface": true},
24
+ "neck": {"value": 22, "unit": "mm", "rule": "The arm's width: its sag and sideways bending are in the chapter"},
25
+ "hub": {"value": 36, "unit": "mm", "rule": "Round the hexagon socket"},
26
+ "collar": {"value": "arm.arm_gap", "unit": "mm", "rule": "A collar on the arm's underside, on the bearing's inner race, so the outer race doesn't drag"},
27
+ "collar_d": {"value": 13.5, "unit": "mm", "rule": "On the inner race, clear of the outer"},
28
+ "hex": {"value": 8, "unit": "mm", "rule": "The spindle's hexagon"},
29
+ "hex_depth": {"value": "thick + collar - floor", "unit": "mm", "rule": "The socket's depth"},
30
+ "floor": {"value": 3, "unit": "mm", "rule": "What the screw pulls against: a socket's floor"},
31
+ "hex_fit": {"value": "x1c.fit + x1c.hole_comp", "unit": "mm", "rule": "Across the socket's flats, over the spindle's, printed"},
32
+ "screw": {"value": "m3.clearance + x1c.hole_comp", "unit": "mm", "rule": "M3 clearance"},
33
+ "gear": {"value": "arm.gear", "unit": "mm", "rule": "The fixed ring's face"},
34
+ "arm_gap": {"value": "arm.ring_gap", "unit": "mm", "rule": "Between the fixed ring and the output ring"},
35
+ "rim": {"value": 62, "unit": "mm", "rule": "Round the 54-tooth ring"},
36
+ "module": {"value": 1, "unit": "mm", "rule": "The gears'"},
37
+ "teeth": {"value": 54, "rule": "The fixed ring"},
38
+ "post_r": {"value": 37, "unit": "mm", "rule": "Three posts outside the output ring"},
39
+ "post": {"value": 7, "unit": "mm", "rule": "Each post's diameter"},
40
+ "lobe": {"value": 12, "unit": "mm", "rule": "The plate reaches out to each post"},
41
+ "p1": {"value": 30, "unit": "°", "rule": "First post"},
42
+ "p2": {"value": 150, "unit": "°", "rule": "Second post"},
43
+ "p3": {"value": 270, "unit": "°", "rule": "Third post"},
44
+ "rad": {"value": 0.017453293, "rule": "Radians in a degree"},
45
+ "clip_at": {"value": "thick + gear + arm_gap + gear + arm.flange + clip_gap", "unit": "mm", "rule": "Each post's tip, where its clip goes on, just past the output's flange"},
46
+ "clip_gap": {"value": 0.3, "unit": "mm", "rule": "The output turns under the clips with this to spare"},
47
+ "pilot": {"value": 2.9, "unit": "mm", "rule": "An M3 screw self-tapped into a post", "kind": "community"},
48
+ "pilot_depth": {"value": 8, "unit": "mm", "rule": "For an M3 × 10 through a clip"},
49
+ "flag_r": {"value": 50, "unit": "mm", "rule": "The home flag, as far from the shoulder as its switch"},
50
+ "flag_h": {"value": 5.5, "unit": "mm", "rule": "Down from the arm's underside far enough to reach the switch's lever"},
51
+ "flag_wide": {"value": 14, "unit": "mm", "rule": "Along the radius"},
52
+ "flag_thick": {"value": 4, "unit": "mm", "rule": "Tangential"},
53
+ "switch_a": {"value": 183, "unit": "°", "rule": "Round from straight on: the forearm's flag meets the lever at 160° of fold"},
54
+ "switch_r": {"value": 45.7, "unit": "mm", "rule": "The elbow switch, as far from the elbow as the forearm's flag: outside the posts' radius"},
55
+ "switch_x": {"value": "long + switch_r * cosd(switch_a)", "unit": "mm", "rule": "Elbow switch post"},
56
+ "switch_y": {"value": "switch_r * sind(switch_a)", "unit": "mm", "rule": "Elbow switch post"},
57
+ "switch_high": {"value": 9.5, "unit": "mm", "rule": "A post so the switch hangs level with the forearm's flag"},
58
+ "post_w": {"value": 14, "unit": "mm", "rule": "Elbow switch post, along the radius"},
59
+ "post_d": {"value": 12, "unit": "mm", "rule": "Elbow switch post, tangential"},
60
+ "switch_pitch": {"value": "arm.switch_pitch", "unit": "mm", "rule": "The switch's screw spacing"},
61
+ "switch_pilot": {"value": "m2.clearance - 0.6", "unit": "mm", "rule": "An M2 self-tapped", "kind": "community"},
62
+ "switch_depth": {"value": 9, "unit": "mm", "rule": "Pilot depth for M2 × 8"},
63
+ "segments": {"value": 64, "rule": "Round enough"},
64
+ "ring_segments": {"value": 96, "rule": "The rim's circle"},
65
+ "hex_segments": {"value": 6, "rule": "A hexagon's sides"},
66
+ "cos30": {"value": "cosd(30)", "rule": "A hexagon, across corners to across flats"},
67
+ "thick": {"value": "arm.arm", "unit": "mm", "rule": "The arm's thickness, and the elbow motor's plate: 16 lines of 0.42 and 40 layers"},
68
+ "bias_d": {"value": 4, "unit": "mm", "rule": "A hole for a rubber band, or a cable tie to hook one on"},
69
+ "bias_1": {"value": 30, "unit": "mm", "rule": "The shoulder's band, from here to a corner bolt of the base"},
70
+ "bias_2": {"value": 95, "unit": "mm", "rule": "The elbow's band, from here to the forearm"},
71
+ "switch_half": {"value": 3, "unit": "mm", "rule": "Half the switch's thickness"}
72
+ }
73
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "arm",
3
+ "description": "A SCARA arm sized from its task: an A5 sheet, a pen, 0.3 mm at 50 mm/s. EXAMPLES chapter 12 explains it.",
4
+ "material": "PLA",
5
+ "objects": [
6
+ "base",
7
+ "housing",
8
+ "sun",
9
+ "planet",
10
+ "speck",
11
+ "output",
12
+ "bridge",
13
+ "spindle",
14
+ "upper",
15
+ "clip",
16
+ "forearm",
17
+ "holder"
18
+ ]
19
+ }
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+ // Sends a step file (rulecad.steps/1, from cad plot) to the arm's Uno, line by line, each after the last was answered.
3
+ // node send.mjs <file.steps.json> --port /dev/tty.usbmodem101 [--machine arm.machine.json] [--no-home]
4
+ // node send.mjs <file.steps.json> --dry-run says what it would send, and checks it against the protocol
5
+ // No dependencies: a serial port is a file, set up with stty.
6
+ import fs from 'node:fs';
7
+ import { spawnSync } from 'node:child_process';
8
+ import { fileURLToPath } from 'node:url';
9
+
10
+ /** One step file as the protocol's lines, in order. @param {object} file @param {{ pen?: { up: number, down: number }, axes?: number }} [o] */
11
+ export function linesOf(file, { pen = { up: 90, down: 30 }, axes = 3 } = {}) {
12
+ if (file?.format !== 'rulecad.steps/1') throw new Error(`not a step file (format is ${JSON.stringify(file?.format)}, wanted rulecad.steps/1)`);
13
+ if (file.axes.length > axes) throw new Error(`${file.axes.length} axes in the file, and the streamer has ${axes}`);
14
+ const lines = [];
15
+ for (const b of file.blocks) {
16
+ if (b.type === 'pen') lines.push(`p ${b.state === 'down' ? pen.down : pen.up} ${Math.round(b.dwell * 1000)}`);
17
+ else if (b.type === 'dwell') lines.push(`w ${Math.round(b.time * 1000)}`);
18
+ else if (b.type === 'move') {
19
+ const s = [0, 1, 2].map((k) => b.steps[k] ?? 0), r = b.rate;
20
+ lines.push(`m ${s.join(' ')} ${Math.round(r.entry)} ${Math.max(1, Math.round(r.peak))} ${Math.round(r.exit)} ${Math.max(1, Math.round(r.accel))} ${b.accelSteps} ${b.decelSteps}`);
21
+ } else throw new Error(`a block of type ${JSON.stringify(b.type)}`);
22
+ }
23
+ return lines;
24
+ }
25
+
26
+ /** The lines to home a machine, from cad machine's description. @param {object} machine */
27
+ export function homeLines(machine) {
28
+ return machine.axes.flatMap((a, i) => (a.homing ? [`h ${i} ${a.homing.direction} ${a.homing.rate} ${a.homing.back}`] : []));
29
+ }
30
+
31
+ // What the firmware would say to a line, so the protocol can be tested with no board
32
+ export function dryRun(lines) {
33
+ const seen = { m: 0, p: 0, w: 0, h: 0, e: 0, d: 0 };
34
+ let peak = 0;
35
+ for (const [i, l] of lines.entries()) {
36
+ const [c, ...args] = l.split(' '), n = args.map(Number), at = `line ${i + 1} ("${l}")`;
37
+ if (l.length > 95) throw new Error(`${at}: longer than the streamer's 95 characters`);
38
+ if (!(c in seen)) throw new Error(`${at}: no such command`);
39
+ if (n.some((x) => !Number.isInteger(x))) throw new Error(`${at}: its numbers are whole`);
40
+ if (c === 'm') { if (n.length !== 9) throw new Error(`${at}: a block is 9 numbers`); if (!n.slice(0, 3).some(Boolean)) throw new Error(`${at}: a block that moves nothing`); if (n[4] > 8000) throw new Error(`${at}: ${n[4]} steps/s is past the streamer's 8000`); peak = Math.max(peak, n[4]); }
41
+ seen[c]++;
42
+ }
43
+ return { lines: lines.length, ...seen, peakRate: peak };
44
+ }
45
+
46
+ async function send(port, lines, say) {
47
+ const r = spawnSync('stty', [process.platform === 'darwin' ? '-f' : '-F', port, '115200', 'raw', '-echo', '-hupcl'], { encoding: 'utf8' });
48
+ if (r.status) throw new Error(`stty ${port}: ${r.stderr}`);
49
+ const rd = fs.createReadStream(port), wr = fs.createWriteStream(port);
50
+ let buffer = '', answer = null;
51
+ rd.on('data', (d) => { buffer += d; let i; while ((i = buffer.indexOf('\n')) >= 0) { const l = buffer.slice(0, i).trim(); buffer = buffer.slice(i + 1); if (answer && /^(ok|error)/.test(l)) { const a = answer; answer = null; a(l); } else if (l) say(l); } });
52
+ await new Promise((res) => setTimeout(res, 2500)); // the Uno resets when the port opens
53
+ for (const [i, l] of lines.entries()) {
54
+ const reply = await new Promise((res) => { answer = res; wr.write(`${l}\n`); });
55
+ if (reply !== 'ok') { wr.write('!\n'); throw new Error(`line ${i + 1} ("${l}"): ${reply}`); }
56
+ if (i % 100 === 0) say(`${i} of ${lines.length}`);
57
+ }
58
+ rd.destroy(); wr.end();
59
+ }
60
+
61
+ if (process.argv[1] === fileURLToPath(import.meta.url)) {
62
+ const args = process.argv.slice(2), opt = (k) => { const i = args.indexOf(`--${k}`); return i < 0 ? undefined : args[i + 1]; }, has = (k) => args.includes(`--${k}`);
63
+ const fileName = args.find((a, i) => !a.startsWith('--') && !['--port', '--machine'].includes(args[i - 1]));
64
+ if (!fileName) { console.error('usage: node send.mjs <file.steps.json> --port <device> [--machine <file>] [--no-home] | --dry-run'); process.exit(2); }
65
+ const file = JSON.parse(fs.readFileSync(fileName, 'utf8')), machine = opt('machine') ? JSON.parse(fs.readFileSync(opt('machine'), 'utf8')) : null;
66
+ const lines = ['e', ...(machine && !has('no-home') ? homeLines(machine) : []), ...linesOf(file, machine?.pen ? { pen: machine.pen } : {}), 'd'];
67
+ if (has('dry-run')) { const r = dryRun(lines); console.log(`dry run: ${r.lines} lines, ${r.m} blocks, ${r.p} pen moves, ${r.h} homes, peak ${r.peakRate} steps/s`); process.exit(0); }
68
+ if (!opt('port')) { console.error('--port <device>, or --dry-run'); process.exit(2); }
69
+ send(opt('port'), lines, console.log).then(() => console.log('done')).catch((e) => { console.error(e.message); process.exit(1); });
70
+ }