Skip to content

Commit 30c1cfe

Browse files
committed
Applicable test all working on the PreciseFlex API
1 parent a38a209 commit 30c1cfe

File tree

2 files changed

+404
-757
lines changed

2 files changed

+404
-757
lines changed

pylabrobot/arms/precise_flex/precise_flex_api.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,12 @@ async def where(self) -> tuple[float, float, float, float, float, float, tuple[f
712712
parts = data.split()
713713

714714
if len(parts) < 6:
715-
raise PreciseFlexError(-1, "Unexpected response format from where command.")
715+
# In case of incomplete response, wait for EOM and try to read again
716+
await self.wait_for_eom()
717+
data = await self.send_command("where")
718+
parts = data.split()
719+
if len(parts) < 6:
720+
raise PreciseFlexError(-1, "Unexpected response format from where command.")
716721

717722
x, y, z, yaw, pitch, roll = self._parse_xyz_response(parts[0:6])
718723
axes = self._parse_angles_response(parts[6:])
@@ -729,7 +734,12 @@ async def where_c(self) -> tuple[float, float, float, float, float, float, int]:
729734
parts = data.split()
730735

731736
if len(parts) != 7:
732-
raise PreciseFlexError(-1, "Unexpected response format from wherec command.")
737+
# In case of incomplete response, wait for EOM and try to read again
738+
await self.wait_for_eom()
739+
data = await self.send_command("wherec")
740+
parts = data.split()
741+
if len(parts) != 7:
742+
raise PreciseFlexError(-1, "Unexpected response format from wherec command.")
733743

734744
x, y, z, yaw, pitch, roll = self._parse_xyz_response(parts[0:6])
735745
config = int(parts[6])
@@ -746,7 +756,12 @@ async def where_j(self) -> tuple[float, float, float, float, float, float, float
746756
parts = data.split()
747757

748758
if not parts:
749-
raise PreciseFlexError(-1, "Unexpected response format from wherej command.")
759+
# In case of incomplete response, wait for EOM and try to read again
760+
await self.wait_for_eom()
761+
data = await self.send_command("wherej")
762+
parts = data.split()
763+
if not parts:
764+
raise PreciseFlexError(-1, "Unexpected response format from wherej command.")
750765

751766
axes = self._parse_angles_response(parts)
752767
return axes
@@ -1176,8 +1191,7 @@ async def wait_for_eom(self) -> None:
11761191
some other means. Does not reply until the robot has stopped.
11771192
"""
11781193
await self.send_command("waitForEom")
1179-
1180-
1194+
await asyncio.sleep(0.2) # Small delay to ensure command is fully processed
11811195

11821196

11831197
async def zero_torque(self, enable: bool, axis_mask: int = 1) -> None:
@@ -1870,6 +1884,9 @@ async def send_command(self, command: str):
18701884
await self.io.write(command.encode('utf-8') + b'\n')
18711885
await asyncio.sleep(0.2) # wait a bit for the robot to process the command
18721886
reply = await self.io.readline()
1887+
1888+
print(f"Sent command: {command}, Received reply: {reply}")
1889+
18731890
return self._parse_reply_ensure_successful(reply)
18741891

18751892
def _parse_xyz_response(self, parts: list[str]) -> tuple[float, float, float, float, float, float]:
@@ -1907,6 +1924,7 @@ def _parse_reply_ensure_successful(self, reply: bytes) -> str:
19071924
- replycode is an integer at the beginning
19081925
- data is rest of the line (excluding CRLF)
19091926
"""
1927+
print("REPLY: ", reply)
19101928
text = reply.decode().strip() # removes \r\n
19111929
if not text:
19121930
raise PreciseFlexError(-1, "Empty reply from device.")

0 commit comments

Comments
 (0)