diff --git a/src/ephys_link/__about__.py b/src/ephys_link/__about__.py index 10aa336..b7e1990 100644 --- a/src/ephys_link/__about__.py +++ b/src/ephys_link/__about__.py @@ -1 +1 @@ -__version__ = "1.2.3" +__version__ = "1.2.5" diff --git a/src/ephys_link/platforms/new_scale_manipulator.py b/src/ephys_link/platforms/new_scale_manipulator.py index 5274b31..7b408b2 100644 --- a/src/ephys_link/platforms/new_scale_manipulator.py +++ b/src/ephys_link/platforms/new_scale_manipulator.py @@ -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 @@ -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() @@ -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. @@ -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() @@ -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. diff --git a/src/ephys_link/platforms/sensapex_manipulator.py b/src/ephys_link/platforms/sensapex_manipulator.py index 218631d..1b0b1b0 100644 --- a/src/ephys_link/platforms/sensapex_manipulator.py +++ b/src/ephys_link/platforms/sensapex_manipulator.py @@ -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. diff --git a/src/ephys_link/server.py b/src/ephys_link/server.py index 0e47e0a..b053a82 100644 --- a/src/ephys_link/server.py +++ b/src/ephys_link/server.py @@ -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()