path and codegen
This commit is contained in:
@@ -124,7 +124,8 @@ pw: ValToira_2021
|
|||||||
```
|
```
|
||||||
zamofing_t@ganymede:~$ ssh gac-cristall@saresc-cons-03
|
zamofing_t@ganymede:~$ ssh gac-cristall@saresc-cons-03
|
||||||
cd /sf/cristallina/applications/mx/zamofing_t/ESB_MX/python/SwissMX/
|
cd /sf/cristallina/applications/mx/zamofing_t/ESB_MX/python/SwissMX/
|
||||||
conda activate /sf/cristallina/applications/conda/envs/crmx38
|
# conda env list
|
||||||
|
conda activate crmx38
|
||||||
python swissmx.py
|
python swissmx.py
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -301,19 +301,32 @@ class Path(UsrROI):
|
|||||||
a circle is plot at the path positions
|
a circle is plot at the path positions
|
||||||
a cross is plot at the fiducial positions
|
a cross is plot at the fiducial positions
|
||||||
'''
|
'''
|
||||||
def __init__( self, pos=(0,0), path=np.array(((6,4),(16,24),(-5,7),(3,12))), fiducial=None, ficucialScale=5, **kargs):
|
def __init__( self, pos=(0,0), path=np.array(((6,4),(16,24),(-5,7),(3,12))), fiducial=None, ficucialScale=5, **kwargs):
|
||||||
|
trf=kwargs.pop('trf',None)
|
||||||
|
if type(path)==list:
|
||||||
|
path=np.array(path)
|
||||||
if fiducial is None:
|
if fiducial is None:
|
||||||
all=path
|
all=path
|
||||||
else:
|
else:
|
||||||
|
if type(fiducial)==list:
|
||||||
|
fiducial=np.array(fiducial)
|
||||||
all=np.vstack((fiducial,path))
|
all=np.vstack((fiducial,path))
|
||||||
mn=all.min(0)
|
mn=all.min(0)
|
||||||
mx=all.max(0)
|
mx=all.max(0)
|
||||||
sz=mx-mn
|
size=self.szOrig=mx-mn
|
||||||
pg.ROI.__init__(self, pos, sz, **kargs)
|
|
||||||
|
pg.ROI.__init__(self, pos, size, **kwargs)
|
||||||
|
if trf is not None:
|
||||||
|
t=self.transform()
|
||||||
|
t.setMatrix(trf[0][0], trf[0][1], 0,
|
||||||
|
trf[1][0], trf[1][1], 0,
|
||||||
|
0, 0, 1)
|
||||||
|
self.setTransform(t)
|
||||||
|
|
||||||
self._fiducial=fiducial
|
self._fiducial=fiducial
|
||||||
self._path=path
|
self._path=path
|
||||||
self._fidScl=ficucialScale
|
self._fidScl=ficucialScale
|
||||||
self._rect=r=QtCore.QRectF(mn[0], mn[1], sz[0], sz[1])
|
self._rect=r=QtCore.QRectF(mn[0]-5*ficucialScale, mn[1]-5*ficucialScale, size[0]+10*ficucialScale, size[1]+10*ficucialScale)
|
||||||
self._qpath=qPth=QPolygonF()
|
self._qpath=qPth=QPolygonF()
|
||||||
for pt in path:
|
for pt in path:
|
||||||
qPth.append(QPointF(*pt))
|
qPth.append(QPointF(*pt))
|
||||||
@@ -331,8 +344,8 @@ class Path(UsrROI):
|
|||||||
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
||||||
p.setPen(self.currentPen)
|
p.setPen(self.currentPen)
|
||||||
#p.drawEllipse(0, 0, int(sz[0]), int(sz[1]))
|
#p.drawEllipse(0, 0, int(sz[0]), int(sz[1]))
|
||||||
p.drawRect(0, 0, int(sz[0]), int(sz[1]))
|
#p.drawRect(0, 0, int(sz[0]), int(sz[1]))
|
||||||
|
p.drawRect(QtCore.QRectF(0, 0, sz[0], sz[1]).normalized())
|
||||||
#obj_info(p)
|
#obj_info(p)
|
||||||
p.scale(sz[0]/r.width(), sz[1]/r.height())
|
p.scale(sz[0]/r.width(), sz[1]/r.height())
|
||||||
p.translate(-r.left(), -r.top())
|
p.translate(-r.left(), -r.top())
|
||||||
@@ -362,10 +375,18 @@ class Path(UsrROI):
|
|||||||
jsn= {
|
jsn= {
|
||||||
'__class__':self.__class__.__name__,
|
'__class__':self.__class__.__name__,
|
||||||
'pos':tuple(self.pos()),
|
'pos':tuple(self.pos()),
|
||||||
'fiducial': repr(self._fiducial),
|
'fiducial': self._fiducial.tolist(),
|
||||||
'path': repr(self._path),
|
'path': self._path.tolist(),
|
||||||
'ficucialScale':self._fidScl
|
'ficucialScale':self._fidScl
|
||||||
}
|
}
|
||||||
|
so=pg.Point(self.szOrig)
|
||||||
|
sn=self.size()
|
||||||
|
trf=self.transform()
|
||||||
|
if not trf.isIdentity() or so!=sn:
|
||||||
|
scl=sn/so
|
||||||
|
#obj_info(trf)
|
||||||
|
trf=((trf.m11()*scl[0],trf.m12()*scl[0]),(trf.m21()*scl[1],trf.m22()*scl[1]))
|
||||||
|
jsn['trf']=trf
|
||||||
return jsn
|
return jsn
|
||||||
|
|
||||||
class FixTargetFrame(UsrROI):
|
class FixTargetFrame(UsrROI):
|
||||||
@@ -532,7 +553,7 @@ class FixTargetFrame(UsrROI):
|
|||||||
|
|
||||||
pts=np.array([xx.reshape(-1), yy.reshape(-1)], dtype=np.float).transpose() #*pitch
|
pts=np.array([xx.reshape(-1), yy.reshape(-1)], dtype=np.float).transpose() #*pitch
|
||||||
|
|
||||||
param={'grid':grid, 'points':pts}
|
param={'grid':grid, 'points':pts, 'mode':mode}
|
||||||
t=self.transform()
|
t=self.transform()
|
||||||
p=np.array(self.pos())
|
p=np.array(self.pos())
|
||||||
s=self.size()/self._dscr['size']
|
s=self.size()/self._dscr['size']
|
||||||
|
|||||||
99
swissmx.py
99
swissmx.py
@@ -1443,7 +1443,9 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
p=(np.asmatrix(m)*trf).A
|
p=(np.asmatrix(m)*trf).A
|
||||||
|
|
||||||
p[:,0]*=-1 #X axis has inverted sign !
|
p[:,0]*=-1 #X axis has inverted sign !
|
||||||
param['points']=p
|
param['ptsTrf']=p # transformed points
|
||||||
|
param['numPts']=p.shape[0]
|
||||||
|
#param['points']=p
|
||||||
|
|
||||||
# add up to 100 test fiducial
|
# add up to 100 test fiducial
|
||||||
vb=self.vb
|
vb=self.vb
|
||||||
@@ -1473,6 +1475,9 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
#_log.debug(f'step to 2nd point:{p[1,:]-p[0,:]}')
|
#_log.debug(f'step to 2nd point:{p[1,:]-p[0,:]}')
|
||||||
#print('DEBUG: difference from point to point:')
|
#print('DEBUG: difference from point to point:')
|
||||||
#print(np.diff(p, axis=0))
|
#print(np.diff(p, axis=0))
|
||||||
|
#param['codeGen']=0
|
||||||
|
param['codeGen']=1
|
||||||
|
param['codeGen']=2
|
||||||
self.daq_collect(**param)
|
self.daq_collect(**param)
|
||||||
|
|
||||||
elif task == TASK_GRID:
|
elif task == TASK_GRID:
|
||||||
@@ -1891,7 +1896,7 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
mft.setAccessibleName(TASK_FIX_TARGET)
|
mft.setAccessibleName(TASK_FIX_TARGET)
|
||||||
self._tabs_daq_methods.setCurrentWidget(mft) #set this as the active tabs
|
self._tabs_daq_methods.setCurrentWidget(mft) #set this as the active tabs
|
||||||
|
|
||||||
mft._cbType.addItems(["Fiducial", "FixTarget(12.5x12.5)", "FixTarget(23.0x23.0)", "FixTarget(<param>)", "Grid(<param>)"])
|
mft._cbType.addItems(["Fiducial", "FixTarget(12.5x12.5)", "FixTarget(23.0x23.0)", "FixTarget(<param>)", "Grid(<param>)", "SwissMX(<param>)", "SwissFEL(<param>)"])
|
||||||
mft._btnAdd.clicked.connect(self.module_fix_target_add_obj)
|
mft._btnAdd.clicked.connect(self.module_fix_target_add_obj)
|
||||||
mft._btnDelAll.clicked.connect(self.module_fix_target_del_all_obj)
|
mft._btnDelAll.clicked.connect(self.module_fix_target_del_all_obj)
|
||||||
mft._btnFit.clicked.connect(self.module_fix_target_fit_fiducial)
|
mft._btnFit.clicked.connect(self.module_fix_target_fit_fiducial)
|
||||||
@@ -2005,8 +2010,7 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
idx=mft._cbType.currentIndex()
|
idx=mft._cbType.currentIndex()
|
||||||
param=mft._txtParam.text()
|
param=mft._txtParam.text()
|
||||||
|
|
||||||
#cb.addItems(["Fiducial", "FixTarget(12.5x12.5)", "FixTarget(23.0x23.0)", "FixTarget(<param>)", "Grid(<param>)"])
|
#mft._cbType.addItems(["Fiducial", "FixTarget(12.5x12.5)", "FixTarget(23.0x23.0)", "FixTarget(<param>)", "Grid(<param>)", "SwissMX-path"])
|
||||||
|
|
||||||
#bm_pos_eu=self._goBeamMarker._pos_eu
|
#bm_pos_eu=self._goBeamMarker._pos_eu
|
||||||
#bm_size_eu=self._goBeamMarker._size_eu
|
#bm_size_eu=self._goBeamMarker._size_eu
|
||||||
|
|
||||||
@@ -2032,6 +2036,27 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
elif idx==4:
|
elif idx==4:
|
||||||
w,h=(30, 22)
|
w,h=(30, 22)
|
||||||
go=UsrGO.Grid((fx-w/2,fy-h/2), (w, h), (30, 22), .1)
|
go=UsrGO.Grid((fx-w/2,fy-h/2), (w, h), (30, 22), .1)
|
||||||
|
elif idx==5:
|
||||||
|
ofs=(0, 0);
|
||||||
|
width=10;
|
||||||
|
fidScl=.02
|
||||||
|
fiducial=((-.2, -.2), (-.2, 2.4), (10.2, -.2), (10.2, 2.4))
|
||||||
|
if param:
|
||||||
|
p=json.loads('{'+param+'}') # "ofs":[10, 5],"width":200,"fidScl":0.5,"fiducial":[[18,7],[25,16],[70, 20]]
|
||||||
|
locals().update(p)
|
||||||
|
fiducial=np.array(fiducial)
|
||||||
|
gp=psi_device.shapepath.GenPath();
|
||||||
|
gp.swissmx_points(ofs=ofs, width=width, flipy=True)
|
||||||
|
go=UsrGO.Path((fx-width/2, fy-1.2), gp.points, fiducial, fidScl)
|
||||||
|
elif idx==6:
|
||||||
|
ofs=(0, 0); width=10; fidScl=.02
|
||||||
|
fiducial=((-.2, -.2), (-.2, 2.0), (10.2, -.2), (10.2, 2.0))
|
||||||
|
if param:
|
||||||
|
p=json.loads('{'+param+'}') # "ofs":[10, 5],"width":200,"fidScl":0.5,"fiducial":[[18,7],[25,16],[70, 20]]
|
||||||
|
locals().update(p)
|
||||||
|
fiducial=np.array(fiducial)
|
||||||
|
gp=psi_device.shapepath.GenPath();gp.swissfel_points(ofs=ofs, width=width,flipy=True)
|
||||||
|
go=UsrGO.Path((fx-width/2,fy-1.2), gp.points, fiducial, fidScl)
|
||||||
else:
|
else:
|
||||||
_log.error('index not handeled')
|
_log.error('index not handeled')
|
||||||
|
|
||||||
@@ -2084,7 +2109,23 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
#go.setSize((1,1))
|
#go.setSize((1,1))
|
||||||
sz=(trf[0,0],trf[1,1])
|
sz=(trf[0,0],trf[1,1])
|
||||||
go.setSize(sz)
|
go.setSize(sz)
|
||||||
|
j=0
|
||||||
|
elif type(go)==UsrGO.Path:
|
||||||
|
if j==4:
|
||||||
|
fid=go._fiducial
|
||||||
|
sz=go.szOrig
|
||||||
|
fid=fid/sz
|
||||||
|
trf=geometry.geometry.least_square_trf(ptFitTrf, fid)
|
||||||
|
print(trf)
|
||||||
|
tr=go.transform()
|
||||||
|
tr.setMatrix(1, trf[1, 0]/trf[0, 0], 0,
|
||||||
|
trf[0, 1]/trf[1, 1], 1, 0,
|
||||||
|
0, 0, 1)
|
||||||
|
go.setTransform(tr)
|
||||||
|
go.setPos(trf[:, 2])
|
||||||
|
# go.setSize((1,1))
|
||||||
|
sz=(trf[0, 0], trf[1, 1])
|
||||||
|
go.setSize(sz)
|
||||||
j=0
|
j=0
|
||||||
elif type(go)==UsrGO.Fiducial and go.size()[0]==0.12:
|
elif type(go)==UsrGO.Fiducial and go.size()[0]==0.12:
|
||||||
if j<ptFitTrf.shape[0]:
|
if j<ptFitTrf.shape[0]:
|
||||||
@@ -2103,7 +2144,16 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
raise AttributeError('canceled')
|
raise AttributeError('canceled')
|
||||||
|
|
||||||
def daq_collect(self, **kwargs):# points, visualizer_method, visualizer_params):
|
def daq_collect(self, **kwargs):# points, visualizer_method, visualizer_params):
|
||||||
#def _OLD_daq_collect_points(self, points, visualizer_method, visualizer_params):
|
'''
|
||||||
|
kwargs:
|
||||||
|
codeGen: 0 pvt motion using ptsTrf
|
||||||
|
1 pvt motion using trf and points
|
||||||
|
2 pvt motion, compact grid code
|
||||||
|
grid: grid dictionary with orig, pitch, count
|
||||||
|
trf: transformation matrix
|
||||||
|
points: list of points without transformation
|
||||||
|
ptsTrf: list of points with transformation
|
||||||
|
'''
|
||||||
app = QApplication.instance()
|
app = QApplication.instance()
|
||||||
cfg = app._cfg
|
cfg = app._cfg
|
||||||
dt_misc = cfg.value(AppCfg.DT_MISC)
|
dt_misc = cfg.value(AppCfg.DT_MISC)
|
||||||
@@ -2121,7 +2171,7 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
app._jungfrau=jf=psi_device.Jungfrau()
|
app._jungfrau=jf=psi_device.Jungfrau()
|
||||||
sp=dt._shapepath
|
sp=dt._shapepath
|
||||||
sp.verbose=dt_misc['verbose']
|
sp.verbose=dt_misc['verbose']
|
||||||
sp.points=kwargs['points']
|
|
||||||
sp.meta['pt2pt_time']=dt_misc['pt2pt_time']
|
sp.meta['pt2pt_time']=dt_misc['pt2pt_time']
|
||||||
sp.meta['sync_mode']=dt_misc['sync_mode']
|
sp.meta['sync_mode']=dt_misc['sync_mode']
|
||||||
sp.meta['sync_flag']=dt_misc['sync_flag']
|
sp.meta['sync_flag']=dt_misc['sync_flag']
|
||||||
@@ -2133,29 +2183,42 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
#dlg.canceled.connect(self.complete_daq)
|
#dlg.canceled.connect(self.complete_daq)
|
||||||
#dlg.setAutoClose(True)
|
#dlg.setAutoClose(True)
|
||||||
#dlg.show()
|
#dlg.show()
|
||||||
|
|
||||||
dlg.setLabelText("Setup Gather/Sync");dlg+=5
|
dlg.setLabelText("Setup Gather/Sync");dlg+=5
|
||||||
sp.setup_gather()
|
sp.setup_gather(kwargs['numPts'])
|
||||||
sp.setup_sync(verbose=sp.verbose&0x40, timeOfs=dt_misc['time_ofs'], timeCor=dt_misc['time_cor'])
|
sp.setup_sync(verbose=sp.verbose&0x40, timeOfs=dt_misc['time_ofs'], timeCor=dt_misc['time_cor'])
|
||||||
|
dlg.setLabelText("Download motion program");dlg+=5
|
||||||
|
codeGen=kwargs['codeGen']
|
||||||
|
if codeGen==0:
|
||||||
|
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10, points=kwargs['ptsTrf'])
|
||||||
|
elif codeGen==1:
|
||||||
|
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10, points=kwargs['points'])
|
||||||
|
elif codeGen==2:
|
||||||
|
sp.setup_motion(fnPrg=fn+'.prg', mode=4, scale=1., dwell=10, grid=kwargs['grid'])
|
||||||
try:
|
try:
|
||||||
p=geo._fitPlane
|
p=geo._fitPlane
|
||||||
#X has inverted sign !
|
if codeGen==0:
|
||||||
#Z is in um -> therefore the offset must be multiplied with 1000!
|
# X has inverted sign !
|
||||||
#Z motor has opposite sign !!!
|
# Z is in um -> therefore the offset must be multiplied with 1000 ! Z motor has opposite sign !
|
||||||
#sp.setup_coord_trf(cz=f'{-p[0]:+.18g}X{p[1]:+.18g}Y{p[2]*1000:+.18g}') # reset to shape path system
|
cz=f'{+p[0]:+.18g}X{-p[1]:+.18g}Y{-p[2]*1000:+.18g}'
|
||||||
sp.setup_coord_trf(cz=f'{+p[0]:+.18g}X{-p[1]:+.18g}Y{-p[2]*1000:+.18g}') # reset to shape path system
|
else:
|
||||||
|
trf=kwargs['trf']
|
||||||
|
cz=f'{+p[0]:+.18g}X{-p[1]:+.18g}Y{-p[2]*1000:+.18g}'
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
cz='0'
|
||||||
|
if codeGen==0:
|
||||||
|
fx='X';fy='Y'
|
||||||
|
else:
|
||||||
|
trf=kwargs['trf']*1000#fix shear/rotation mm->um
|
||||||
|
fx=f'{trf[0,0]:+.18g}X{trf[1,0]:+.18g}Y{trf[2,0]:+.18g}'
|
||||||
|
fy=f'{trf[0,1]:+.18g}X{trf[1,1]:+.18g}Y{trf[2,1]:+.18g}'
|
||||||
_log.warning('no plane fitting done. z does not move')
|
_log.warning('no plane fitting done. z does not move')
|
||||||
sp.setup_coord_trf() # reset to shape path system
|
sp.setup_coord_trf(fx, fy, cz) # reset to shape path system
|
||||||
# sp.meta['pt2pt_time']=10 #put between setup_sync and setup_motion to have more motion points than FEL syncs
|
|
||||||
dlg.setLabelText("Download motion program");dlg+=5
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sp.comm.gpascii._cb_func=lambda i, sz:self.cb_progress(i, sz, dlg)
|
sp.comm.gpascii._cb_func=lambda i, sz:self.cb_progress(i, sz, dlg)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10)
|
|
||||||
if dlg.wasCanceled():
|
if dlg.wasCanceled():
|
||||||
return
|
return
|
||||||
dlg.setLabelText("Homing and get ready");dlg+=5
|
dlg.setLabelText("Homing and get ready");dlg+=5
|
||||||
|
|||||||
Reference in New Issue
Block a user