Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add auto offset adjustment for objective switching #87

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions software/control/_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,3 +857,4 @@ def load_formats():
XERYON_SPEED = 80
XERYON_OBJECTIVE_SWITCHER_POS_1 = ['4x', '10x']
XERYON_OBJECTIVE_SWITCHER_POS_2 = ['20x', '40x', '60x']
XERYON_OBJECTIVE_SWITCHER_POS_2_OFFSET_MM = 2
2 changes: 1 addition & 1 deletion software/control/gui_hcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def loadHardwareObjects(self):

if USE_XERYON:
try:
self.objective_changer = ObjectiveChanger2PosController(sn=XERYON_SERIAL_NUMBER)
self.objective_changer = ObjectiveChanger2PosController(sn=XERYON_SERIAL_NUMBER,stage=self.stage)
except Exception:
self.log.error("Error initializing Xeryon objective switcher")
raise
Expand Down
19 changes: 17 additions & 2 deletions software/control/objective_changer_2_pos_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,46 @@
import time
import serial

from control.Xeryon import *
from control.Xeryon import Xeryon
from control._def import * # to remove once we create ObjectiveChangerConfig
import squid.abc

class ObjectiveChanger2PosController:
def __init__(self, sn: str):
def __init__(self, sn: str, stage: Optional[squid.abc.AbstractStage] = None):
super().__init__()
port = [p.device for p in serial.tools.list_ports.comports() if sn == p.serial_number]
self.controller = Xeryon(port[0], 115200)
self.axisX = self.controller.addAxis(Stage.XLA_1250_3N, "Z")
self.controller.start()
self.controller.reset()

self.stage = stage

self.position1 = -19
self.position2 = 19

self.current_position = None
self.retracted = False # moved down by self.position2_offset for position 2

self.position2_offset = XERYON_OBJECTIVE_SWITCHER_POS_2_OFFSET_MM

def home(self):
self.axisX.findIndex()

def moveToPosition1(self):
self.axisX.setDPOS(self.position1)
if self.stage is not None and self.current_position == 2 and self.retracted:
# revert retracting z by self.position2_offset
self.stage.move_z(self.position2_offset)
self.retracted = False
self.current_position = 1

def moveToPosition2(self):
self.axisX.setDPOS(self.position2)
if self.stage is not None and self.current_position == 1:
# retract z by self.position2_offset
self.stage.move_z(-self.position2_offset)
self.retracted = True
self.current_position = 2

def currentPosition(self) -> int:
Expand Down
Loading