Skip to content

Commit 8abf182

Browse files
committed
JointCoords is a list of floats
1 parent d4d7f9c commit 8abf182

File tree

9 files changed

+231
-263
lines changed

9 files changed

+231
-263
lines changed

pylabrobot/arms/arm.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from collections.abc import Iterable
12
from typing import Optional, Union
23

34
from pylabrobot.arms.backend import AccessPattern, ArmBackend
4-
from pylabrobot.arms.coords import CartesianCoords, JointCoords
5+
from pylabrobot.arms.precise_flex.coords import CartesianCoords
6+
from pylabrobot.arms.standard import JointCoords
57
from pylabrobot.machines.machine import Machine
68

79

@@ -12,28 +14,27 @@ def __init__(self, backend: ArmBackend):
1214
super().__init__(backend=backend)
1315
self.backend: ArmBackend = backend
1416

15-
async def move_to(self, position: Union[CartesianCoords, JointCoords]):
16-
"""Move the arm to a specified position in 3D space."""
17+
async def move_to(self, position: Union[CartesianCoords, Iterable[float]]):
18+
"""Move the arm to a specified position in 3D space or joint space."""
19+
if isinstance(position, Iterable) and not isinstance(position, list):
20+
position = list(position)
1721
return self.backend.move_to(position)
1822

1923
async def get_joint_position(self) -> JointCoords:
20-
"""Get the current position of the arm in 3D space."""
24+
"""Get the current position of the arm in joint space."""
2125
return await self.backend.get_joint_position()
2226

2327
async def get_cartesian_position(self) -> CartesianCoords:
2428
"""Get the current position of the arm in 3D space."""
2529
return await self.backend.get_cartesian_position()
2630

2731
async def open_gripper(self):
28-
"""Open the arm's gripper."""
2932
return await self.backend.open_gripper()
3033

3134
async def close_gripper(self):
32-
"""Close the arm's gripper."""
3335
return await self.backend.close_gripper()
3436

3537
async def is_gripper_closed(self) -> bool:
36-
"""Check if the gripper is currently closed."""
3738
return await self.backend.is_gripper_closed()
3839

3940
async def halt(self):
@@ -55,9 +56,10 @@ async def approach(
5556
5657
Args:
5758
position: Target position (CartesianCoords or JointCoords)
58-
access: Access pattern defining how to approach the target.
59-
Defaults to VerticalAccess() if not specified.
59+
access: Access pattern defining how to approach the target. Defaults to VerticalAccess() if not specified.
6060
"""
61+
if isinstance(position, Iterable) and not isinstance(position, list):
62+
position = list(position)
6163
return await self.backend.approach(position, access)
6264

6365
async def pick_plate(
@@ -67,9 +69,10 @@ async def pick_plate(
6769
6870
Args:
6971
position: Target position for pickup
70-
access: Access pattern defining how to approach and retract.
71-
Defaults to VerticalAccess() if not specified.
72+
access: Access pattern defining how to approach and retract. Defaults to VerticalAccess() if not specified.
7273
"""
74+
if isinstance(position, Iterable) and not isinstance(position, list):
75+
position = list(position)
7376
return await self.backend.pick_plate(position, access)
7477

7578
async def place_plate(
@@ -79,7 +82,8 @@ async def place_plate(
7982
8083
Args:
8184
position: Target position for placement
82-
access: Access pattern defining how to approach and retract.
83-
Defaults to VerticalAccess() if not specified.
85+
access: Access pattern defining how to approach and retract. Defaults to VerticalAccess() if not specified.
8486
"""
87+
if isinstance(position, Iterable) and not isinstance(position, list):
88+
position = list(position)
8589
return await self.backend.place_plate(position, access)

pylabrobot/arms/backend.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from abc import ABCMeta, abstractmethod
22
from dataclasses import dataclass
3-
from typing import Optional, Union
3+
from typing import List, Optional, Union
44

5-
from pylabrobot.arms.coords import CartesianCoords, JointCoords
5+
from pylabrobot.arms.precise_flex.coords import CartesianCoords
6+
from pylabrobot.arms.standard import JointCoords
67
from pylabrobot.machines.backend import MachineBackend
78

89

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ class ElbowOrientation(Enum):
1010
LEFT = "left"
1111

1212

13-
@dataclass
14-
class JointCoords:
15-
rail: float
16-
base: float
17-
shoulder: float
18-
elbow: float
19-
wrist: float
20-
gripper: float
21-
22-
2313
@dataclass
2414
class CartesianCoords:
2515
location: Coordinate
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass
5+
class PreciseFlexJointCoords:
6+
rail: float
7+
base: float
8+
shoulder: float
9+
elbow: float
10+
wrist: float
11+
gripper: float
12+
13+
def __iter__(self):
14+
# for conversion to a list
15+
return iter(
16+
[
17+
self.rail,
18+
self.base,
19+
self.shoulder,
20+
self.elbow,
21+
self.wrist,
22+
self.gripper,
23+
]
24+
)
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
1-
from typing import Optional
1+
from typing import List
22

3-
from pylabrobot.arms.coords import CartesianCoords, ElbowOrientation, JointCoords
3+
from pylabrobot.arms.precise_flex.joints import PreciseFlexJointCoords
44
from pylabrobot.arms.precise_flex.precise_flex_backend import PreciseFlexBackend
5-
from pylabrobot.resources import Coordinate, Rotation
65

76

8-
class PreciseFlex400Backend(PreciseFlexBackend):
9-
"""Backend for the PreciseFlex 400 robotic arm."""
7+
class PreciseFlex3400Backend(PreciseFlexBackend):
8+
"""Backend for the PreciseFlex 3400 robotic arm."""
109

1110
def __init__(self, host: str, port: int = 10100, timeout=20) -> None:
1211
super().__init__(host=host, port=port, timeout=timeout)
1312

14-
def convert_to_joint_space(
15-
self, position: tuple[float, float, float, float, float, float]
16-
) -> JointCoords:
17-
"""Convert a tuple of joint angles to a JointCoords object."""
13+
def convert_to_joint_space(self, position: List[float]) -> PreciseFlexJointCoords:
14+
"""Convert a tuple of joint angles to a PreciseFlexJointCoords object."""
1815
if len(position) != 6:
1916
raise ValueError("Position must be a tuple of 6 joint angles.")
20-
return JointCoords(0, position[0], position[1], position[2], position[3], position[4])
17+
return PreciseFlexJointCoords(
18+
0, position[0], position[1], position[2], position[3], position[4]
19+
)
2120

22-
def convert_to_joints_array(
23-
self, position: JointCoords
24-
) -> tuple[float, float, float, float, float, float]:
21+
def convert_to_joints_array(self, position: PreciseFlexJointCoords) -> List[float]:
2522
"""Convert a JointSpace object to a list of joint angles."""
26-
joints = (
23+
return [
2724
position.base,
2825
position.shoulder,
2926
position.elbow,
3027
position.wrist,
3128
position.gripper,
3229
0,
33-
) # PF400 has 5 joints, last is fixed
34-
return joints
30+
] # PF400 has 5 joints, last is fixed
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from typing import Optional
1+
from typing import List
22

3-
from pylabrobot.arms.coords import CartesianCoords, ElbowOrientation, JointCoords
3+
from pylabrobot.arms.precise_flex.joints import PreciseFlexJointCoords
44
from pylabrobot.arms.precise_flex.precise_flex_backend import PreciseFlexBackend
5-
from pylabrobot.resources import Coordinate, Rotation
65

76

87
class PreciseFlex400Backend(PreciseFlexBackend):
@@ -11,24 +10,19 @@ class PreciseFlex400Backend(PreciseFlexBackend):
1110
def __init__(self, host: str, port: int = 10100, timeout=20) -> None:
1211
super().__init__(host=host, port=port, timeout=timeout)
1312

14-
def convert_to_joint_space(
15-
self, position: tuple[float, float, float, float, float, float]
16-
) -> JointCoords:
17-
"""Convert a tuple of joint angles to a JointCoords object."""
13+
def convert_to_joint_space(self, position: List[float]) -> PreciseFlexJointCoords:
14+
"""Convert a list of joint angles to a PreciseFlexJointCoords object."""
1815
if len(position) != 6:
19-
raise ValueError("Position must be a tuple of 6 joint angles.")
20-
return JointCoords(0, position[0], position[1], position[2], position[3], 0)
16+
raise ValueError("Position must be a list of 6 joint angles.")
17+
return PreciseFlexJointCoords(0, position[0], position[1], position[2], position[3], 0)
2118

22-
def convert_to_joints_array(
23-
self, position: JointCoords
24-
) -> tuple[float, float, float, float, float, float]:
25-
"""Convert a JointSpace object to a list of joint angles."""
26-
joints = (
19+
def convert_to_joints_array(self, position: PreciseFlexJointCoords) -> List[float]:
20+
"""Convert a PreciseFlexJointCoords object to a list of joint angles."""
21+
return [
2722
position.base,
2823
position.shoulder,
2924
position.elbow,
3025
position.wrist,
3126
0,
3227
0,
33-
) # PF400 has 4 joints, last two are fixed
34-
return joints
28+
] # PF400 has 4 joints, last two are fixed

0 commit comments

Comments
 (0)