From c1c45cdf9933c343c364b40176f606963d116f98 Mon Sep 17 00:00:00 2001 From: Kenneth Yang <82800265+kjy5@users.noreply.github.com> Date: Sat, 24 Jun 2023 13:47:40 -0700 Subject: [PATCH] New scale patch (#166) * Duplicate Z to D, restrict to Z-axis movement when inside brain * Pass manipulator type * Autoformat code --------- Co-authored-by: kjy5 --- ephys_link/common.py | 6 ++++-- ephys_link/platform_handler.py | 3 ++- ephys_link/platforms/new_scale_handler.py | 3 +++ ephys_link/platforms/new_scale_manipulator.py | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ephys_link/common.py b/ephys_link/common.py index 6b8928e..ea1fc5b 100644 --- a/ephys_link/common.py +++ b/ephys_link/common.py @@ -70,6 +70,8 @@ class GetManipulatorsOutputData(dict): :param manipulators: Tuple of manipulator IDs (as strings) :type manipulators: list + :param type: Type of the output data (temporary solution until #165 is implemented) + :type type: str :param error: Error message :type error: str @@ -77,10 +79,10 @@ class GetManipulatorsOutputData(dict): :code:`{"manipulators": ["1", "2"], "error": ""}` """ - def __init__(self, manipulators: list, error: str) -> None: + def __init__(self, manipulators: list, type: str, error: str) -> None: """Constructor""" super(GetManipulatorsOutputData, self).__init__( - manipulators=manipulators, error=error + manipulators=manipulators, type=type, error=error ) diff --git a/ephys_link/platform_handler.py b/ephys_link/platform_handler.py index e73033a..216da71 100644 --- a/ephys_link/platform_handler.py +++ b/ephys_link/platform_handler.py @@ -29,6 +29,7 @@ def __init__(self): # Registered manipulators are stored as a dictionary of IDs (string) to # manipulator objects self.manipulators = {} + self.type = "sensapex" # Remove this after #165 # Platform Handler Methods @@ -72,7 +73,7 @@ def get_manipulators(self) -> com.GetManipulatorsOutputData: except Exception as e: print(f"[ERROR]\t\t Getting manipulators: {type(e)}: {e}\n") finally: - return com.GetManipulatorsOutputData(devices, error) + return com.GetManipulatorsOutputData(devices, self.type, error) def register_manipulator(self, manipulator_id: str) -> str: """Register a manipulator diff --git a/ephys_link/platforms/new_scale_handler.py b/ephys_link/platforms/new_scale_handler.py index 9050bf7..373e638 100644 --- a/ephys_link/platforms/new_scale_handler.py +++ b/ephys_link/platforms/new_scale_handler.py @@ -24,6 +24,9 @@ def __init__(self) -> None: """Initialize New Scale handler""" super().__init__() + # FIXME: Remove after #165 + self.type = "new_scale" + # Load New Scale API clr.AddReference("../resources/NstMotorCtrl") # noinspection PyUnresolvedReferences diff --git a/ephys_link/platforms/new_scale_manipulator.py b/ephys_link/platforms/new_scale_manipulator.py index 803f7dc..b86211f 100644 --- a/ephys_link/platforms/new_scale_manipulator.py +++ b/ephys_link/platforms/new_scale_manipulator.py @@ -74,7 +74,7 @@ def get_pos(self) -> com.PositionalOutputData: self._x.CurPosition / 1000, self._y.CurPosition / 1000, self._z.CurPosition / 1000, - 0, + self._z.CurPosition / 1000, ] com.dprint(f"[SUCCESS]\t Got position of manipulator {self._id}\n") return com.PositionalOutputData(position, "") @@ -117,7 +117,7 @@ async def goto_pos( # Alter target position if inside brain if self._inside_brain: target_position = self.get_pos()["position"] - target_position[3] = position_um[3] + target_position[2] = position_um[2] # Send move command for i in range(3):