Skip to content

Commit

Permalink
Merge pull request #99 from Cephla-Lab/objective-changer-bug-fix
Browse files Browse the repository at this point in the history
objective switcher init bug fix
  • Loading branch information
hongquanli authored Feb 8, 2025
2 parents 04692f3 + 97b3d7e commit 56ea9d8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
28 changes: 19 additions & 9 deletions software/control/gui_hcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
import control.camera as camera_fc

if USE_XERYON:
from control.objective_changer_2_pos_controller import ObjectiveChanger2PosController
from control.objective_changer_2_pos_controller import ObjectiveChanger2PosController, ObjectiveChanger2PosController_Simulation

import control.core.core as core
import control.microcontroller as microcontroller
Expand Down Expand Up @@ -219,14 +219,6 @@ def loadObjects(self, is_simulation):
self.camera, self.microcontroller, self.configurationManager, self.illuminationController, parent=self
)

if USE_PRIOR_STAGE:
self.stage: squid.abc.AbstractStage = squid.stage.prior.PriorStage(sn=PRIOR_STAGE_SN, stage_config=squid.config.get_stage_config())

else:
self.stage: squid.abc.AbstractStage = squid.stage.cephla.CephlaStage(
microcontroller=self.microcontroller, stage_config=squid.config.get_stage_config()
)

self.slidePositionController = core.SlidePositionController(
self.stage, self.liveController, is_for_wellplate=True
)
Expand Down Expand Up @@ -314,6 +306,13 @@ def loadSimulationObjects(self):
self.microcontroller = microcontroller.Microcontroller(
serial_device=microcontroller.get_microcontroller_serial_device(simulated=True)
)
if USE_PRIOR_STAGE:
self.stage: squid.abc.AbstractStage = squid.stage.prior.PriorStage(sn=PRIOR_STAGE_SN, stage_config=squid.config.get_stage_config())

else:
self.stage: squid.abc.AbstractStage = squid.stage.cephla.CephlaStage(
microcontroller=self.microcontroller, stage_config=squid.config.get_stage_config()
)
# Initialize simulation objects
if ENABLE_SPINNING_DISK_CONFOCAL:
self.xlight = serial_peripherals.XLight_Simulation()
Expand All @@ -340,6 +339,9 @@ def loadSimulationObjects(self):
self.emission_filter_wheel = serial_peripherals.Optospin_Simulation(SN=None)
if USE_SQUID_FILTERWHEEL:
self.squid_filter_wheel = filterwheel.SquidFilterWheelWrapper_Simulation(None)
if USE_XERYON:
self.objective_changer = ObjectiveChanger2PosController_Simulation(sn=XERYON_SERIAL_NUMBER,stage=self.stage)


def loadHardwareObjects(self):
# Initialize hardware objects
Expand All @@ -353,6 +355,14 @@ def loadHardwareObjects(self):
self.log.error(f"Error initializing Microcontroller")
raise

if USE_PRIOR_STAGE:
self.stage: squid.abc.AbstractStage = squid.stage.prior.PriorStage(sn=PRIOR_STAGE_SN, stage_config=squid.config.get_stage_config())

else:
self.stage: squid.abc.AbstractStage = squid.stage.cephla.CephlaStage(
microcontroller=self.microcontroller, stage_config=squid.config.get_stage_config()
)

if ENABLE_SPINNING_DISK_CONFOCAL:
try:
self.xlight = serial_peripherals.XLight(XLIGHT_SERIAL_NUMBER, XLIGHT_SLEEP_TIME_FOR_WHEEL)
Expand Down
43 changes: 41 additions & 2 deletions software/control/objective_changer_2_pos_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import time
import serial

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

class ObjectiveChanger2PosController:
def __init__(self, sn: str, stage: Optional[squid.abc.AbstractStage] = None):
Expand Down Expand Up @@ -49,4 +50,42 @@ def currentPosition(self) -> int:
return self.current_position

def setSpeed(self, value: float):
self.axisX.setSpeed(value)
self.axisX.setSpeed(value)


class ObjectiveChanger2PosController_Simulation:
def __init__(self, sn: str, stage: Optional[squid.abc.AbstractStage] = None):
super().__init__()

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):
pass

def moveToPosition1(self):
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):
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:
return self.current_position

def setSpeed(self, value: float):
pass

0 comments on commit 56ea9d8

Please sign in to comment.