Skip to content

Commit

Permalink
fixing mirror and position mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
edyoshikun committed Dec 12, 2023
1 parent b6cf5e0 commit 76b6dab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
2 changes: 2 additions & 0 deletions copylot/assemblies/photom/demo/demo_photom_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@

# %%
photom_device.calibrate(mirror_index=0, rectangle_size_xy=(0.01, 0.01))

# %%
22 changes: 13 additions & 9 deletions copylot/assemblies/photom/photom.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
from copylot import logger
from typing import Tuple
import time
from typing import Optional

#TODO: add the logger from copylot

class PhotomAssembly:
def __init__(
self,
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
Expand Down Expand Up @@ -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)
Expand All @@ -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.")

Expand Down
2 changes: 1 addition & 1 deletion copylot/assemblies/photom/utils/affine_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand Down
16 changes: 7 additions & 9 deletions copylot/hardware/mirrors/abstract_mirror.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from abc import ABCMeta, abstractmethod
from typing import Tuple


class AbstractMirror(metaclass=ABCMeta):
"""AbstractMirror
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
16 changes: 7 additions & 9 deletions copylot/hardware/mirrors/optotune/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 76b6dab

Please sign in to comment.