@rulecad/cad 0.7.35 → 0.7.37
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 +127 -37
- package/README.md +15 -2
- package/lib/assembly.mjs +133 -3
- package/package.json +2 -2
- package/schemas/assembly.schema.json +6 -1
package/EXAMPLES.md
CHANGED
|
@@ -460,30 +460,47 @@ export function main (v) {
|
|
|
460
460
|
"title": "Slide base",
|
|
461
461
|
"version": "0.1.0",
|
|
462
462
|
"uses": ["x1c"],
|
|
463
|
+
"engine": "manifold",
|
|
463
464
|
"anchors": {
|
|
464
465
|
"axle": { "at": [0, "centre", "thick"], "axis": [0, 0, 1] },
|
|
465
466
|
"track": { "at": ["start", 0, "thick"], "axis": [1, 0, 0] }
|
|
466
467
|
},
|
|
467
468
|
"variables": {
|
|
468
469
|
"centre": { "value": 7.2, "unit": "mm", "rule": "The pinion's axle above the rack's pitch line: its pitch radius and its shift, m z / 2 + x m" },
|
|
469
|
-
"length": { "value":
|
|
470
|
+
"length": { "value": 120, "unit": "mm", "rule": "The rack (75.4 mm) and its travel, ±22 mm" },
|
|
470
471
|
"start": { "value": -37.7, "unit": "mm", "rule": "The rack's middle under the knob at rest: half its 24 teeth, 12 × π" },
|
|
471
|
-
"
|
|
472
|
-
"
|
|
472
|
+
"strip": { "value": 12, "unit": "mm", "rule": "The strip under the rack, from behind its guide to under its teeth" },
|
|
473
|
+
"boss": { "value": 12, "unit": "mm", "rule": "Round the axle's foot" },
|
|
474
|
+
"foot": { "value": 40, "unit": "mm", "rule": "A foot across the middle, so it stands without rocking" },
|
|
475
|
+
"thick": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Fifteen layers" },
|
|
476
|
+
"pin": { "value": "3.2 - x1c.line / 2", "unit": "mm", "rule": "The axle: the pinion's 3.2 mm bore less half a line, so it turns" },
|
|
477
|
+
"pin_height": { "value": "x1c.layer * 60", "unit": "mm", "rule": "Up through the pinion and its knob" },
|
|
478
|
+
"guide_y": { "value": "0 - 5.45 - x1c.line / 2", "unit": "mm", "rule": "Behind the rack's back (1.25 + 4.2 mm under its pitch line), half a line clear" },
|
|
479
|
+
"guide": { "value": "x1c.line * 4", "unit": "mm", "rule": "The guide wall: four lines" },
|
|
480
|
+
"guide_height": { "value": "x1c.layer * 20", "unit": "mm", "rule": "Most of the rack's width" }
|
|
473
481
|
}
|
|
474
482
|
}
|
|
475
483
|
```
|
|
476
484
|
|
|
477
485
|
```js projects/home/objects/rail.js
|
|
478
|
-
// The base: a
|
|
486
|
+
// The base as little as holds it: a strip under the rack's travel with a wall behind the rack (so it slides straight
|
|
487
|
+
// and can't back away from the pinion), a boss carrying the pinion's axle, and a foot across the middle.
|
|
479
488
|
import jscad from '@jscad/modeling'
|
|
489
|
+
const { cuboid, cylinder } = jscad.primitives
|
|
480
490
|
|
|
481
491
|
export function main (v) {
|
|
482
|
-
|
|
492
|
+
const y0 = v.guide_y - v.guide, strip = cuboid({ size: [v.length, v.strip, v.thick], center: [0, y0 + v.strip / 2, v.thick / 2] })
|
|
493
|
+
const boss = cylinder({ radius: v.boss / 2, height: v.thick, center: [0, v.centre, v.thick / 2] })
|
|
494
|
+
const neck = cuboid({ size: [v.boss, v.centre - y0, v.thick], center: [0, (y0 + v.centre) / 2, v.thick / 2] })
|
|
495
|
+
const foot = cuboid({ size: [v.boss, v.foot, v.thick], center: [0, y0 + v.foot / 2 - v.boss, v.thick / 2] })
|
|
496
|
+
const axle = cylinder({ radius: v.pin / 2, height: v.pin_height, center: [0, v.centre, v.thick + v.pin_height / 2] })
|
|
497
|
+
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] })
|
|
498
|
+
return v.ops.union(strip, boss, neck, foot, axle, guide)
|
|
483
499
|
}
|
|
484
500
|
```
|
|
485
501
|
|
|
486
|
-
The assembly: the knob turns on the base's axle, and the rack slides along its track
|
|
502
|
+
The assembly: the knob turns on the base's axle (a pin printed with the base), and the rack slides along its track
|
|
503
|
+
against a guide wall, its middle under the knob at
|
|
487
504
|
rest, so half a turn either way (±22 mm) keeps the pinion on its teeth. The slide's joint doesn't say
|
|
488
505
|
how far it moves for a turn of the knob: its `mesh` says which joint drives it, and the gears' module and teeth (read
|
|
489
506
|
from the parts, so they can't disagree). The check works out the travel a turn and the phase that puts a tooth in a
|
|
@@ -503,6 +520,7 @@ gap, and says whether the axle is where the gears need it.
|
|
|
503
520
|
{ "id": "slide", "type": "prismatic", "parent": "rail.track", "child": "rack.slide", "min": -100, "max": 100,
|
|
504
521
|
"mesh": { "with": "knob", "module": "pinion.module", "teeth": ["pinion.teeth", "rack.teeth"], "shift": ["pinion.shift", 0] } }
|
|
505
522
|
],
|
|
523
|
+
"fits": [{ "a": "pinion", "b": "rail", "engage": "pinion.width", "note": "The pinion down its axle" }],
|
|
506
524
|
"poses": { "home": { "knob": 0 }, "out": { "knob": 150 } }
|
|
507
525
|
}
|
|
508
526
|
```
|
|
@@ -513,7 +531,8 @@ npx cad check home/slider --sweep --steps 12
|
|
|
513
531
|
```
|
|
514
532
|
|
|
515
533
|
The check says `knob drives slide: 43.98 mm of rack a turn`, the contact ratio, and that the axle is where the gears
|
|
516
|
-
need it (`centre distance 7.2 mm, as they need`). Set the base's `centre` to
|
|
534
|
+
need it (`centre distance 7.2 mm, as they need`). Set the base's `centre` to 6.9 and it fails: 0.3 mm closer is more than the
|
|
535
|
+
teeth's 0.15 mm of backlash allows, and they would jam. The
|
|
517
536
|
sweep turns the knob from −180° to 180° with the rack following, and names any teeth that touch on the way. The link
|
|
518
537
|
carries the knob as a slider, with the rack moving with it: `npx cad link home/slider --md`.
|
|
519
538
|
|
|
@@ -533,7 +552,7 @@ planetary({ module: 1, ratio: 0.25, planets: 3, held: 'ring', input: 'carrier',
|
|
|
533
552
|
|
|
534
553
|
The ring is the sun and two planets across (18 + 2 × 18 = 54), and the planets go in evenly: 18 + 54 = 72 is a whole
|
|
535
554
|
number of threes. The parts: a case with the ring on it and a pin for the sun, the sun with the spool's shaft, three
|
|
536
|
-
planets,
|
|
555
|
+
planets, the carrier with the planets' pins and the crank arm, and the crank's handle.
|
|
537
556
|
|
|
538
557
|
```json projects/home/objects/winder-case.json
|
|
539
558
|
{
|
|
@@ -544,21 +563,36 @@ planets, and the carrier with the planets' pins and the crank.
|
|
|
544
563
|
"uses": ["x1c"],
|
|
545
564
|
"engine": "manifold",
|
|
546
565
|
"variables": {
|
|
547
|
-
"radius": { "value":
|
|
566
|
+
"radius": { "value": 33, "unit": "mm", "rule": "The ring's rim: the case is a rim under it" },
|
|
567
|
+
"rim": { "value": "x1c.line * 14", "unit": "mm", "rule": "The rim under the ring's, wide enough for its push pins" },
|
|
568
|
+
"snap": { "value": 2, "unit": "mm", "rule": "Two push pins hold the ring still: their shafts" },
|
|
569
|
+
"snap_lip": { "value": 0.3, "unit": "mm", "rule": "The barb's lip, clicking over the floor of the ring's counterbore" },
|
|
570
|
+
"snap_back": { "value": 90, "unit": "deg", "rule": "A square back: it holds for good" },
|
|
571
|
+
"snap_at": { "value": 30.6, "unit": "mm", "rule": "Halfway across the ring's rim, between its roots and its outside" },
|
|
572
|
+
"snap_length": { "value": 4, "unit": "mm", "rule": "Up the ring's 6 mm rim to its 2 mm counterbore" },
|
|
573
|
+
"flange": { "value": 2, "unit": "mm", "rule": "A push pin's foot flange, buried in the rim" },
|
|
574
|
+
"hub": { "value": 12, "unit": "mm", "rule": "Round the sun's axle" },
|
|
575
|
+
"spoke": { "value": "x1c.line * 12", "unit": "mm", "rule": "Three spokes from the hub to the rim" },
|
|
576
|
+
"spokes": { "value": 3, "rule": "Three: it stands without rocking" },
|
|
548
577
|
"t": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Base, fifteen layers" },
|
|
549
578
|
"pin": { "value": 3, "unit": "mm", "rule": "The sun's axle" },
|
|
550
|
-
"pin_height": { "value":
|
|
579
|
+
"pin_height": { "value": 22, "unit": "mm", "rule": "Up through the sun and its shaft" }
|
|
551
580
|
}
|
|
552
581
|
}
|
|
553
582
|
```
|
|
554
583
|
|
|
555
584
|
```js projects/home/objects/winder-case.js
|
|
556
|
-
// The case: a
|
|
585
|
+
// The case as little as holds it: a rim the ring sits on (two push pins hold it still), a hub with the sun's axle
|
|
586
|
+
// standing in it, and spokes between.
|
|
557
587
|
import jscad from '@jscad/modeling'
|
|
558
|
-
const { cylinder } = jscad.primitives
|
|
588
|
+
const { cylinder, cuboid } = jscad.primitives
|
|
589
|
+
const { rotateZ } = jscad.transforms
|
|
559
590
|
|
|
560
591
|
export function main (v) {
|
|
561
|
-
|
|
592
|
+
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] }))
|
|
593
|
+
const spokes = Array.from({ length: v.spokes }, (_, k) => rotateZ((2 * Math.PI * k) / v.spokes, cuboid({ size: [v.radius - v.rim / 2, v.spoke, v.t], center: [(v.radius - v.rim / 2) / 2, 0, v.t / 2] })))
|
|
594
|
+
const snaps = [0, Math.PI].map((a) => jscad.transforms.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)))
|
|
595
|
+
return v.ops.union(rim, cylinder({ radius: v.hub / 2, height: v.t, center: [0, 0, v.t / 2] }), ...spokes, ...snaps,
|
|
562
596
|
cylinder({ radius: v.pin / 2, height: v.pin_height, center: [0, 0, v.t + v.pin_height / 2] }))
|
|
563
597
|
}
|
|
564
598
|
```
|
|
@@ -570,17 +604,33 @@ export function main (v) {
|
|
|
570
604
|
"title": "Winder ring gear",
|
|
571
605
|
"version": "0.1.0",
|
|
572
606
|
"uses": ["x1c"],
|
|
607
|
+
"engine": "manifold",
|
|
573
608
|
"variables": {
|
|
609
|
+
"rim": { "value": 66, "unit": "mm", "rule": "Across the outside: a rim wide enough for the push pins' holes" },
|
|
610
|
+
"snap": { "value": 2, "unit": "mm", "rule": "The case's push pins" },
|
|
611
|
+
"clear": { "value": "x1c.line / 2", "unit": "mm", "rule": "Half a line round a pin" },
|
|
612
|
+
"snap_at": { "value": 30.6, "unit": "mm", "rule": "As the case's pins" },
|
|
613
|
+
"counterbore": { "value": 2, "unit": "mm", "rule": "Deep enough that a barb clicks below the ring's top, clear of the crank arm" },
|
|
614
|
+
"barb": { "value": 1.6, "unit": "mm", "rule": "The counterbore's radius: the barb and its clearance" },
|
|
574
615
|
"module": { "value": 1, "unit": "mm", "rule": "3.6 lines across a tooth on the X1C" },
|
|
575
616
|
"teeth": { "value": 54, "rule": "The sun and two planets across: 18 + 2 × 18" },
|
|
576
|
-
"width": { "value": "x1c.layer *
|
|
617
|
+
"width": { "value": "x1c.layer * 30", "unit": "mm", "rule": "Face width, thirty layers: plenty for a spool's pull" }
|
|
577
618
|
}
|
|
578
619
|
}
|
|
579
620
|
```
|
|
580
621
|
|
|
581
622
|
```js projects/home/objects/winder-ring.js
|
|
623
|
+
// The ring gear, held to the case by two push pins: through-holes in its rim, counterbored at the top for the barbs.
|
|
624
|
+
import jscad from '@jscad/modeling'
|
|
625
|
+
const { cylinder } = jscad.primitives
|
|
626
|
+
|
|
582
627
|
export function main (v) {
|
|
583
|
-
|
|
628
|
+
const holes = [0, Math.PI].flatMap((a) => {
|
|
629
|
+
const x = v.snap_at * Math.cos(a), y = v.snap_at * Math.sin(a)
|
|
630
|
+
return [cylinder({ radius: v.snap / 2 + v.clear, height: v.width, center: [x, y, v.width / 2] }),
|
|
631
|
+
cylinder({ radius: v.barb, height: v.counterbore, center: [x, y, v.width - v.counterbore / 2] })]
|
|
632
|
+
})
|
|
633
|
+
return v.ops.subtract(v.gears.internal({ module: v.module, teeth: v.teeth, width: v.width, rim: v.rim }), ...holes)
|
|
584
634
|
}
|
|
585
635
|
```
|
|
586
636
|
|
|
@@ -595,7 +645,7 @@ export function main (v) {
|
|
|
595
645
|
"variables": {
|
|
596
646
|
"module": { "value": 1, "unit": "mm", "rule": "As the ring" },
|
|
597
647
|
"teeth": { "value": 18, "rule": "From planetary(): 18 for 4 : 1 with three planets" },
|
|
598
|
-
"width": { "value": "x1c.layer *
|
|
648
|
+
"width": { "value": "x1c.layer * 30", "unit": "mm", "rule": "As the ring" },
|
|
599
649
|
"bore": { "value": "3 + x1c.line / 2", "unit": "mm", "rule": "A 3 mm pin and half a line's clearance" }
|
|
600
650
|
}
|
|
601
651
|
}
|
|
@@ -621,7 +671,7 @@ The sun is a planet with the spool's shaft on top, bored through for its axle:
|
|
|
621
671
|
"variables": {
|
|
622
672
|
"module": { "value": 1, "unit": "mm", "rule": "As the ring" },
|
|
623
673
|
"teeth": { "value": 18, "rule": "From planetary()" },
|
|
624
|
-
"width": { "value": "x1c.layer *
|
|
674
|
+
"width": { "value": "x1c.layer * 30", "unit": "mm", "rule": "As the ring" },
|
|
625
675
|
"bore": { "value": "3 + x1c.line / 2", "unit": "mm", "rule": "On the case's 3 mm axle" },
|
|
626
676
|
"shaft": { "value": 8, "unit": "mm", "rule": "The spool's shaft, inside the sun's roots" },
|
|
627
677
|
"shaft_height": { "value": 12, "unit": "mm", "rule": "Up through the carrier, and a spool's width over it" }
|
|
@@ -641,54 +691,89 @@ export function main (v) {
|
|
|
641
691
|
}
|
|
642
692
|
```
|
|
643
693
|
|
|
644
|
-
The carrier: a disc over the gears, inside the ring's tips,
|
|
645
|
-
|
|
694
|
+
The carrier is drawn as it prints: a flat plate on the bed (the disc over the gears, inside the ring's tips, and the
|
|
695
|
+
crank arm in the same plane, reaching out over the ring), with a pin standing up from it for each planet. The assembly
|
|
696
|
+
turns it over, so its pins hang down into the planets. The planets turn every 120° at the sun-to-planet distance
|
|
697
|
+
(m (S + P) / 2 = 18 mm). The handle is a part of its own, printed upright and pressed into the arm's end, as a crank
|
|
698
|
+
handle usually is.
|
|
646
699
|
|
|
647
700
|
```json projects/home/objects/winder-carrier.json
|
|
648
701
|
{
|
|
649
702
|
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
650
703
|
"name": "winder-carrier",
|
|
651
|
-
"title": "Winder carrier and crank",
|
|
704
|
+
"title": "Winder carrier and crank arm",
|
|
652
705
|
"version": "0.1.0",
|
|
653
706
|
"uses": ["x1c"],
|
|
654
707
|
"engine": "manifold",
|
|
655
708
|
"anchors": {
|
|
656
|
-
"axis": { "at": [0, 0, 0], "axis": [0, 0, 1] },
|
|
657
|
-
"
|
|
658
|
-
"
|
|
659
|
-
"
|
|
709
|
+
"axis": { "at": [0, 0, 0], "axis": [0, 0, -1] },
|
|
710
|
+
"grip": { "at": ["arm", 0, 0], "axis": [0, 0, -1] },
|
|
711
|
+
"p0": { "at": ["a", 0, "t + drop"], "axis": [0, 0, -1] },
|
|
712
|
+
"p1": { "at": ["0 - a / 2", "a * 0.8660254", "t + drop"], "axis": [0, 0, -1] },
|
|
713
|
+
"p2": { "at": ["0 - a / 2", "0 - a * 0.8660254", "t + drop"], "axis": [0, 0, -1] }
|
|
660
714
|
},
|
|
661
715
|
"variables": {
|
|
662
716
|
"a": { "value": 18, "unit": "mm", "rule": "Sun to planet: m (S + P) / 2" },
|
|
663
|
-
"drop": { "value": "
|
|
717
|
+
"drop": { "value": "6 + x1c.layer * 2", "unit": "mm", "rule": "A planet's width and two layers' gap above it" },
|
|
664
718
|
"radius": { "value": 25, "unit": "mm", "rule": "Inside the ring's tips (26 mm)" },
|
|
665
719
|
"t": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Fifteen layers" },
|
|
666
720
|
"hole": { "value": 9, "unit": "mm", "rule": "Round the sun's 8 mm shaft" },
|
|
667
721
|
"pin": { "value": 3, "unit": "mm", "rule": "The planets' axles" },
|
|
668
|
-
"arm": { "value": 45, "unit": "mm", "rule": "The crank's reach" },
|
|
722
|
+
"arm": { "value": 45, "unit": "mm", "rule": "The crank's reach, out over the ring" },
|
|
669
723
|
"bar": { "value": 10, "unit": "mm", "rule": "The crank arm's width" },
|
|
670
|
-
"
|
|
671
|
-
"
|
|
724
|
+
"peg": { "value": 4, "unit": "mm", "rule": "The handle's peg" },
|
|
725
|
+
"fit": { "value": "x1c.line / 4", "unit": "mm", "rule": "A press fit for the handle's peg: a quarter line" },
|
|
726
|
+
"planets": { "value": 3, "rule": "From planetary(): three planets" }
|
|
672
727
|
}
|
|
673
728
|
}
|
|
674
729
|
```
|
|
675
730
|
|
|
676
731
|
```js projects/home/objects/winder-carrier.js
|
|
732
|
+
// The carrier as it prints: a flat plate (the disc and the crank arm) on the bed, the planets' pins standing up from it.
|
|
677
733
|
import jscad from '@jscad/modeling'
|
|
678
734
|
const { cylinder, cuboid } = jscad.primitives
|
|
679
735
|
|
|
680
736
|
export function main (v) {
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
const
|
|
684
|
-
const
|
|
685
|
-
const
|
|
686
|
-
const
|
|
687
|
-
return v.ops.subtract(v.ops.union(
|
|
737
|
+
const plate = v.ops.union(cylinder({ radius: v.radius, height: v.t, center: [0, 0, v.t / 2] }),
|
|
738
|
+
cuboid({ size: [v.arm, v.bar, v.t], center: [v.arm / 2, 0, v.t / 2] }), cylinder({ radius: v.bar / 2, height: v.t, center: [v.arm, 0, v.t / 2] }))
|
|
739
|
+
const third = (2 * Math.PI) / v.planets
|
|
740
|
+
const pins = [0, 1, 2].map((k) => cylinder({ radius: v.pin / 2, height: v.drop, center: [v.a * Math.cos(k * third), v.a * Math.sin(k * third), v.t + v.drop / 2] }))
|
|
741
|
+
const hole = cylinder({ radius: v.hole / 2, height: v.t, center: [0, 0, v.t / 2] })
|
|
742
|
+
const socket = cylinder({ radius: v.peg / 2 - v.fit, height: v.t, center: [v.arm, 0, v.t / 2] })
|
|
743
|
+
return v.ops.subtract(v.ops.union(plate, ...pins), hole, socket)
|
|
744
|
+
}
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
```json projects/home/objects/winder-handle.json
|
|
748
|
+
{
|
|
749
|
+
"$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
|
|
750
|
+
"name": "winder-handle",
|
|
751
|
+
"title": "Winder handle",
|
|
752
|
+
"version": "0.1.0",
|
|
753
|
+
"uses": ["x1c"],
|
|
754
|
+
"anchors": { "peg": { "at": [0, 0, "grip_height"], "axis": [0, 0, -1] } },
|
|
755
|
+
"variables": {
|
|
756
|
+
"grip": { "value": 9, "unit": "mm", "rule": "A finger round it" },
|
|
757
|
+
"grip_height": { "value": 22, "unit": "mm", "rule": "A finger's width and a little" },
|
|
758
|
+
"peg": { "value": 4, "unit": "mm", "rule": "Into the arm's socket" },
|
|
759
|
+
"peg_height": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Through the arm" }
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
```js projects/home/objects/winder-handle.js
|
|
765
|
+
// The handle as it prints: the grip on the bed, its peg standing on top.
|
|
766
|
+
import jscad from '@jscad/modeling'
|
|
767
|
+
const { cylinder } = jscad.primitives
|
|
768
|
+
|
|
769
|
+
export function main (v) {
|
|
770
|
+
return v.ops.union(cylinder({ radius: v.grip / 2, height: v.grip_height, center: [0, 0, v.grip_height / 2] }),
|
|
771
|
+
cylinder({ radius: v.peg / 2, height: v.peg_height, center: [0, 0, v.grip_height + v.peg_height / 2] }))
|
|
688
772
|
}
|
|
689
773
|
```
|
|
690
774
|
|
|
691
|
-
The assembly holds the ring
|
|
775
|
+
The assembly holds the ring on the case, by two push pins up from the case's rim into counterbored holes in the
|
|
776
|
+
ring's (the fit that says so is what the check reads as holding it), and turns the carrier on the crank; the `planetary` turns the sun and the
|
|
692
777
|
planets with it, in phase. The gears sit two layers off the case, so nothing rubs as it turns. The case, the sun and the carrier
|
|
693
778
|
are built with Manifold's booleans (`"engine": "manifold"`): closed solids, so the check measures them quickly.
|
|
694
779
|
|
|
@@ -701,13 +786,15 @@ are built with Manifold's booleans (`"engine": "manifold"`): closed solids, so t
|
|
|
701
786
|
{ "id": "ring", "object": "winder-ring", "at": [0, 0, "case.t"] },
|
|
702
787
|
{ "id": "sun", "object": "winder-sun" },
|
|
703
788
|
{ "id": "carrier", "object": "winder-carrier" },
|
|
789
|
+
{ "id": "handle", "object": "winder-handle" },
|
|
704
790
|
{ "id": "p0", "object": "winder-gear" },
|
|
705
791
|
{ "id": "p1", "object": "winder-gear" },
|
|
706
792
|
{ "id": "p2", "object": "winder-gear" }
|
|
707
793
|
],
|
|
708
794
|
"joints": [
|
|
709
795
|
{ "id": "sun", "type": "revolute", "parent": { "item": "case", "at": [0, 0, "case.t + 0.4"], "axis": [0, 0, 1] }, "child": "sun.axis", "min": -3000, "max": 3000 },
|
|
710
|
-
{ "id": "crank", "type": "revolute", "parent": { "item": "case", "at": [0, 0, "case.t + 0.8 + ring.width"], "axis": [0, 0, 1] }, "child": "carrier.axis", "min": -180, "max": 180, "label": "Crank" },
|
|
796
|
+
{ "id": "crank", "type": "revolute", "parent": { "item": "case", "at": [0, 0, "case.t + 0.8 + ring.width + carrier.t"], "axis": [0, 0, 1] }, "child": "carrier.axis", "min": -180, "max": 180, "label": "Crank" },
|
|
797
|
+
{ "id": "handle", "type": "fixed", "parent": "carrier.grip", "child": "handle.peg" },
|
|
711
798
|
{ "id": "p0", "type": "revolute", "parent": "carrier.p0", "child": "p0.axis", "min": -3000, "max": 3000 },
|
|
712
799
|
{ "id": "p1", "type": "revolute", "parent": "carrier.p1", "child": "p1.axis", "min": -3000, "max": 3000 },
|
|
713
800
|
{ "id": "p2", "type": "revolute", "parent": "carrier.p2", "child": "p2.axis", "min": -3000, "max": 3000 }
|
|
@@ -716,6 +803,9 @@ are built with Manifold's booleans (`"engine": "manifold"`): closed solids, so t
|
|
|
716
803
|
{ "sun": "sun", "carrier": "carrier", "ring": "ring", "planets": ["p0", "p1", "p2"], "drive": "carrier",
|
|
717
804
|
"module": "ring.module", "teeth": ["sun.teeth", "p0.teeth", "ring.teeth"] }
|
|
718
805
|
],
|
|
806
|
+
"fits": [{ "a": "handle", "b": "carrier", "min": "0 - carrier.fit * 2", "note": "The handle's peg pressed into the arm" },
|
|
807
|
+
{ "a": "ring", "b": "case", "fastens": true, "note": "The ring held still on the case by its two push pins" },
|
|
808
|
+
{ "a": "handle", "b": "carrier", "engage": "carrier.t", "note": "The handle's peg through the arm" }],
|
|
719
809
|
"poses": { "rest": { "crank": 0 }, "quarter": { "crank": 90 } }
|
|
720
810
|
}
|
|
721
811
|
```
|
package/README.md
CHANGED
|
@@ -366,9 +366,14 @@ then y, then z, as `rotate` does.
|
|
|
366
366
|
true` makes it a ring gear round its pinion. `shift` ([the driver's, this one's]), `pressureAngle` and `backlash` are
|
|
367
367
|
as `@rulecad/gears` takes them. Each gear is drawn as `v.gears` draws it (axis up its z, first tooth on +x; a rack
|
|
368
368
|
along its x, teeth up +y) and its joint is anchored at its centre, along its axis. The check gives the ratio, the
|
|
369
|
-
contact ratio and the centre distance (`mesh.centre`: closer than the gears need
|
|
370
|
-
each placed between the two axes
|
|
369
|
+
contact ratio and the centre distance (`mesh.centre`: closer than the gears need eats their backlash, and past it they jam; further adds backlash),
|
|
370
|
+
each placed between the two axes, and measures the pair from its drawn teeth (`mesh.backlash`, `mesh.interference`,
|
|
371
|
+
kept in `.cache/gears/`); `--sweep` turns the train and looks for teeth that touch. Both gears' axes sit on
|
|
371
372
|
one part, or on parts held still; planets on a carrier are a `planetary`.
|
|
373
|
+
- **Worms and bevels:** `"worm": true` (or `{ "diameter", "hand" }`) in a mesh makes the driving joint a worm and
|
|
374
|
+
this one its wheel, `teeth` [starts, the wheel's], the axes crossed at right angles; the check says the ratio,
|
|
375
|
+
whether it locks, and the centre distance. `"bevel": true` makes the two bevel gears, their axes meeting at the
|
|
376
|
+
shaft angle; the cones must share their apex (`mesh.bevel`). Both follow in phase, so `--sweep` turns them clean.
|
|
372
377
|
- **Planetary gearboxes:** `"planetary": [{ "sun": "sun", "carrier": "carrier", "ring": "ring", "planets": ["p0", "p1",
|
|
373
378
|
"p2"], "drive": "carrier", "module": 1, "teeth": ["sun.teeth", "p0.teeth", "ring.teeth"] }]` names the items. One of
|
|
374
379
|
the sun, carrier and ring is held (no joint, or a fixed one); the one `drive` names turns on its revolute, and the
|
|
@@ -376,6 +381,14 @@ then y, then z, as `rotate` does.
|
|
|
376
381
|
centre distance and contact ratio, and fails a planet that can't mesh with the sun and the ring where it is
|
|
377
382
|
(`planetary.phase`: planets go every 360° / n, and (S + R) / n is whole). `planetary()` in `@rulecad/gears` finds
|
|
378
383
|
teeth for a ratio.
|
|
384
|
+
- **What holds each part:** in an assembly that moves, every part but the first turns or slides on a joint, or is
|
|
385
|
+
fastened to the first through fits with `"fastens": true` (the pins, screws or press that do it, named in the fit's
|
|
386
|
+
note): `{ "a": "ring", "b": "case", "fastens": true, "note": "Two push pins" }`. A part only placed somewhere is
|
|
387
|
+
said (`assembly.loose`): a ring gear resting on its case would turn with its planets.
|
|
388
|
+
- **Onto a shaft:** `{ "a": "arm", "b": "crank", "engage": "arm.thick" }` checks that a part slid onto a shaft, a pin or a
|
|
389
|
+
peg goes that far onto it along the joint between them (`fit.engage`), not just against its end: an arm resting on
|
|
390
|
+
a shaft's end touches it face to face, as a seated one does, and nothing overlaps either way, so only this tells
|
|
391
|
+
them apart. It looks within `radius` (10 mm) of the joint's axis.
|
|
379
392
|
- **Loops:** each item has one joint to its parent. Where parts join in a ring (two links between the same two
|
|
380
393
|
parts), let joints place every part, then name the meeting that closes the ring in `loops`. The check measures it
|
|
381
394
|
in every pose: `"loops": [{ "a": "link_l.top", "b": "mount_l.axis", "label": "Left pivot lines up" }]`. Its anchors
|
package/lib/assembly.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import { host, readJson } from './host.mjs';
|
|
|
20
20
|
import fs from 'node:fs';
|
|
21
21
|
import crypto from 'node:crypto';
|
|
22
22
|
import path from 'node:path';
|
|
23
|
+
import { fileURLToPath } from 'node:url';
|
|
23
24
|
import { evaluate, loadRuleSet } from './rules.mjs';
|
|
24
25
|
import { paths, printerOf } from './workspace.mjs';
|
|
25
26
|
import { locate, build, readObject, jscad } from './design.mjs';
|
|
@@ -29,7 +30,7 @@ import { bounds } from '@rulecad/printcheck';
|
|
|
29
30
|
import { closest, closestAt, inside, distanceToFace, overlapAt } from '@rulecad/fit';
|
|
30
31
|
import { keys as keyCentres, readLayout, hasLayout } from './layout.mjs';
|
|
31
32
|
import { DOFS, frame, turn, mul, pathLength, jointValues, placeItems, jointMatrix } from '@rulecad/model-link';
|
|
32
|
-
import { gearModel, internalModel, rackModel, mesh as meshOf, phase, rackPhase } from '@rulecad/gears';
|
|
33
|
+
import { gearModel, internalModel, rackModel, mesh as meshOf, phase, rackPhase, contact, wormModel, wormMesh, bevelModel, bevelMesh } from '@rulecad/gears';
|
|
33
34
|
import { ops as booleans } from '@rulecad/shapes';
|
|
34
35
|
|
|
35
36
|
export const assemblyPath = (ref) => { const [project, name] = String(ref).split('/'); return path.join(paths.project(project || ''), 'assemblies', `${name || ''}.json`); };
|
|
@@ -366,6 +367,18 @@ function motionOf(a, placed, num, ref) {
|
|
|
366
367
|
return { items, joints, poses, pose: a.pose || Object.keys(poses)[0], loops, ref, marks, meshes };
|
|
367
368
|
}
|
|
368
369
|
|
|
370
|
+
// A pair measured from its drawn teeth (@rulecad/gears contact: backlash, transmission error, interference), kept in
|
|
371
|
+
// .cache/gears/ by the pair, the centre distance and the gears package's code, as it takes half a second
|
|
372
|
+
let gearsCode = null;
|
|
373
|
+
function measured(a, b, centre) {
|
|
374
|
+
gearsCode ||= (() => { const dir = path.dirname(fileURLToPath(import.meta.resolve('@rulecad/gears'))); return fs.readdirSync(dir).filter((f) => f.endsWith('.mjs') && f !== 'test.mjs').sort().map((f) => fs.readFileSync(path.join(dir, f), 'utf8')).join(''); })();
|
|
375
|
+
const file = paths.cache('gears', `${crypto.createHash('sha256').update(JSON.stringify([gearsCode, a, b, +centre.toFixed(6)])).digest('hex')}.json`);
|
|
376
|
+
if (!process.env.CAD_NO_CACHE && host.exists(file)) return JSON.parse(host.readText(file));
|
|
377
|
+
const r = contact(a, b, { centre, steps: 12 }), keep = { findings: r.findings, backlash: r.backlash, error: r.error };
|
|
378
|
+
try { host.writeText(file, JSON.stringify(keep)); } catch {} // (only slower without it)
|
|
379
|
+
return keep;
|
|
380
|
+
}
|
|
381
|
+
|
|
369
382
|
// A planetary gearbox: "planetary": [{ "sun", "carrier", "ring", "planets": [items], "drive": "sun" | "carrier" | "ring",
|
|
370
383
|
// "module", "teeth": [sun, planet, ring] }]. One of the sun, carrier and ring is held (no joint, or a fixed one); the
|
|
371
384
|
// one named by drive turns on its joint, and every other moving part (the third, and each planet on the carrier)
|
|
@@ -432,6 +445,10 @@ function planetaries(list, joints, items, num) {
|
|
|
432
445
|
if (Math.abs(miss) > 1e-6) f('fail', `planet ${p.id} can't mesh with the sun and the ring at once where it is (${(p.beta / DEG).toFixed(2)}° round the sun): planets go every ${(360 / planets.length).toFixed(2)}°, and (S + R) / planets must be whole (${S + R} / ${planets.length})`, 'planetary.phase', [O, centre]);
|
|
433
446
|
const m = meshOf(sun, planet, { centre: p.r });
|
|
434
447
|
for (const x of m.findings) f(x.level, `sun and ${p.id}: ${x.text}`, x.code, [O, centre]);
|
|
448
|
+
if (i === 0) {
|
|
449
|
+
for (const x of measured({ ...common, teeth: S }, { ...common, teeth: P }, p.r).findings) f(x.level, `sun and ${p.id}: ${x.text}`, x.code, [O, centre]);
|
|
450
|
+
for (const x of measured({ ...common, teeth: P }, { ...common, teeth: R, kind: 'internal' }, p.r).findings) f(x.level, `${p.id} and the ring: ${x.text}`, x.code, [O, centre]);
|
|
451
|
+
}
|
|
435
452
|
});
|
|
436
453
|
const ratioText = `the ${drive} drives the ${third}${held[0] === 'carrier' ? '' : ' and the planets'} (the ${held[0]} held): ${Number(Math.abs(k3).toFixed(4))} turns of the ${third} for each turn of the ${drive}, ${k3 * sg[drive] * sg[third] < 0 ? 'opposite ways' : 'the same way'}`;
|
|
437
454
|
out.push({ joint: follower.id, with: lead.id, kind: 'planetary', text: ratioText, findings, between: [O, O], planetary: true });
|
|
@@ -439,6 +456,80 @@ function planetaries(list, joints, items, num) {
|
|
|
439
456
|
return out;
|
|
440
457
|
}
|
|
441
458
|
|
|
459
|
+
// Bevel gears: "mesh": { "with": <the other's joint>, "module", "teeth": [its, this one's], "bevel": true } on revolutes
|
|
460
|
+
// whose axes meet at the shaft angle, each gear drawn as @rulecad/gears draws one (back end at z = 0, apex up z). The
|
|
461
|
+
// cones must share their apex. The ratio is the surface speeds' where the pitch cones touch; the phase puts a tooth
|
|
462
|
+
// of one against a space of the other along that line.
|
|
463
|
+
function bevelDrive(j, lead, spec, teeth, common, joints, items, num) {
|
|
464
|
+
const what = `joint ${j.id}: mesh`, DEG = Math.PI / 180;
|
|
465
|
+
const col = (W, k) => [W[k], W[4 + k], W[8 + k]], org = (W) => [W[3], W[7], W[11]];
|
|
466
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2], sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]], add = (a, b) => a.map((x, i) => x + b[i]), times = (a, k) => a.map((x) => x * k);
|
|
467
|
+
const crossP = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]], len = (v) => Math.hypot(...v), unit = (v) => times(v, 1 / len(v));
|
|
468
|
+
const ang = (v, x0, z) => Math.atan2(dot(crossP(x0, v), z), dot(x0, v));
|
|
469
|
+
const v = jointValues({ joints, poses: {} }, {}); v[lead.id] = [0]; v[j.id] = [0];
|
|
470
|
+
const worlds = placeItems({ items, joints }, v), W1 = worlds[lead.child], W2 = worlds[j.child];
|
|
471
|
+
const O1 = org(W1), Z1 = col(W1, 2), X1 = col(W1, 0), O2 = org(W2), Z2 = col(W2, 2), X2 = col(W2, 0);
|
|
472
|
+
const shaft = Math.acos(Math.max(-1, Math.min(1, dot(Z1, Z2)))) / DEG;
|
|
473
|
+
let g1, g2;
|
|
474
|
+
try { g1 = bevelModel({ ...common, teeth: teeth[0], mate: teeth[1], shaftAngle: shaft }); g2 = bevelModel({ ...common, teeth: teeth[1], mate: teeth[0], shaftAngle: shaft }); } catch (e) { throw new Error(`${what}: ${e.message}`); }
|
|
475
|
+
// each cone's apex: along its axis, its cone distance × cos δ from its back end
|
|
476
|
+
const A1 = add(O1, times(Z1, g1.coneDistance * Math.cos(g1.pitchAngle * DEG))), A2 = add(O2, times(Z2, g2.coneDistance * Math.cos(g2.pitchAngle * DEG)));
|
|
477
|
+
const findings = [];
|
|
478
|
+
const apart = len(sub(A1, A2));
|
|
479
|
+
if (apart > 0.01) findings.push({ level: 'fail', text: `the cones' apexes are ${Number(apart.toFixed(3))} mm apart: bevel gears mesh only when their cones meet at one point (move one along its axis)`, code: 'mesh.bevel' });
|
|
480
|
+
// where the pitch cones touch: from the apex, δ1 from the first's axis toward the second's (both pointing away)
|
|
481
|
+
const out1 = times(Z1, -1), out2 = times(Z2, -1), across = unit(sub(out2, times(out1, dot(out1, out2))));
|
|
482
|
+
const g = add(times(out1, Math.cos(g1.pitchAngle * DEG)), times(across, Math.sin(g1.pitchAngle * DEG))), P = add(A1, times(g, g1.coneDistance));
|
|
483
|
+
const radial = (Z, X) => { const r = sub(g, times(Z, dot(g, Z))); return ang(r, X, Z); };
|
|
484
|
+
const b1 = radial(Z1, X1), b2 = radial(Z2, X2);
|
|
485
|
+
// the second turns so the surface speeds match where they touch: ω2 = ω1 (Z1 × P)·(Z2 × P) / |Z2 × P|², P from the apex
|
|
486
|
+
const p = sub(P, A1), r = dot(crossP(Z1, p), crossP(Z2, p)) / dot(crossP(Z2, p), crossP(Z2, p));
|
|
487
|
+
const sgn = (jt, Z) => Math.sign(dot(col(mul(jt.parent < 0 ? [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0] : worlds[jt.parent], jt.a), 2), Z));
|
|
488
|
+
const s1 = sgn(lead, Z1), s2 = sgn(j, Z2), z2 = teeth[1];
|
|
489
|
+
const phi = b2 - Math.PI / z2 - r * b1;
|
|
490
|
+
j.follow = [lead.id, s2 * r * s1, (s2 * phi) / DEG];
|
|
491
|
+
const m = bevelMesh({ ...common, teeth: teeth[0], shaftAngle: shaft }, { ...common, teeth: teeth[1], shaftAngle: shaft });
|
|
492
|
+
findings.push(...m.findings);
|
|
493
|
+
return { joint: j.id, with: lead.id, kind: 'bevel', findings, between: [O1, O2], text: `bevel gears at ${Number(shaft.toFixed(2))}°, ${Number((teeth[0] / teeth[1]).toFixed(4))} turns of the second for each of the first (cones of ${Number(g1.pitchAngle.toFixed(2))}° and ${Number(g2.pitchAngle.toFixed(2))}°)` };
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// A worm and its wheel: "mesh": { "with": <the worm's joint>, "module", "teeth": [starts, wheel's teeth], "worm": {
|
|
497
|
+
// "diameter"?, "hand"? } } on the wheel's revolute, the axes crossed. In the wheel's middle plane the worm's thread is a
|
|
498
|
+
// rack along the worm's axis, moving a lead a turn: the wheel follows it as a pinion does a rack, its helix's turn at
|
|
499
|
+
// that plane taken into account. The worm is drawn as @rulecad/gears draws it (axis up its z, from z = 0).
|
|
500
|
+
function wormDrive(j, lead, spec, teeth, common, joints, items, num) {
|
|
501
|
+
const what = `joint ${j.id}: mesh`, DEG = Math.PI / 180;
|
|
502
|
+
const col = (W, k) => [W[k], W[4 + k], W[8 + k]], org = (W) => [W[3], W[7], W[11]];
|
|
503
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2], sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
504
|
+
const crossP = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]], len = (v) => Math.hypot(...v);
|
|
505
|
+
const ang = (v, x0, z) => Math.atan2(dot(crossP(x0, v), z), dot(x0, v));
|
|
506
|
+
const ws = spec.worm === true ? {} : spec.worm;
|
|
507
|
+
let w, wheel;
|
|
508
|
+
try {
|
|
509
|
+
w = wormModel({ ...common, starts: teeth[0], ...(ws.diameter != null ? { diameter: num(ws.diameter) } : {}), ...(ws.hand ? { hand: ws.hand } : {}) });
|
|
510
|
+
wheel = gearModel({ ...common, teeth: teeth[1], helix: w.leadAngle, hand: w.hand });
|
|
511
|
+
} catch (e) { throw new Error(`${what}: ${e.message}`); }
|
|
512
|
+
const v = jointValues({ joints, poses: {} }, {}); v[lead.id] = [0]; v[j.id] = [0];
|
|
513
|
+
const worlds = placeItems({ items, joints }, v), Ww = worlds[lead.child], W2 = worlds[j.child];
|
|
514
|
+
const Ow = org(Ww), U = col(Ww, 2), Xw = col(Ww, 0), O2 = org(W2), Z2 = col(W2, 2), X2 = col(W2, 0);
|
|
515
|
+
if (Math.abs(dot(U, Z2)) > 1e-6) throw new Error(`${what}: a worm's axis and its wheel's cross at right angles`);
|
|
516
|
+
// the line between the axes: across both (the worm's along U, the wheel's along Z2)
|
|
517
|
+
const rel = sub(O2, Ow), at = dot(rel, U), toWheel = sub(sub(rel, U.map((x) => x * at)), Z2.map((x) => x * dot(rel, Z2))), dist = len(toWheel), Y = toWheel.map((x) => x / dist), Zr = crossP(U, Y);
|
|
518
|
+
const sense = w.hand === 'left' ? -1 : 1, sw = Math.sign(dot(col(mul(lead.parent < 0 ? [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0] : worlds[lead.parent], lead.a), 2), U));
|
|
519
|
+
const s2 = Math.sign(dot(Z2, Zr)), tw = ang(Y, Xw, U), g2 = ang(X2, U, Zr) * 1, r2 = wheel.pitch / 2;
|
|
520
|
+
// the wheel's helix: its tooth 0 at the worm's plane is turned by k z there
|
|
521
|
+
const zMid = dot(sub(Ow, O2), Z2), k = (sense * Math.tan(w.leadAngle * DEG)) / r2;
|
|
522
|
+
const phr = rackPhase(wheel, at), L = w.lead;
|
|
523
|
+
// space centres of the thread, at the wheel, sit at z0 = sense L (tw − θw) / 2π along the worm; the wheel turns as on a rack
|
|
524
|
+
const theta = (dw) => { const z0 = (sense * L * (tw - sw * dw * DEG)) / (2 * Math.PI); return s2 * ((z0 - phr) / r2 - g2) - k * zMid; };
|
|
525
|
+
const a0 = theta(0), a1 = theta(1);
|
|
526
|
+
j.follow = [lead.id, (a1 - a0) / DEG, a0 / DEG];
|
|
527
|
+
const m = wormMesh({ ...common, starts: teeth[0], ...(ws.diameter != null ? { diameter: num(ws.diameter) } : {}), ...(ws.hand ? { hand: ws.hand } : {}) }, { teeth: teeth[1] });
|
|
528
|
+
const c = meshOf(wheel, rackModel({ ...common, teeth: 4 }), { centre: dist - w.pitch / 2 });
|
|
529
|
+
const findings = [...m.findings, ...c.findings.filter((x) => x.code === 'mesh.centre').map((x) => ({ ...x, text: x.text.replace("centre to the rack's pitch line", "the wheel's centre to the worm's pitch cylinder") }))];
|
|
530
|
+
return { joint: j.id, with: lead.id, kind: 'worm', findings, between: [Ow.map((x, i) => x + U[i] * at), O2], text: `a worm of ${teeth[0]} start${teeth[0] > 1 ? 's' : ''}, ${Number((teeth[1] / teeth[0]).toFixed(3))} turns of the worm for one of the wheel` };
|
|
531
|
+
}
|
|
532
|
+
|
|
442
533
|
// Gears that mesh: "mesh": { "with": <the driving joint>, "module", "teeth": [its, this one's], "shift"?, "ring"? } on
|
|
443
534
|
// a revolute (a gear, or a ring with "ring": true) or a prismatic (a rack). It becomes a follow: the ratio from the
|
|
444
535
|
// teeth, and the offset that puts a tooth in a gap, read from where the two gears are with their joints at 0. Each
|
|
@@ -464,11 +555,13 @@ function gearMeshes(joints, items, num) {
|
|
|
464
555
|
if (!lead) throw new Error(`${what}: "with" names the driving joint (${joints.filter((x) => x !== j).map((x) => x.id).join(', ')}; got ${JSON.stringify(spec.with)})`);
|
|
465
556
|
if (lead.type !== 'revolute') throw new Error(`${what}: ${lead.id} is a ${lead.type}; the driver is a gear turning on a revolute`);
|
|
466
557
|
if (j.type !== 'revolute' && j.type !== 'prismatic') throw new Error(`${what}: a gear turns on a revolute, a rack slides on a prismatic (this is a ${j.type})`);
|
|
467
|
-
const kind = j.type === 'prismatic' ? 'rack' : spec.ring ? 'internal' : 'external';
|
|
558
|
+
const kind = spec.bevel ? 'bevel' : spec.worm ? 'worm' : j.type === 'prismatic' ? 'rack' : spec.ring ? 'internal' : 'external';
|
|
468
559
|
if (!(lead.parent === j.parent || (still(lead.parent) && still(j.parent)))) throw new Error(`${what}: ${lead.id} and ${j.id} turn on parts that move apart (a planet on a carrier): a mesh needs both on one part, or both on parts held still`);
|
|
469
560
|
const teeth = list(spec.teeth).map(num), shift = list(spec.shift ?? [0, 0]).map(num);
|
|
470
561
|
if (teeth.length !== 2) throw new Error(`${what}: teeth is [the driver's, this one's] (got ${JSON.stringify(spec.teeth)})`);
|
|
471
562
|
const common = { module: num(spec.module), ...(spec.pressureAngle != null ? { pressureAngle: num(spec.pressureAngle) } : {}), ...(spec.backlash != null ? { backlash: num(spec.backlash) } : {}) };
|
|
563
|
+
if (kind === 'worm') { out.push(wormDrive(j, lead, spec, teeth, common, joints, items, num)); continue; }
|
|
564
|
+
if (kind === 'bevel') { out.push(bevelDrive(j, lead, spec, teeth, common, joints, items, num)); continue; }
|
|
472
565
|
let A, B;
|
|
473
566
|
try {
|
|
474
567
|
A = gearModel({ ...common, teeth: teeth[0], shift: shift[0] });
|
|
@@ -492,13 +585,14 @@ function gearMeshes(joints, items, num) {
|
|
|
492
585
|
const k = (Math.PI * A.pitch) / 360, g1 = angleIn(along(X1, Zr), U, Zr);
|
|
493
586
|
j.follow = [lead.id, sTravel * s1 * k, sTravel * (k * g1 + rackPhase(A, at))];
|
|
494
587
|
const m = meshOf(A, B, { centre: height });
|
|
495
|
-
result.findings = m.findings; result.between = [O1, [R0[0] + at * U[0], R0[1] + at * U[1], R0[2] + at * U[2]]]; result.text = m.text;
|
|
588
|
+
result.findings = [...m.findings, ...measured({ ...common, teeth: teeth[0], shift: shift[0] }, { ...common, teeth: teeth[1], kind: 'rack' }, height).findings]; result.between = [O1, [R0[0] + at * U[0], R0[1] + at * U[1], R0[2] + at * U[2]]]; result.text = m.text;
|
|
496
589
|
} else {
|
|
497
590
|
const O2 = org(W2), X2 = col(W2, 0), Z2 = col(W2, 2), ax2 = axisOf(j);
|
|
498
591
|
if (Math.abs(Math.abs(dot(ax2.dir, Z2)) - 1) > 1e-6 || len(along(sub(O2, ax2.at), ax2.dir)) > 1e-4) throw new Error(`${what}: ${j.id} doesn't turn its gear about the gear's own centre and axis: anchor the gear's joint at its centre, along its axis`);
|
|
499
592
|
if (Math.abs(Math.abs(dot(Z1, Z2)) - 1) > 1e-6) throw new Error(`${what}: ${lead.id} and ${j.id} turn about axes that aren't parallel (spur gears need parallel axes)`);
|
|
500
593
|
const s = Math.sign(dot(Z1, Z2)), d = along(sub(O2, O1), Z1), beta = angleIn(d, X1, Z1), g2 = angleIn(along(X2, Z1), X1, Z1);
|
|
501
594
|
const m = meshOf(A, B, { centre: len(d) });
|
|
595
|
+
m.findings.push(...measured({ ...common, teeth: teeth[0], shift: shift[0] }, { ...common, teeth: teeth[1], shift: shift[1] ?? 0, kind }, len(d)).findings);
|
|
502
596
|
// b's angle in the driver's frame is ratio × a's + phase; its joint measures about its own z (the other way when flipped)
|
|
503
597
|
j.follow = [lead.id, s * m.ratio, s * (phase(A, B, beta) - g2)];
|
|
504
598
|
result.findings = m.findings; result.between = [O1, O2]; result.text = m.text;
|
|
@@ -602,6 +696,7 @@ export function checkAssembly(s) {
|
|
|
602
696
|
for (const x of s.fits) {
|
|
603
697
|
if (x.poses && !x.poses.includes(s.pose)) continue; // a fit for some poses only: the folded screen over the keys
|
|
604
698
|
if (x.holes) { holesFit(x); continue; }
|
|
699
|
+
if (x.engage != null) { engageFit(x); continue; }
|
|
605
700
|
const A = pickIn(x.a, x), key = x.note || `${x.a} / ${x.b}`;
|
|
606
701
|
const lo = x.min != null ? x.num(x.min) : -Infinity, hi = x.max != null ? x.num(x.max) : Infinity;
|
|
607
702
|
const reach = Math.max(2, ...[lo, hi].filter(Number.isFinite)) + 1; // look past the range, so a gap near it is measured
|
|
@@ -635,6 +730,29 @@ export function checkAssembly(s) {
|
|
|
635
730
|
{ code: 'fit', values: { ...(worst.gap < 0 ? { overlap: -worst.gap } : { gap: worst.gap }), min: lo, max: hi, inRange: results.filter((r) => r.ok).length, copies: results.length },
|
|
636
731
|
refs: { a: x.a, b: x.b, label: x.label, ...(s.pose ? { pose: s.pose } : {}), outOfRange: results.filter((r) => !r.ok).map((r) => r.id), ...where }, ...(worst.at ? { at: { lo: worst.at, hi: worst.at } } : {}) });
|
|
637
732
|
}
|
|
733
|
+
// Engage fits: a part slid onto a shaft, a pin or a peg goes onto it, not just against its end. Along the axis of the
|
|
734
|
+
// joint between them, each part's material near the axis (within radius, 10 mm) spans a stretch; how far the two
|
|
735
|
+
// stretches overlap is how far one is on the other. An arm resting on a shaft's end touches it face to face, as a
|
|
736
|
+
// seated one does, and nothing overlaps either way: only this tells them apart.
|
|
737
|
+
function engageFit(x) {
|
|
738
|
+
const top = (n) => String(n).split(/[.@]/)[0], ids = s.motion?.items.map((i) => i[0]) || [], a = top(x.a), b = top(x.b), label = x.note || `${x.a} onto ${x.b}`;
|
|
739
|
+
const j = (s.motion?.joints || []).find((jt) => { const pair = [ids[jt.child], jt.parent < 0 ? null : ids[jt.parent]]; return pair.includes(a) && pair.includes(b); });
|
|
740
|
+
if (!j) return f('fail', `${label}: no joint between ${a} and ${b} to measure along (engage measures along the joint that holds one on the other)`, null, { code: 'fit.engage', refs: { a: x.a, b: x.b } });
|
|
741
|
+
const worlds = placeItems(s.motion, s.jointValues), P = mul(j.parent < 0 ? [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0] : worlds[j.parent], j.a);
|
|
742
|
+
const O = [P[3], P[7], P[11]], Z = [P[2], P[6], P[10]], r = x.radius != null ? x.num(x.radius) : 10, need = x.num(x.engage);
|
|
743
|
+
const span = (parts) => {
|
|
744
|
+
let lo = Infinity, hi = -Infinity;
|
|
745
|
+
for (const p of parts) for (const t of p.triangles) for (const v of t) {
|
|
746
|
+
const d = [v[0] - O[0], v[1] - O[1], v[2] - O[2]], along = d[0] * Z[0] + d[1] * Z[1] + d[2] * Z[2];
|
|
747
|
+
if (Math.hypot(d[0] - along * Z[0], d[1] - along * Z[1], d[2] - along * Z[2]) <= r) { lo = Math.min(lo, along); hi = Math.max(hi, along); }
|
|
748
|
+
}
|
|
749
|
+
return [lo, hi];
|
|
750
|
+
};
|
|
751
|
+
const [la, ha] = span(pickIn(x.a, x)), [lb, hb] = span(pickIn(x.b, x)), on = Math.max(0, Math.min(ha, hb) - Math.max(la, lb));
|
|
752
|
+
const ok = on >= need - 1e-3; // (flush is on: a hair under, in the floating point, is not short)
|
|
753
|
+
f(ok ? 'pass' : 'fail', `${label}: ${on > 1e-3 ? `${mm(on)} mm on` : `not on at all (${Math.max(la, lb) - Math.min(ha, hb) < 1e-3 ? 'end to end' : 'apart'})`} along their joint${ok ? '' : `, where it should go ${mm(need)} mm on: its anchor is on the wrong face, or the shaft too short`}`, ok ? null : `${a}: not on ${b}`, { code: 'fit.engage', values: { engaged: on, need }, refs: { a: x.a, b: x.b, joint: j.id } });
|
|
754
|
+
}
|
|
755
|
+
|
|
638
756
|
// Holes fits: each mounting hole's screw path, clear into a hole, with material round it
|
|
639
757
|
function holesFit(x) {
|
|
640
758
|
const A = pick(x.a), B = pick(x.b), label = x.label || `${x.a} into ${x.b}`;
|
|
@@ -667,6 +785,18 @@ export function checkAssembly(s) {
|
|
|
667
785
|
}
|
|
668
786
|
if (outside.length) f('fail', `joints out of range: ${outside.join(', ')}`, `${outside.length} joints out of range`, { code: 'joint.range', refs: { joints: outside } });
|
|
669
787
|
for (const l of loopGaps(s)) f(l.ok ? 'pass' : 'fail', `${l.label}: ${l.ok ? 'closed' : 'apart'} (${mm(l.gap)} mm, axes ${mm(l.angle)}° apart)`, `${l.label}: ${l.ok ? 'closed' : 'apart'}`, { code: 'loop', values: { gap: l.gap, angle: l.angle }, refs: { label: l.label } });
|
|
788
|
+
// Held by something: in a mechanism, every part but the first either turns or slides on a joint, or is fastened,
|
|
789
|
+
// through a chain of fits with "fastens", to the first. A part only placed somewhere stays there in the model and
|
|
790
|
+
// nowhere else: a ring gear resting on its case turns with the planets; a pawl resting on its post walks off it.
|
|
791
|
+
if (s.motion.joints.some((j) => j.type !== 'fixed')) {
|
|
792
|
+
const ids = s.motion.items.map((x) => x[0]), top = (n) => String(n).split(/[.@]/)[0];
|
|
793
|
+
const held = new Set([ids[0], ...s.motion.joints.map((j) => ids[j.child])]), links = s.fits.filter((x) => x.fastens).map((x) => [top(x.a), top(x.b)]);
|
|
794
|
+
for (let grew = true; grew;) { grew = false; for (const [a, b] of links) { if (held.has(a) && !held.has(b)) { held.add(b); grew = true; } if (held.has(b) && !held.has(a)) { held.add(a); grew = true; } } }
|
|
795
|
+
const placed = new Set(s.objects.filter((o) => !o.unplaced && o.role !== 'reference').map((o) => top(o.id)));
|
|
796
|
+
const loose = ids.filter((id) => !held.has(id) && placed.has(id));
|
|
797
|
+
if (loose.length) f('warn', `${loose.join(', ')} ${loose.length > 1 ? 'are' : 'is'} placed, but nothing holds ${loose.length > 1 ? 'them' : 'it'}: give ${loose.length > 1 ? 'each' : 'it'} a joint, or fasten it to what it sits on (pins, screws, a press) and say so with a fit that "fastens"`, `${loose.length} loose`, { code: 'assembly.loose', refs: { items: loose } });
|
|
798
|
+
else f('pass', `every part turns or slides on a joint, or is fastened to the ${ids[0]}`, null, { code: 'assembly.held' });
|
|
799
|
+
}
|
|
670
800
|
// Gears: each mesh's centre distance and contact ratio, said between the two axes (the rest by --sweep)
|
|
671
801
|
for (const g of s.motion.meshes || []) {
|
|
672
802
|
f('info', g.planetary ? g.text : `${g.with} drives ${g.joint}: ${g.text}`, null, { code: 'mesh.ratio', refs: { joints: [g.with, g.joint] } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.37",
|
|
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": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@rulecad/fea": "^0.2.1",
|
|
71
71
|
"@rulecad/topopt": "^0.3.0",
|
|
72
72
|
"@rulecad/flexures": "^0.5.0",
|
|
73
|
-
"@rulecad/gears": "^0.
|
|
73
|
+
"@rulecad/gears": "^0.3.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"@rulecad/pcb": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0"
|
|
@@ -64,6 +64,9 @@
|
|
|
64
64
|
"properties": {
|
|
65
65
|
"a": { "$ref": "#/$defs/names" },
|
|
66
66
|
"b": { "$ref": "#/$defs/names" },
|
|
67
|
+
"engage": { "$ref": "#/$defs/expr", "description": "a goes at least this far (mm) onto b along the joint between them: a part slid onto a shaft or a pin, not resting on its end" },
|
|
68
|
+
"radius": { "$ref": "#/$defs/expr", "description": "With engage: how near the joint's axis to look (mm, default 10)" },
|
|
69
|
+
"fastens": { "type": "boolean", "description": "a and b are fastened together (pins, screws, a press): what holds a part that has no joint" },
|
|
67
70
|
"min": { "$ref": "#/$defs/expr" },
|
|
68
71
|
"max": { "$ref": "#/$defs/expr" },
|
|
69
72
|
"note": { "type": "string" },
|
|
@@ -114,7 +117,9 @@
|
|
|
114
117
|
"shift": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "$ref": "#/$defs/expr" } },
|
|
115
118
|
"pressureAngle": { "$ref": "#/$defs/expr" },
|
|
116
119
|
"backlash": { "$ref": "#/$defs/expr" },
|
|
117
|
-
"ring": { "type": "boolean" }
|
|
120
|
+
"ring": { "type": "boolean" },
|
|
121
|
+
"bevel": { "type": "boolean" },
|
|
122
|
+
"worm": { "anyOf": [{ "type": "boolean" }, { "type": "object", "additionalProperties": false, "properties": { "diameter": { "$ref": "#/$defs/expr" }, "hand": { "enum": ["right", "left"] } } }] }
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
125
|
}
|