Skip to content

Commit d4d7f9c

Browse files
committed
move coordinate convertor into backend
1 parent 8620a2c commit d4d7f9c

File tree

5 files changed

+153
-238
lines changed

5 files changed

+153
-238
lines changed

pylabrobot/arms/arm.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ async def get_cartesian_position(self) -> CartesianCoords:
2424
"""Get the current position of the arm in 3D space."""
2525
return await self.backend.get_cartesian_position()
2626

27-
async def set_speed(self, speed: float):
28-
"""Set the speed of the arm's movement."""
29-
return await self.backend.set_speed(speed)
30-
31-
async def get_speed(self) -> float:
32-
"""Get the current speed of the arm's movement."""
33-
return await self.backend.get_speed()
34-
3527
async def open_gripper(self):
3628
"""Open the arm's gripper."""
3729
return await self.backend.open_gripper()
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1+
from typing import Optional
2+
3+
from pylabrobot.arms.coords import CartesianCoords, ElbowOrientation, JointCoords
14
from pylabrobot.arms.precise_flex.precise_flex_backend import PreciseFlexBackend
5+
from pylabrobot.resources import Coordinate, Rotation
26

37

48
class PreciseFlex400Backend(PreciseFlexBackend):
59
"""Backend for the PreciseFlex 400 robotic arm."""
610

711
def __init__(self, host: str, port: int = 10100, timeout=20) -> None:
8-
super().__init__("pf3400", host, port, timeout)
12+
super().__init__(host=host, port=port, timeout=timeout)
13+
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."""
18+
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], position[4])
21+
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 = (
27+
position.base,
28+
position.shoulder,
29+
position.elbow,
30+
position.wrist,
31+
position.gripper,
32+
0,
33+
) # PF400 has 5 joints, last is fixed
34+
return joints
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1+
from typing import Optional
2+
3+
from pylabrobot.arms.coords import CartesianCoords, ElbowOrientation, JointCoords
14
from pylabrobot.arms.precise_flex.precise_flex_backend import PreciseFlexBackend
5+
from pylabrobot.resources import Coordinate, Rotation
26

37

48
class PreciseFlex400Backend(PreciseFlexBackend):
59
"""Backend for the PreciseFlex 400 robotic arm."""
610

711
def __init__(self, host: str, port: int = 10100, timeout=20) -> None:
8-
super().__init__("pf400", host, port, timeout)
12+
super().__init__(host=host, port=port, timeout=timeout)
13+
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."""
18+
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)
21+
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 = (
27+
position.base,
28+
position.shoulder,
29+
position.elbow,
30+
position.wrist,
31+
0,
32+
0,
33+
) # PF400 has 4 joints, last two are fixed
34+
return joints

0 commit comments

Comments
 (0)