Skip to content

Commit

Permalink
Fixing issue with Autofocus signals
Browse files Browse the repository at this point in the history
  • Loading branch information
beniroquai committed Jul 5, 2023
1 parent 64fe08e commit b09fdaa
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ imswitch/ImSwitch/recordings*
locai/*
conda/*
conda-out/*
imswitch/ImSwitch/ImSwitch/recordings/*
2 changes: 1 addition & 1 deletion imswitch/imcontrol/controller/CommunicationChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 12 additions & 6 deletions imswitch/imcontrol/controller/controllers/PositionerController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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. """
Expand All @@ -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):
Expand Down
18 changes: 3 additions & 15 deletions imswitch/imcontrol/model/managers/positioners/ESP32StageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from imswitch.imcommon.model import APIExport, generateAPI, initLogger
import threading


PHYS_FACTOR = 1
gTIMEOUT = 100
class ESP32StageManager(PositionerManager):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit b09fdaa

Please sign in to comment.