Skip to content

Arms: rename GripDirection→GripperDirection (string literal); rotate convention so 0°=+X#1034

Merged
rickwierenga merged 2 commits into
v1b1from
gripper-direction-rotate-convention
May 14, 2026
Merged

Arms: rename GripDirection→GripperDirection (string literal); rotate convention so 0°=+X#1034
rickwierenga merged 2 commits into
v1b1from
gripper-direction-rotate-convention

Conversation

@rickwierenga
Copy link
Copy Markdown
Member

Summary

  • Rename GripDirection enum → GripperDirection = Literal[\"front\",\"back\",\"left\",\"right\"] (and GripOrientationGripperOrientation). String-literal type plays nicely with JSON, kwargs, and IDE autocomplete; enum was overkill.
  • Rotate the cross-backend rotation convention so direction=0° is +X (CCW about +Z, right-hand rule), instead of -Y. New cardinal mapping: right=0°, back=90°, left=180°, front=270°.
  • iSWAP backend updated for both: _direction_degrees_to_grip_direction mapping rotates one step (firmware contract unchanged), iSWAPBackend.rotate(grip_direction=…) now takes a string. Tests updated to feed the new degree values; physical poses unchanged (e.g. "front" pickup that used to be direction=0 is now direction=270, still emitting firmware gr=1).
  • OrientableArm._resource_width_for_direction flips: direction%180==0 is now along ±X (right/left), so jaws grip in Y.
  • Legacy _LEGACY_TO_NEW_GRIP becomes a static enum→string dict.
  • architecture.md and the user guide spell out the convention with a table.

This PR is the v1 half of the work. KX2 FK/IK in kx2-backend will need the same yaw rotation as a follow-up after this lands and merges in.

Test plan

  • pytest pylabrobot/capabilities/arms/ pylabrobot/arms/ pylabrobot/hamilton/ pylabrobot/legacy/liquid_handling/ — 582 passed, 0 regressions
  • Wider sweep pytest pylabrobot/ — 1699 passed; the 13 unrelated xarm6 / scila failures pre-exist on v1b1 and are unaffected
  • Smoke-test on a real STAR(let) iSWAP (the firmware-command test pins gr=1..4 so this should be safe, but worth a sanity move)
  • Sphinx doc build

🤖 Generated with Claude Code

rickwierenga and others added 2 commits May 12, 2026 22:08
…convention so 0°=+X

`GripDirection` was an enum with `FRONT=0°, RIGHT=90°, BACK=180°, LEFT=270°`,
which baked the deck-frame "front" axis into the value 0. That entangled the
math (CCW yaw about +Z) with a deck convention, and made the type clunky for
JSON/serialization. Two changes:

1. Cross-backend convention is now: `direction` (and `CartesianPose.rotation.z`)
   is the world yaw of the front finger in degrees, CCW about +Z, with **0°=+X**.
   Cardinal mapping rotates 90°: `right=0°, back=90°, left=180°, front=270°`.

2. `GripDirection` enum → `GripperDirection = Literal["front","back","left","right"]`.
   `GripOrientation` → `GripperOrientation = Union[GripperDirection, float]`.
   Resolver in `OrientableArm` validates the string and looks up the new mapping.

Backend updates:
- iSWAP (`_direction_degrees_to_grip_direction`): firmware grip_direction stays
  1..4 in physical-axis order (firmware contract is unchanged); the
  user-degrees → firmware-code mapping rotates by one step. `iSWAPBackend.rotate`
  now takes a `GripperDirection` string and string-compares.
- Grip-width axis selection in `OrientableArm._resource_width_for_direction`
  flips: `direction%180==0` is now along +X (right/left), so jaws grip in Y.
- Legacy `_LEGACY_TO_NEW_GRIP` becomes a static enum→string dict (no more
  `_NewGripDirection[d.name]` enum bridging).

Tests updated to feed the new degree values; physical poses preserved (e.g.
"front" pickup that used to be `direction=0` is now `direction=270`, still
producing firmware `gr=1`). All arm/iSWAP/legacy LH tests pass; the 13
unrelated pre-existing xarm6/scila failures on v1b1 are untouched.

architecture.md and the user guide spell out the convention with a table.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… import isn't unused

ruff F401 caught the unused `GripperDirection` import in orientable_arm.py.
Annotate the dict as Dict[GripperDirection, float] — this also documents
the keys, which the lookup at L33 relies on being one of the four literals.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rickwierenga rickwierenga merged commit 1a7044f into v1b1 May 14, 2026
1 of 19 checks passed
@rickwierenga rickwierenga deleted the gripper-direction-rotate-convention branch May 14, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant