From 76b6dabcfdb3c19fb78788a7e91e09228c03607d Mon Sep 17 00:00:00 2001 From: Rachel Banks Date: Tue, 12 Dec 2023 13:37:16 -0800 Subject: [PATCH] fixing mirror and position mapping. --- .../photom/demo/demo_photom_assembly.py | 2 ++ copylot/assemblies/photom/photom.py | 22 +++++++++++-------- .../photom/utils/affine_transform.py | 2 +- copylot/hardware/mirrors/abstract_mirror.py | 16 ++++++-------- copylot/hardware/mirrors/optotune/mirror.py | 16 ++++++-------- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/copylot/assemblies/photom/demo/demo_photom_assembly.py b/copylot/assemblies/photom/demo/demo_photom_assembly.py index 3b1379f..84ab0c2 100644 --- a/copylot/assemblies/photom/demo/demo_photom_assembly.py +++ b/copylot/assemblies/photom/demo/demo_photom_assembly.py @@ -31,3 +31,5 @@ # %% photom_device.calibrate(mirror_index=0, rectangle_size_xy=(0.01, 0.01)) + +# %% diff --git a/copylot/assemblies/photom/photom.py b/copylot/assemblies/photom/photom.py index 030468f..f56ba95 100644 --- a/copylot/assemblies/photom/photom.py +++ b/copylot/assemblies/photom/photom.py @@ -13,7 +13,9 @@ from copylot import logger from typing import Tuple import time +from typing import Optional +#TODO: add the logger from copylot class PhotomAssembly: def __init__( @@ -21,8 +23,8 @@ def __init__( laser: list[AbstractLaser], mirror: list[AbstractMirror], affine_matrix_path: list[Path], - camera: list[AbstractCamera] = None, - dac: list[AbstractDAQ] = None, + camera: Optional[list[AbstractCamera]] = None, + dac: Optional[list[AbstractDAQ]]= None, ): # hardware self.camera = camera @@ -67,10 +69,10 @@ def capture(self): pass ## Mirror Functions - def get_position(self, mirror_index: int) -> list[float, float]: + def get_position(self, mirror_index: int) -> list[float]: if mirror_index < len(self.mirror): - if self.DAC is None: - NotImplementedError("No DAC found.") + if self.DAC is not None: + raise NotImplementedError("No DAC found.") else: position = self.mirror[mirror_index].position return list(position) @@ -79,12 +81,14 @@ def get_position(self, mirror_index: int) -> list[float, float]: def set_position(self, mirror_index: int, position: list[float]): if mirror_index < len(self.mirror): - if self.DAC is None: - NotImplementedError("No DAC found.") + if self.DAC is not None: + raise NotImplementedError("No DAC found.") else: # TODO: logic for applying the affine transform to the position - new_position = self.mirror.affine_transform_obj.apply_affine(position) - self.mirror[mirror_index].position = new_position + print(f'postion before affine transform: {position}') + new_position = self.mirror[mirror_index].affine_transform_obj.apply_affine(position) + print(f'postion after affine transform: {new_position[0]}{new_position[1]}') + self.mirror[mirror_index].position = [new_position[0][0], new_position[1][0]] else: raise IndexError("Mirror index out of range.") diff --git a/copylot/assemblies/photom/utils/affine_transform.py b/copylot/assemblies/photom/utils/affine_transform.py index 87bcbc5..d958e73 100644 --- a/copylot/assemblies/photom/utils/affine_transform.py +++ b/copylot/assemblies/photom/utils/affine_transform.py @@ -76,7 +76,7 @@ def get_affine_matrix(self, origin, dest): ) return self.T_affine - def apply_affine(self, coord_list: list): + def apply_affine(self, coord_list: list)->list: """ Perform affine transformation. :param coord_list: a list of origin coordinate (e.g. [[x,y], ...] or [[list for ch0], [list for ch1]]) diff --git a/copylot/hardware/mirrors/abstract_mirror.py b/copylot/hardware/mirrors/abstract_mirror.py index d3cd966..5163abb 100644 --- a/copylot/hardware/mirrors/abstract_mirror.py +++ b/copylot/hardware/mirrors/abstract_mirror.py @@ -1,6 +1,4 @@ from abc import ABCMeta, abstractmethod -from typing import Tuple - class AbstractMirror(metaclass=ABCMeta): """AbstractMirror @@ -17,13 +15,13 @@ def __init__(self): @property @abstractmethod - def position(self) -> Tuple[float, float]: + def position(self) -> list[float,float]: """Get the current mirror position XY""" pass @position.setter @abstractmethod - def position(self, value: Tuple[float, float]): + def position(self, value: list[float,float]): """Set the mirror position XY""" pass @@ -53,25 +51,25 @@ def position_y(self, value: float): @property @abstractmethod - def relative_position(self) -> Tuple[float, float]: + def relative_position(self) -> list[float, float]: """Get the current relative mirror position""" pass @relative_position.setter @abstractmethod - def relative_position(self, value: Tuple[float, float]): + def relative_position(self, value: list[float, float]): """Set the relative mirror position""" pass @property @abstractmethod - def movement_limits(self) -> Tuple[float, float, float, float]: + def movement_limits(self) -> list[float, float, float, float]: """Get the current mirror movement limits""" pass @movement_limits.setter @abstractmethod - def movement_limits(self, value: Tuple[float, float, float, float]): + def movement_limits(self, value: list[float, float, float, float]): """Set the mirror movement limits""" pass @@ -110,6 +108,6 @@ def external_drive_control(self, value: bool): pass @abstractmethod - def voltage_to_position(self, voltage: Tuple[float, float]) -> Tuple[float, float]: + def voltage_to_position(self, voltage: list[float, float]) -> list[float, float]: """Convert voltage to position""" pass diff --git a/copylot/hardware/mirrors/optotune/mirror.py b/copylot/hardware/mirrors/optotune/mirror.py index 6c3b45d..2de99f0 100644 --- a/copylot/hardware/mirrors/optotune/mirror.py +++ b/copylot/hardware/mirrors/optotune/mirror.py @@ -9,8 +9,6 @@ from copylot import logger from copylot.hardware.mirrors.optotune import optoMDC from copylot.hardware.mirrors.abstract_mirror import AbstractMirror -from typing import Tuple - class OptoMirror(AbstractMirror): def __init__(self, com_port: str = None): @@ -53,11 +51,11 @@ def position(self): return self.position_x, self.position_y @position.setter - def position(self, value: Tuple[float, float]): + def position(self, value: list[float, float]): """ Parameters ---------- - value:Tuple[float,float] + value:list[float,float] The normalized angular value, value = theta/tan(50degree) 50 degree is the maximum optical deflection angle for each direction. Here x has a range limits of [-1,1] , The combination of value for x-axis and y-axis should be less than 1 @@ -128,22 +126,22 @@ def position_y(self, value): logger.info(f"position_y set to: {value}") @property - def relative_position(self) -> Tuple[float, float]: + def relative_position(self) -> list[float, float]: """Get the current relative mirror position""" pass @relative_position.setter - def relative_position(self, value: Tuple[float, float]): + def relative_position(self, value: list[float, float]): """Set the relative mirror position""" pass @property - def movement_limits(self) -> Tuple[float, float, float, float]: + def movement_limits(self) -> list[float, float, float, float]: """Get the current mirror movement limits""" pass @movement_limits.setter - def movement_limits(self, value: Tuple[float, float, float, float]): + def movement_limits(self, value: list[float, float, float, float]): """Set the mirror movement limits""" pass @@ -178,6 +176,6 @@ def external_drive_control(self, value: bool): pass - def voltage_to_position(self, voltage: Tuple[float, float]) -> Tuple[float, float]: + def voltage_to_position(self, voltage: list[float, float]) -> list[float, float]: """Convert voltage to position""" pass