diff --git a/.gitignore b/.gitignore index 8f7594ff0..9cc0607c2 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,4 @@ imswitch/ImSwitch/recordings* locai/* conda/* conda-out/* +imswitch/ImSwitch/ImSwitch/recordings/* diff --git a/imswitch/imcontrol/controller/CommunicationChannel.py b/imswitch/imcontrol/controller/CommunicationChannel.py index c1df884aa..c99f67795 100644 --- a/imswitch/imcontrol/controller/CommunicationChannel.py +++ b/imswitch/imcontrol/controller/CommunicationChannel.py @@ -92,7 +92,7 @@ class CommunicationChannel(SignalInterface): #sigSendScannersInScan = Signal(object) # (scannerList) - sigAutoFocus = Signal(float, float, float) # scanrange and stepsize and initialz + sigAutoFocus = Signal(float, float) # scanrange and stepsize sigAutoFocusRunning = Signal(bool) # indicate if autofocus is running or not sigInitialFocalPlane = Signal(float) # initial focal plane for DeckScanController diff --git a/imswitch/imcontrol/controller/controllers/AufofocusController.py b/imswitch/imcontrol/controller/controllers/AufofocusController.py index 90658d50e..6d94765d2 100644 --- a/imswitch/imcontrol/controller/controllers/AufofocusController.py +++ b/imswitch/imcontrol/controller/controllers/AufofocusController.py @@ -92,7 +92,7 @@ def doAutofocusBackground(self, rangez=100, resolutionz=10): # precompute values for Z-scan Nz = int(2 * rangez // resolutionz) allfocusvals = np.zeros(Nz) - allfocuspositions = np.linspace(-abs(rangez), abs(rangez), Nz) + initialPosition + allfocuspositions = np.int32(np.linspace(-abs(rangez), abs(rangez), Nz) + initialPosition) allfocusimages = [] # 0 move focus to initial position diff --git a/imswitch/imcontrol/controller/controllers/DeckScanController.py b/imswitch/imcontrol/controller/controllers/DeckScanController.py index f179d18ff..735189cd0 100644 --- a/imswitch/imcontrol/controller/controllers/DeckScanController.py +++ b/imswitch/imcontrol/controller/controllers/DeckScanController.py @@ -313,8 +313,7 @@ def doAutofocus(self, params): self._widget.setNImages("Autofocusing...") slot, well, first_position_offset, first_z_focus, first_pos = self.get_first_row() self.positioner.move(value=first_pos, axis="XYZ", is_absolute=True, is_blocking=True) - self._commChannel.sigAutoFocus.emit(float(params["valueRange"]), float(params["valueSteps"]), - float(params["valueInitial"])) + self._commChannel.sigAutoFocus.emit(float(params["valueRange"]), float(params["valueSteps"]))#FIXME: float(params["valueInitial"])) self.isAutofocusRunning = True while self.isAutofocusRunning: time.sleep(0.1) diff --git a/imswitch/imcontrol/controller/controllers/HistoScanController.py b/imswitch/imcontrol/controller/controllers/HistoScanController.py index 8151d512d..815bf53c3 100644 --- a/imswitch/imcontrol/controller/controllers/HistoScanController.py +++ b/imswitch/imcontrol/controller/controllers/HistoScanController.py @@ -220,8 +220,7 @@ def doScan(self): def doAutofocus(self, params): self._logger.info("Autofocusing...") - isRunInBackground = False - self._commChannel.sigAutoFocus.emit(int(params["valueRange"]), int(params["valueSteps"], isRunInBackground)) + self._commChannel.sigAutoFocus.emit(int(params["valueRange"]), int(params["valueSteps"])) def doScanThread(self, coordinateList): # store initial stage position diff --git a/imswitch/imcontrol/controller/controllers/OpentronsDeckScanController.py b/imswitch/imcontrol/controller/controllers/OpentronsDeckScanController.py index 8799743de..5b4e65d1d 100644 --- a/imswitch/imcontrol/controller/controllers/OpentronsDeckScanController.py +++ b/imswitch/imcontrol/controller/controllers/OpentronsDeckScanController.py @@ -247,7 +247,7 @@ def doAutofocus(self, params): slot, well, offset = self.get_first_position() self.scanner.moveToWell(well=well, slot=slot, is_blocking=True) self.scanner.shiftXY(xy_shift=offset, is_blocking=True) - self._commChannel.sigAutoFocus.emit(float(params["valueRange"]), float(params["valueSteps"]), float(params["valueInitial"])) + self._commChannel.sigAutoFocus.emit(float(params["valueRange"]), float(params["valueSteps"])) #FIXME:, float(params["valueInitial"])) self.isAutofocusRunning = True while self.isAutofocusRunning: time.sleep(0.1) diff --git a/imswitch/imcontrol/controller/controllers/PositionerController.py b/imswitch/imcontrol/controller/controllers/PositionerController.py index 20fb75eaa..a7d697297 100644 --- a/imswitch/imcontrol/controller/controllers/PositionerController.py +++ b/imswitch/imcontrol/controller/controllers/PositionerController.py @@ -3,8 +3,8 @@ from imswitch.imcommon.model import APIExport from ..basecontrollers import ImConWidgetController from imswitch.imcommon.model import initLogger - - +import threading +import time class PositionerController(ImConWidgetController): """ Linked to PositionerWidget.""" @@ -67,7 +67,8 @@ def move(self, positionerName, axis, dist, isAbsolute=None, isBlocking=False): self._master.positionersManager[positionerName].move(dist, axis, isAbsolute, isBlocking) except: self._master.positionersManager[positionerName].move(dist, axis) - self.updatePosition(positionerName, axis) + self.updatePosition() + def setPos(self, positionerName, axis, position): """ Moves the positioner to the specified position in the specified axis. """ @@ -92,9 +93,14 @@ def setSpeed(self, positionerName, axis, speed=(1000, 1000, 1000)): self._widget.setSpeedSize(positionerName, axis, speed) def updatePosition(self, positionerName, axis): - newPos = self._master.positionersManager[positionerName].position[axis] - self._widget.updatePosition(positionerName, axis, newPos) - self.setSharedAttr(positionerName, axis, _positionAttr, newPos) + #newPos = self._master.positionersManager[positionerName].position[axis]#FIXME: Is this always pulling the latest position from the device? + def grabPos(): + for i in range(10): + newPos = self._master.positionersManager[positionerName].getPosition()[axis] + self._widget.updatePosition(positionerName, axis, newPos) + self.setSharedAttr(positionerName, axis, _positionAttr, newPos) + time.sleep(.3) + threading.Thread(target=grabPos).start() @APIExport(runOnUIThread=True) def homeAxis(self, positionerName, axis, isBlocking=False): diff --git a/imswitch/imcontrol/model/managers/positioners/ESP32StageManager.py b/imswitch/imcontrol/model/managers/positioners/ESP32StageManager.py index 1042aafcf..75714aac9 100644 --- a/imswitch/imcontrol/model/managers/positioners/ESP32StageManager.py +++ b/imswitch/imcontrol/model/managers/positioners/ESP32StageManager.py @@ -5,7 +5,7 @@ from imswitch.imcommon.model import APIExport, generateAPI, initLogger import threading - + PHYS_FACTOR = 1 gTIMEOUT = 100 class ESP32StageManager(PositionerManager): @@ -178,14 +178,7 @@ def __init__(self, positionerInfo, name, **lowLevelManagers): self.setupMotor(self.minT, self.maxT, self.stepsizeT, self.backlashT, "T") # get bootup position and write to GUI - self._position = self.getPosition() - - # force setting the position - self.setPosition(self._position['X'],"X") - self.setPosition(self._position['Y'],"X") - self.setPosition(self._position['Z'],"Z") - self.setPosition(self._position['T'],"T") - + self._position = self.getPosition() def setAxisOrder(self, order=[0,1,2,3]): self._motor.setMotorAxisOrder(order=order) @@ -231,11 +224,7 @@ def move(self, value=0, axis="X", is_absolute=False, is_blocking=True, accelerat elif axis == 'XYZ': self._motor.move_xyz(value, speed, acceleration=acceleration, is_absolute=is_absolute, is_enabled=isEnable, is_blocking=is_blocking, timeout=timeout) else: - print('Wrong axis, has to be "X" "Y" or "Z".') - - # finally update positions - threading.Thread(target=self.getPosition).start() - + print('Wrong axis, has to be "X" "Y" or "Z".') def measure(self, sensorID=0, NAvg=100): return self._motor.read_sensor(sensorID=sensorID, NAvg=NAvg) @@ -271,7 +260,6 @@ def getPosition(self): # load position from device # t,x,y,z try: - time.sleep(0.5) allPositions = self._motor.get_position() except: allPositions = [0,0,0,0]