From 0b2deea50b2992fb11725c2236cf517a3eaa9254 Mon Sep 17 00:00:00 2001 From: Kenneth Yang <82800265+kjy5@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:48:57 -0700 Subject: [PATCH] Throw error if finish movement and can't write (#248) --- src/ephys_link/platforms/new_scale_manipulator.py | 12 ++++++++++-- src/ephys_link/platforms/sensapex_manipulator.py | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ephys_link/platforms/new_scale_manipulator.py b/src/ephys_link/platforms/new_scale_manipulator.py index 01b3185..3650f3e 100644 --- a/src/ephys_link/platforms/new_scale_manipulator.py +++ b/src/ephys_link/platforms/new_scale_manipulator.py @@ -100,8 +100,8 @@ async def goto_pos( """ # Check if able to write if not self._can_write: - print(f"[ERROR]\t\t Manipulator {self._id} movement " f"canceled") - return com.PositionalOutputData([], "Manipulator " "movement canceled") + print(f"[ERROR]\t\t Manipulator {self._id} movement canceled") + return com.PositionalOutputData([], "Manipulator movement canceled") # Stop current movement if self._is_moving: @@ -147,6 +147,10 @@ async def goto_pos( # Mark movement as finished self._is_moving = False + # Return success unless write was disabled during movement (meaning a stop occurred) + if not self._can_write: + return com.PositionalOutputData([], "Manipulator movement canceled") + com.dprint( f"[SUCCESS]\t Moved manipulator {self._id} to position" f" {manipulator_final_position}\n" @@ -207,6 +211,10 @@ async def drive_to_depth( # Mark movement as finished self._is_moving = False + # Return success unless write was disabled during movement (meaning a stop occurred) + if not self._can_write: + return com.DriveToDepthOutputData(0, "Manipulator movement canceled") + com.dprint( f"[SUCCESS]\t Moved manipulator {self._id} to position" f" {manipulator_final_position}\n" diff --git a/src/ephys_link/platforms/sensapex_manipulator.py b/src/ephys_link/platforms/sensapex_manipulator.py index 015559a..2772fa6 100644 --- a/src/ephys_link/platforms/sensapex_manipulator.py +++ b/src/ephys_link/platforms/sensapex_manipulator.py @@ -102,6 +102,10 @@ async def goto_pos( # Mark movement as finished self._is_moving = False + # Return success unless write was disabled during movement (meaning a stop occurred) + if not self._can_write: + return com.PositionalOutputData([], "Manipulator movement canceled") + com.dprint( f"[SUCCESS]\t Moved manipulator {self._id} to position" f" {manipulator_final_position}\n"