Skip to content

Commit 6d4cb49

Browse files
committed
Edit PreciseFlex API and backend to support Cartesian and Joint coordinates; update method signatures and add new backend classes for PreciseFlex 400 and PreciseFlex 3400
1 parent a3c883a commit 6d4cb49

File tree

6 files changed

+319
-172
lines changed

6 files changed

+319
-172
lines changed

pylabrobot/arms/backend.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
from abc import ABCMeta, abstractmethod
22
from enum import Enum
3+
from dataclasses import dataclass
34

45
from pylabrobot.machines.backend import MachineBackend
56

67
class ElbowOrientation(Enum):
7-
LEFT = "left"
88
RIGHT = "right"
9+
LEFT = "left"
10+
11+
@dataclass
12+
class JointCoords:
13+
rail: float
14+
base: float
15+
shoulder: float
16+
elbow: float
17+
wrist: float
18+
gripper: float
19+
20+
@dataclass
21+
class CartesianCoords:
22+
x: float
23+
y: float
24+
z: float
25+
yaw: float
26+
pitch: float
27+
roll: float
28+
orientation: ElbowOrientation | None = None
929

1030
class ArmBackend(MachineBackend, metaclass=ABCMeta):
1131
"""Backend for a robotic arm"""
@@ -51,51 +71,31 @@ async def move_to_safe(self):
5171
...
5272

5373
@abstractmethod
54-
async def approach_j(self, joint_position: tuple[float, float, float, float, float, float, float], approach_height: float):
74+
async def approach(self, position: CartesianCoords | JointCoords, approach_height: float):
5575
"""Move the arm to a position above the specified coordinates by a certain distance."""
5676
...
5777

5878
@abstractmethod
59-
async def pick_plate_j(self, joint_position: tuple[float, float, float, float, float, float, float], approach_height: float):
79+
async def pick_plate(self, position: CartesianCoords | JointCoords, approach_height: float):
6080
"""Pick a plate from the specified position."""
6181
...
6282

6383
@abstractmethod
64-
async def place_plate_j(self, joint_position: tuple[float, float, float, float, float, float, float], approach_height: float):
84+
async def place_plate(self, position: CartesianCoords | JointCoords, approach_height: float):
6585
"""Place a plate at the specified position."""
6686
...
6787

6888
@abstractmethod
69-
async def move_to_j(self, joint_position: tuple[float, float, float, float, float, float, float]):
89+
async def move_to(self, position: CartesianCoords | JointCoords):
7090
"""Move the arm to a specified position in 3D space."""
7191
...
7292

7393
@abstractmethod
74-
async def get_position_j(self) -> tuple[float, float, float, float, float, float, float]:
94+
async def get_joint_position(self) -> JointCoords:
7595
"""Get the current position of the arm in 3D space."""
7696
...
7797

7898
@abstractmethod
79-
async def approach_c(self, cartesian_position: tuple[float, float, float, float, float, float], approach_height: float, orientation: ElbowOrientation | None = None):
80-
"""Move the arm to a position above the specified coordinates by a certain distance."""
81-
...
82-
83-
@abstractmethod
84-
async def pick_plate_c(self, cartesian_position: tuple[float, float, float, float, float, float], approach_height: float, orientation: ElbowOrientation | None = None):
85-
"""Pick a plate from the specified position."""
86-
...
87-
88-
@abstractmethod
89-
async def place_plate_c(self, cartesian_position: tuple[float, float, float, float, float, float], approach_height: float, orientation: ElbowOrientation | None = None):
90-
"""Place a plate at the specified position."""
91-
...
92-
93-
@abstractmethod
94-
async def move_to_c(self, cartesian_position: tuple[float, float, float, float, float, float], orientation: ElbowOrientation | None = None):
95-
"""Move the arm to a specified position in 3D space."""
96-
...
97-
98-
@abstractmethod
99-
async def get_position_c(self) -> tuple[float, float, float, float, float, float, ElbowOrientation | None]:
99+
async def get_cartesian_position(self) -> CartesianCoords:
100100
"""Get the current position of the arm in 3D space."""
101101
...
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pylabrobot.arms.precise_flex.precise_flex_backend import PreciseFlexBackend
2+
3+
4+
class PreciseFlex400Backend(PreciseFlexBackend):
5+
"""Backend for the PreciseFlex 400 robotic arm."""
6+
def __init__(self, host: str, port: int = 10100, timeout=20) -> None:
7+
super().__init__('pf3400', host, port, timeout)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pylabrobot.arms.precise_flex.precise_flex_backend import PreciseFlexBackend
2+
3+
4+
class PreciseFlex400Backend(PreciseFlexBackend):
5+
"""Backend for the PreciseFlex 400 robotic arm."""
6+
def __init__(self, host: str, port: int = 10100, timeout=20) -> None:
7+
super().__init__('pf400', host, port, timeout)

pylabrobot/arms/precise_flex/precise_flex_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,12 @@ async def where_c(self) -> tuple[float, float, float, float, float, float, int]:
733733
data = await self.send_command("wherec")
734734
parts = data.split()
735735

736-
if len(parts) != 6:
736+
if len(parts) != 7:
737737
# In case of incomplete response, wait for EOM and try to read again
738738
await self.wait_for_eom()
739739
data = await self.send_command("wherec")
740740
parts = data.split()
741-
if len(parts) != 6:
741+
if len(parts) != 7:
742742
raise PreciseFlexError(-1, "Unexpected response format from wherec command.")
743743

744744
x, y, z, yaw, pitch, roll = self._parse_xyz_response(parts[0:6])

0 commit comments

Comments
 (0)