Skip to content

Commit

Permalink
Fix new scale drive and stop (#326)
Browse files Browse the repository at this point in the history
* Fix New Scale checking for movement

* Relaxed tolerance on NS

* Fix drive failure error reporting

* Stop new scale if cannot write
  • Loading branch information
kjy5 authored Feb 16, 2024
1 parent 553a8c7 commit c09932e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/ephys_link/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.3"
__version__ = "1.2.5"
19 changes: 9 additions & 10 deletions src/ephys_link/platforms/new_scale_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(

super().__init__()
self._id = manipulator_id
self._movement_tolerance = 0.01
self._x = x_axis
self._y = y_axis
self._z = z_axis
Expand Down Expand Up @@ -131,13 +132,13 @@ async def goto_pos(self, position: list[float], speed: float) -> com.PositionalO
)
self._axes[i].MoveAbsolute(target_position_um[i])

# Check and wait for completion
# Check and wait for completion (while able to write)
self.query_all_axes()
while (
not (self._x.CurStatus & AT_TARGET_FLAG)
or not (self._y.CurStatus & AT_TARGET_FLAG)
or not (self._z.CurStatus & AT_TARGET_FLAG)
):
) and self._can_write:
await asyncio.sleep(POSITION_POLL_DELAY)
self.query_all_axes()

Expand All @@ -153,11 +154,9 @@ async def goto_pos(self, position: list[float], speed: float) -> com.PositionalO
return com.PositionalOutputData([], "Manipulator movement canceled")

# Return error if movement did not reach target.
if not all(
abs(manipulator_final_position[i] - position[i]) < self._movement_tolerance
for i in range(len(position))
):
com.dprint(f"[ERROR]\t\t Manipulator {self._id} did not reach target position")
if not all(abs(manipulator_final_position[i] - position[i]) < self._movement_tolerance for i in range(3)):
com.dprint(f"[ERROR]\t\t Manipulator {self._id} did not reach target position.")
com.dprint(f"\t\t\t Expected: {position}, Got: {manipulator_final_position}")
return com.PositionalOutputData([], "Manipulator did not reach target position")

# Made it to the target.
Expand Down Expand Up @@ -204,9 +203,9 @@ async def drive_to_depth(self, depth: float, speed: float) -> com.DriveToDepthOu
)
self._z.MoveAbsolute(target_depth_um)

# Check and wait for completion
# Check and wait for completion (while able to write)
self._z.QueryPosStatus()
while not (self._z.CurStatus & AT_TARGET_FLAG):
while not (self._z.CurStatus & AT_TARGET_FLAG) and self._can_write:
await asyncio.sleep(0.1)
self._z.QueryPosStatus()

Expand All @@ -233,7 +232,7 @@ async def drive_to_depth(self, depth: float, speed: float) -> com.DriveToDepthOu
print(f"[ERROR]\t\t Moving manipulator {self._id} to depth {depth}")
print(f"{e}\n")
# Return 0 and error message on failure
return com.DriveToDepthOutputData(0, "Error driving " "manipulator")
return com.DriveToDepthOutputData(0, "Error driving manipulator")

def calibrate(self) -> bool:
"""Calibrate the manipulator.
Expand Down
2 changes: 1 addition & 1 deletion src/ephys_link/platforms/sensapex_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def drive_to_depth(self, depth: float, speed: float) -> com.DriveToDepthOu
return com.DriveToDepthOutputData(movement_result["position"][3], "")

# Return 0 and error message on failure
return com.DriveToDepthOutputData(0, "Error driving " "manipulator")
return com.DriveToDepthOutputData(0, movement_result["error"])

def set_inside_brain(self, inside: bool) -> None:
"""Set if the manipulator is inside the brain.
Expand Down
2 changes: 1 addition & 1 deletion src/ephys_link/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async def drive_to_depth(self, _, data: str) -> str:
print(f"[ERROR]\t\t Error in drive_to_depth: {e}\n")
return com.DriveToDepthOutputData(-1, "Error in drive_to_depth").json()
else:
com.dprint(f"[EVENT]\t\t Drive manipulator {manipulator_id} " f"to depth {depth}")
com.dprint(f"[EVENT]\t\t Drive manipulator {manipulator_id} to depth {depth}")
drive_result = await self.platform.drive_to_depth(manipulator_id, depth, speed)
return drive_result.json()

Expand Down

0 comments on commit c09932e

Please sign in to comment.