docs/kitbash.md: Rams and linkages: the model, the three kinds, the gates, the oracle rule, R-3 readings and costs

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-02 17:52:42 +01:00
commit c19a12403f

View file

@ -590,6 +590,72 @@ field. Nothing in a kit is run as Python. Division by zero, a result that is not
or `segments` that is not whole are refused when the part is built, naming the expression; so is a shape whose
vertices overflow.
## Rams and linkages
`brokkr_kitbash/ram.py` owns the motion of a ram across one hinge. It is numpy and the standard library, imports
nothing from the package, and no action calls it yet: a rig or a runtime loads the file alone. Its input is a
mechanism record: the hinge (pivot, unit axis, `lo` and `hi` in degrees, positive right-handed about the axis like
a pin joint's roll), a kind, and pins, each in its own body's rest frame.
| kind | pins | the ram runs |
| --- | --- | --- |
| `direct` | `a` on the parent, `b` on the child | `a` to `b` |
| `four_bar` | `a`; `rocker` (R), the rocker's pivot on the parent; `p` on the rocker; `c` on the child; `d` = `p` | `a` to `p`: the excavator bucket linkage, a coupler from `p` to `c` turning the child |
| `bell_crank` | the same, `d` elsewhere on the rocker, at least 2 bore from `p` | `a` to `d` |
Everything is a function of the record and the hinge angle: `pose` gives each body's rotation, the ram's base and
eye, its pin-to-pin length L and dL/dtheta; `length` and `extension` (L less the closed length) are what a rig
drives a rod from. Nothing stores a rocker angle or an extension. The loop is solved in the plane across the axis:
`p` lies where the rocker's circle about R meets the coupler's about `c`, on the side of R -> `c` it has at rest,
so an angle gives the same pose whatever was asked before it. A pin's coordinate along the axis says only where
its member stands: the rocker bars at R's, the coupler at `c`'s, the ram at `a`'s plus each of `offsets` (twins).
Rates are closed form: for a linkage dphi/dtheta = (axis x (c - O)) . k / ((axis x (p - R)) . k), k along the
coupler, and dL/dtheta = (axis x (d - R)) . u x dphi/dtheta, u along the ram.
`fit` runs the gates over the range, in this order, and a failed gate is a `RamError` naming the kind, the gate
and the angle or pin, with the readings attached:
- **assembly**: the rocker and coupler close the loop at every step, and on the way from rest when the range does
not hold 0; within 1e-9 of a dead centre is refused, since the branch would change there.
- **stroke**: barrel = L_min - over - back - e_b, and it holds the travel, the overtravel at both ends and the gland.
- **toggle**, **arm**: dL/dtheta keeps one sign, and |dL/dtheta| (the effective arm: hinge torque per unit ram
force) stays at or above `min_arm`.
- **load** (linkages): the coupler's pin load per unit ram force, |dL/dtheta| over the coupler's moment arm about
the hinge, stays at or under `max_load` (3).
- **clash**: clearance, when a distance oracle is given.
Transmission angles at `c` and `p` are reported and not gated. Over the R-3 knee's 125 degrees the best least
transmission angle of 200,000 sampled four-bars was 21.9 degrees, under the 30 to 40 a textbook asks; a gate there
would have refused every one of them. What a poor angle costs is pin load, and that is the gate.
Clearance takes `distance(body, points) -> distances`: `body` one of parent, child, rocker, coupler, `points` in
that body's rest frame. The barrel, the rod (per offset) and the link bars are sampled along their axes at most
`spacing` apart (default the barrel's radius) and carried into every body's rest frame at each angle but their
own; a sample is clear at radius + gap + spacing / 2 or more, which keeps the gap for the surface between samples.
Only the clevis ends are left out: `e_a` at the ram's base, 0.4 `e_b` at its eye, 1.5 `link_r` at a link's pins;
the pin a clevis turns on is not part of the body the oracle answers for. The oracle may cap what it returns at
`Ram.reach(spacing)`: on the R-3 meshes (3,564 triangles) a BVH nearest query capped there cost 0.55 us against
3.12 us uncapped. A four-bar at the default spacing asks 155 points an angle.
`search` seats a mechanism from a grid (ram seats; for linkages rocker pivots, child pins, `p` on a polar grid
about R, and `d` about R for a bell crank), refuses a grid over `limit` candidates naming the count, runs every
gate but clearance on all of them, then clearance in order of least arm; a miss returns the tally by gate and the
nearest miss. `record` and `from_record` carry a fitted mechanism as JSON; `swept` gives the ram's swept surface in
any body's frame, for a recess.
Readings on the R-3 knee (bore 0.042, tests/test_ram.py; bodies as boxes and cylinders, links as twin plates
outside the shin's side armour):
| drive | range | reading |
| --- | --- | --- |
| direct, the joint library's seats | 0..-62 | fits |
| direct, 2,000 seat pairs behind the knee | 0..-125 | none fits |
| four-bar behind the knee | 0..-125 | passes every gate before clearance: rocker swing 70.5, L 0.722..1.168, arm 0.096..0.265, pin load 1.61, transmission 16.5; refused on clearance: at -125 the barrel is inside the shin, a body the ram is not pinned to |
| bell crank in front of the knee | 0..-125 | fits: rocker swing 105.7, L 0.659..1.038, arm 0.091..0.215, pin load 1.13, transmission 13.8; ram and links clear the thigh, the shin and each other's bodies on both sides, least 0.109 beyond radius and gap to the shin (the coupler at -125) |
One candidate's gates before clearance cost 1.7 to 3.8 ms at 49 steps on Starfire (median 3.6 of five reps of 200
under other load); `limit` (20,000) is about a minute of them.
## The actions
| action | fields | what it does |