Arms: rename GripDirection→GripperDirection (string literal); rotate convention so 0°=+X#1034
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GripDirectionenum →GripperDirection = Literal[\"front\",\"back\",\"left\",\"right\"](andGripOrientation→GripperOrientation). String-literal type plays nicely with JSON, kwargs, and IDE autocomplete; enum was overkill.direction=0°is+X(CCW about +Z, right-hand rule), instead of-Y. New cardinal mapping:right=0°, back=90°, left=180°, front=270°._direction_degrees_to_grip_directionmapping 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 bedirection=0is nowdirection=270, still emitting firmwaregr=1).OrientableArm._resource_width_for_directionflips:direction%180==0is now along ±X (right/left), so jaws grip in Y._LEGACY_TO_NEW_GRIPbecomes a static enum→string dict.architecture.mdand the user guide spell out the convention with a table.This PR is the v1 half of the work. KX2 FK/IK in
kx2-backendwill 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 regressionspytest pylabrobot/— 1699 passed; the 13 unrelated xarm6 / scila failures pre-exist onv1b1and are unaffectedgr=1..4so this should be safe, but worth a sanity move)🤖 Generated with Claude Code