better but not yet perfect autofocus

This commit is contained in:
2022-09-19 17:20:00 +02:00
parent 21afed9739
commit c3542ad38c
7 changed files with 223 additions and 93 deletions

View File

@@ -666,6 +666,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
def cb_new_frame_pv(self, **kwargs):
#thrd=threading.current_thread()
#_log.debug(f'thread:{thrd.getName()}, {thrd.native_id}')
#_log.debug(f"{kwargs['timestamp']}")
app=QApplication.instance()
cam=app._camera
@@ -679,6 +680,11 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
pic.dtype=np.uint16
camera.epics_cam.set_fiducial(pic, 255)
cam._pic=pic
cam._timestamp=kwargs['timestamp']
try:
cam.process()
except AttributeError as e:
pass
# self._goImg.setImage(cam._pic) caused some deadlocks.
# therefore try to update the image with signals instead
self.sigNewCamImg.emit()
@@ -1613,14 +1619,39 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
af_range=misc['af_range']
n=misc['af_steps']
rng=(-af_range/2, af_range/2)
with pg.ProgressDialog('Progress', 0, n) as dlg:
geo.autofocus(app._camera, self.tweakers['base_z'],rng, n,dlg)
#geo.autofocus(app._camera, self.tweakers['base_z'],rng, n,dlg)
af= geometry.autofocus(app._camera, self.tweakers['base_z'])
# af.run(rng, n, dlg)
#with pg.ProgressDialog('Progress', 0, n) as dlg:
af.run_continous(rng=(-.5, .5), velo=0.3)
def cb_find_fiducial(self):
app=QApplication.instance()
geo=app._geometry
#geo.autofocus(app._camera, self.tweakers['base_z'],rng=(-1, 1), n=30,saveImg=True)
pos,corr=geo.find_fiducial(app._camera, sz=(210,210),brd=(20,20))
fx=self.tweakers["fast_x"].get_rbv()
fy=self.tweakers["fast_y"].get_rbv()
bz=self.tweakers["base_z"].get_rbv()
#oc=geo._opt_ctr
#bm_pos=self._goBeamMarker.pos()
#bm_sz=self._goBeamMarker.size()
#pos_eu=geo.pix2pos(pos)
#pImg=pg.Point(self._goImg.mapFromScene(pos))
#pTrk=pg.Point(self._goTracked.mapFromScene(pos))
pos_scn=self._goImg.mapToScene(pg.Point(pos))
pos_eu=self._goTracked.mapFromScene(pos_scn)
l=.120
#go=UsrGO.Fiducial((fx-l/2, fy-l/2), (l, l), bz)
go=UsrGO.Fiducial((pos_eu.x()-l/2, pos_eu.y()-l/2), (l, l), bz)
go.sigRegionChangeFinished.connect(self.cb_fiducial_update_z)
grp=self._goTracked
grp.addItem(go)
self._moduleFixTarget._tree.setData(grp.childItems())
pass
def cb_testcode(self):