Skip to content

Expose iSWAPBackend.rotation_drive_request_position()#1011

Open
BioCam wants to merge 6 commits intov1b1from
expose-request_iswap_rotation_drive_position
Open

Expose iSWAPBackend.rotation_drive_request_position()#1011
BioCam wants to merge 6 commits intov1b1from
expose-request_iswap_rotation_drive_position

Conversation

@BioCam
Copy link
Copy Markdown
Collaborator

@BioCam BioCam commented Apr 26, 2026

It is time to re-start "Epic: Tame the iSWAP" ... a series of tasks/PRs aimed at making this unpredictable beast more reliable, predictable and ready for our agents.

This is PR 0 of many to come...

Adds iSWAPBackend.rotation_drive_request_position() - returns the iSWAP rotation drive position as a Coordinate in deck space - plus the supporting rotation_drive_request_x_offset() read of EEPROM kg via C0:RA.
Also renames a few drive methods so naming reflects what they actually return.

Problem

The iSWAP arm is a 2-link planar manipulator (L1 = L2 = 138 mm) whose base — the rotation drive — sits at a fixed offset from the X-arm carriage.
Every kinematic calculation on the iSWAP — forward kinematics from joint angles to gripper pose, inverse kinematics from a target plate pose to joint angles, reachable-workspace and collision checks — starts from that base point in deck coordinates.
Without it, there is no anchor to put the arm geometry on the deck.

Today the rotation drive's deck position has to be reconstructed by hand from three separate reads:

  1. X-arm carriage center,
  2. the per-machine X offset stored as EEPROM kg (set during service, currently exposed nowhere in PLR),
  3. rotation-drive Y from request_gripper_y_position, and the 13 mm vertical drop from the rotation-drive plane to the gripper finger plane to recover Z.
Screenshot 2026-04-26 at 20 07 38

This is the foundational primitive for moving iSWAP path planning out of C0's firmware macros (PG, PP) and into PLR — the larger "tame the iSWAP" goal.
Until joint 0 is queryable as a Coordinate, none of the downstream kinematic work can land cleanly.

Separately, the existing request_{rotation,wrist}_drive_position_increments methods return an angle in motor increments, not a spatial position — the name was misleading and now actively collides with the new rotation_drive_request_position(), which really does return a Coordinate.

PR content / solution

New on iSWAPBackend:

  • rotation_drive_request_x_offset() -> float — reads EEPROM kg via C0:RA (mm, /10). Per-machine, set at service.
  • rotation_drive_z_offset_above_finger = 13.0 — class constant for the rotation-drive-to-finger vertical offset.
  • rotation_drive_request_position() -> Coordinate — composes X-arm center − kg, rotation-drive Y, finger Z + 13 mm.
    Raises RuntimeError if no iSWAP is installed.

Renames (angle ≠ position):

  • request_rotation_drive_position_incrementsrotation_drive_request_angle_increments
  • request_rotation_drive_orientationrotation_drive_request_orientation
  • request_wrist_drive_position_incrementsrequest_wrist_drive_angle_increments
  • rotate_rotation_driverotation_drive_rotate

Legacy backend (legacy/.../STAR_backend.py):

  • 4 deprecation shim bodies updated to delegate to the new method names.
  • Existing """Deprecated: use ...""" docstrings left untouched (no new deprecation messaging introduced).

@BioCam BioCam requested a review from rickwierenga April 26, 2026 19:09
Comment on lines +306 to +331
Previously measured to be 32.8 mm by contributor;
per-machine calibrated during service. Required for deriving the
iSWAP rotation drive's deck X coordinate from the X-arm carriage center.
"""
resp = await self.driver.send_command(module="C0", command="RA", ra="kg", fmt="kg###")
return cast(int, resp["kg"]) / 10.0

# Vertical drop from the iSWAP rotation drive plane to the gripper
# finger plane, per VENUS Programmer Guide §15.1.1.
rotation_drive_z_offset_above_finger = 13.0

async def rotation_drive_request_position(self) -> Coordinate:
"""Position of the iSWAP rotation drive (joint 0) in deck coordinates, mm."""
if not self.driver.extended_conf.left_x_drive.iswap_installed: # type: ignore[union-attr]
raise RuntimeError("iSWAP is not installed")

x_arm_center = await self.driver.left_x_arm.request_position() # type: ignore[union-attr]
iswap_x_offset = await self.rotation_drive_request_x_offset()
rotation_drive_y = await self.rotation_drive_request_y()
finger_loc = (await self.request_gripper_location()).location

return Coordinate(
x=x_arm_center - iswap_x_offset,
y=rotation_drive_y,
z=finger_loc.z + self.rotation_drive_z_offset_above_finger,
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth considering making rotation_drive_request_position private, just loading it in _on_setup and then storing it locally so we don't have to call this firmware command every time.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what you mean:

Every time the STAR's X-arm moves this position is different, same for when the iSWAP performs any action, or channels require the iSWAP to move out of the way?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the offset should be constant right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh you don't mean making rotation_drive_request_position private,
but instead you mean making rotation_drive_request_x_offset private and cached during setup?

yes, that makes sense - will implement

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sorry

BioCam added a commit to BioCam/pylabrobot that referenced this pull request Apr 27, 2026
@rickwierenga
Copy link
Copy Markdown
Member

can I or you merge this?

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.

2 participants