wip
This commit is contained in:
@@ -450,7 +450,8 @@ class FixTargetFrame(UsrROI):
|
|||||||
def __init__( self, pos=(0,0), size=(100,100), tpl='test', dscr=None, **kwargs):
|
def __init__( self, pos=(0,0), size=(100,100), tpl='test', dscr=None, **kwargs):
|
||||||
self.code_gen=kwargs.pop('code_gen',0)
|
self.code_gen=kwargs.pop('code_gen',0)
|
||||||
trf=kwargs.pop('trf',None)
|
trf=kwargs.pop('trf',None)
|
||||||
pg.ROI.__init__(self, pos, size, **kwargs)
|
assert(kwargs==dict())
|
||||||
|
pg.ROI.__init__(self, pos, size)#, **kwargs)
|
||||||
if trf is not None:
|
if trf is not None:
|
||||||
t=self.transform()
|
t=self.transform()
|
||||||
t.setMatrix(trf[0][0], trf[0][1], 0,
|
t.setMatrix(trf[0][0], trf[0][1], 0,
|
||||||
@@ -552,7 +553,7 @@ class FixTargetFrame(UsrROI):
|
|||||||
|
|
||||||
def get_scan_param(self):
|
def get_scan_param(self):
|
||||||
'returns scan parameters for scanning with deltatau. the format is as used for shapepath'
|
'returns scan parameters for scanning with deltatau. the format is as used for shapepath'
|
||||||
mode=0x2 #default fast y axis
|
scan=0x2 #default fast y axis
|
||||||
grid=self._dscr['grid']
|
grid=self._dscr['grid']
|
||||||
self._dscr['size']
|
self._dscr['size']
|
||||||
#pos=np.array(self.pos())
|
#pos=np.array(self.pos())
|
||||||
@@ -560,10 +561,10 @@ class FixTargetFrame(UsrROI):
|
|||||||
#pos =np.array(grid['pos'],np.float)
|
#pos =np.array(grid['pos'],np.float)
|
||||||
#pitch=np.array(grid['pitch'],np.float)
|
#pitch=np.array(grid['pitch'],np.float)
|
||||||
xx, yy=np.meshgrid(range(cnt[0]), range(cnt[1]))
|
xx, yy=np.meshgrid(range(cnt[0]), range(cnt[1]))
|
||||||
if mode&0x01: #modify x scaning forward backward each line
|
if scan&0x01: #modify x scaning forward backward each line
|
||||||
for i in range(1,cnt[1],2):
|
for i in range(1,cnt[1],2):
|
||||||
xx[i]=xx[i][::-1]
|
xx[i]=xx[i][::-1]
|
||||||
if mode&0x02: # modify y scaning forward backward each line
|
if scan&0x02: # modify y scaning forward backward each line
|
||||||
xx=xx.T
|
xx=xx.T
|
||||||
yy=yy.T
|
yy=yy.T
|
||||||
for i in range(1, cnt[0], 2):
|
for i in range(1, cnt[0], 2):
|
||||||
@@ -573,15 +574,22 @@ class FixTargetFrame(UsrROI):
|
|||||||
|
|
||||||
param={'grid':grid, 'points':pts, 'code_gen': self.code_gen}
|
param={'grid':grid, 'points':pts, 'code_gen': self.code_gen}
|
||||||
|
|
||||||
|
# TODO: simplify !!!
|
||||||
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']
|
||||||
trf=np.array(((t.m11(),t.m12()),(t.m21(),t.m22()),(0,0)))
|
trf=np.array(((t.m11(),t.m12()),(t.m21(),t.m22()),(0,0)))
|
||||||
trf[2,:]=p # shift origin
|
trf[2,:]=p # shift origin
|
||||||
#trf[:2, 0]*=s[0];trf[:2, 1]*=s[1] #scaling (before rotation shear)
|
|
||||||
trf[:2,:]=(trf[:2,:].T*s).T # same as np.asmatrix(np.diag(s))*trf[:2,:], trf[:2,:]*=s not working, scale before rot / shear
|
trf[:2,:]=(trf[:2,:].T*s).T # same as np.asmatrix(np.diag(s))*trf[:2,:], trf[:2,:]*=s not working, scale before rot / shear
|
||||||
|
|
||||||
# trf*'gridpos in um' -> motor pos in mm
|
# trf*'gridpos in um' -> motor pos in mm
|
||||||
|
pos=np.array(param['grid']['pos']) # in um
|
||||||
|
pitch=np.array(param['grid']['pitch']) # in um
|
||||||
|
trf2=np.asmatrix(np.identity(3))
|
||||||
|
trf2[:, :2]=trf
|
||||||
|
trf2*=np.asmatrix(((-1000, 0, 0), (0, 1000, 0), (0, 0, 1)))
|
||||||
|
trf3=np.asmatrix(((pitch[0], 0, 0), (0, pitch[1], 0), (pos[0], pos[1], 1)))
|
||||||
|
trf=(trf3*trf2)[:, :2]
|
||||||
param['trf']=trf
|
param['trf']=trf
|
||||||
return param
|
return param
|
||||||
|
|
||||||
|
|||||||
105
swissmx.py
105
swissmx.py
@@ -1430,30 +1430,10 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
_log.warning(f'no scan parameters for object->skipped:{go}')
|
_log.warning(f'no scan parameters for object->skipped:{go}')
|
||||||
continue
|
continue
|
||||||
|
trf=np.asmatrix(param['trf'])
|
||||||
p=param['points']
|
p=param['points']
|
||||||
trf=np.asmatrix(param['trf']*1000) #fix shear/rotation mm->um
|
p=(np.hstack((p,np.ones((p.shape[0],1))))*trf).A
|
||||||
trf[:,0]*=-1 #X axis has inverted sign !
|
param['pts_trf']=p # transformed points in um motor coordinates
|
||||||
if t==UsrGO.FixTargetFrame:
|
|
||||||
pos=np.array(param['grid']['pos']) #in um
|
|
||||||
pitch=np.array(param['grid']['pitch']) #in um
|
|
||||||
#TODO !!!
|
|
||||||
#input grid coordinate output um
|
|
||||||
trf2=np.asmatrix(np.identity(3))
|
|
||||||
trf2[:, :2]=param['trf']
|
|
||||||
trf2*=np.asmatrix(((-1000, 0, 0), (0, 1000, 0), (0, 0, 1)))
|
|
||||||
trf3=np.asmatrix(((pitch[0], 0, 0), (0, pitch[1], 0), (pos[0], pos[1], 1)))
|
|
||||||
trf2=(trf3*trf2)[:,:2]
|
|
||||||
p2=(np.asmatrix((0,0,1))*trf2).A
|
|
||||||
p2=(np.hstack((param['points'],np.ones((p.shape[0],1))))*trf2).A
|
|
||||||
|
|
||||||
m=np.hstack((p*pitch+pos,np.ones((p.shape[0],1))))
|
|
||||||
p=(np.asmatrix(m)*trf).A
|
|
||||||
param['pts_trf']=p # transformed points
|
|
||||||
else:
|
|
||||||
m=np.hstack((p,np.ones((p.shape[0],1))))
|
|
||||||
p=(np.asmatrix(m)*trf).A
|
|
||||||
param['pts_trf']=p # transformed points
|
|
||||||
|
|
||||||
param['num_pts']=p.shape[0]
|
param['num_pts']=p.shape[0]
|
||||||
vb=self.vb
|
vb=self.vb
|
||||||
grp=self._goTracked
|
grp=self._goTracked
|
||||||
@@ -2017,7 +1997,20 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
#mft._cbType.addItems(["Fiducial", "FixTarget(12.5x12.5)", "FixTarget(23.0x23.0)", "FixTarget(<param>)", "Grid(<param>)", "SwissMX-path"])
|
#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
|
||||||
|
try:
|
||||||
|
pLst=param.split(',')
|
||||||
|
pStr='{'
|
||||||
|
for p in pLst:
|
||||||
|
if not p: continue
|
||||||
|
m=re.match('\s*(.*?)\s*[=:]\s*(.*)\s*', p)
|
||||||
|
k, v=m.groups()
|
||||||
|
v=v.replace('(', '[').replace(')', ']')
|
||||||
|
pStr+=f'"{k}":{v}'
|
||||||
|
pStr+='}'
|
||||||
|
param=json.loads(pStr) # "ofs":[10, 5],"width":200,"fidScl":0.5,"fiducial":[[18,7],[25,16],[70, 20]]
|
||||||
|
except json.decoder.JSONDecodeError as e:
|
||||||
|
_log.error(f'{e}:{param}')
|
||||||
|
param=dict()
|
||||||
if idx==0:
|
if idx==0:
|
||||||
#go=UsrGO.Fiducial(bm_pos+bm_sz/2-(20, 20), (40, 40),(fx,fy,bz))
|
#go=UsrGO.Fiducial(bm_pos+bm_sz/2-(20, 20), (40, 40),(fx,fy,bz))
|
||||||
l=.120
|
l=.120
|
||||||
@@ -2028,36 +2021,36 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
l=np.linalg.norm(v)
|
l=np.linalg.norm(v)
|
||||||
l=12.5
|
l=12.5
|
||||||
#ctr=bm_pos+bm_sz/2
|
#ctr=bm_pos+bm_sz/2
|
||||||
go=UsrGO.FixTargetFrame((fx-l/2,fy-l/2), (l, l), tpl='12.5x12.5')
|
go=UsrGO.FixTargetFrame((fx-l/2,fy-l/2), (l, l), tpl='12.5x12.5',**param)
|
||||||
elif idx==2:
|
elif idx==2:
|
||||||
v=geo.pos2pix((23, 0))
|
v=geo.pos2pix((23, 0))
|
||||||
l=np.linalg.norm(v)
|
l=np.linalg.norm(v)
|
||||||
l=23
|
l=23
|
||||||
go=UsrGO.FixTargetFrame((fx-l/2,fy-l/2), (l, l), tpl='23.0x23.0')
|
go=UsrGO.FixTargetFrame((fx-l/2,fy-l/2), (l, l), tpl='23.0x23.0',**param)
|
||||||
elif idx==3:
|
elif idx==3:
|
||||||
w,h=(.120*12, .120*8)
|
w,h=(.120*12, .120*8)
|
||||||
go=UsrGO.FixTargetFrame((fx-w/2,fy-h/2), (w, h), tpl='test')
|
go=UsrGO.FixTargetFrame((fx-w/2,fy-h/2), (w, h), tpl='test',**param)
|
||||||
elif idx==4:
|
elif idx==4:
|
||||||
w,h=(30, 22)
|
w,h=size=param.pop('size',(30, 20))
|
||||||
go=UsrGO.Grid((fx-w/2,fy-h/2), (w, h), (30, 22), .1)
|
cnt=param.pop('cnt',(30, 22))
|
||||||
|
fiducialSize=param.pop('fiducialSize',.1)
|
||||||
|
go=UsrGO.Grid((fx-w/2,fy-h/2), size, cnt, fiducialSize,**param)
|
||||||
elif idx==5:
|
elif idx==5:
|
||||||
ofs=(.2, .2); width=10; fidScl=.02
|
ofs=param.pop('ofs',(.2, .2))
|
||||||
fiducial=((.1, .1), (.1, 2.7), (10.3, .1), (10.3, 2.7))
|
width=param.pop('width',10)
|
||||||
if param:
|
fidScl=param.pop('fidScl',.02)
|
||||||
p=json.loads('{'+param+'}') # "ofs":[10, 5],"width":200,"fidScl":0.5,"fiducial":[[18,7],[25,16],[70, 20]]
|
fiducial=param.pop('fiducial',((.1, .1), (.1, 2.7), (10.3, .1), (10.3, 2.7)))
|
||||||
locals().update(p)
|
|
||||||
fiducial=np.array(fiducial)
|
fiducial=np.array(fiducial)
|
||||||
gp=psi_device.shapepath.GenPath(); gp.swissmx_points(ofs=ofs, width=width, flipy=True)
|
gp=psi_device.shapepath.GenPath(); gp.swissmx_points(ofs=ofs, width=width, flipy=True)
|
||||||
sz=gp.points.max(0)+np.array(ofs)*2
|
sz=gp.points.max(0)+np.array(ofs)*2
|
||||||
go=UsrGO.Path((fx-sz[0]/2, fy-sz[1]/2), sz, gp.points, fiducial, fidScl)
|
go=UsrGO.Path((fx-sz[0]/2, fy-sz[1]/2), sz, gp.points, fiducial, fidScl,**param)
|
||||||
elif idx==6:
|
elif idx==6:
|
||||||
ofs=(.2, .2); width=10; fidScl=.02
|
ofs=param.pop('ofs',(.2, .2))
|
||||||
fiducial=((.1, .1), (.1, 2.2), (10.3, .1), (10.3, 2.2))
|
width=param.pop('width',10)
|
||||||
if param:
|
fidScl=param.pop('fidScl',.02)
|
||||||
p=json.loads('{'+param+'}') # "ofs":[10, 5],"width":200,"fidScl":0.5,"fiducial":[[18,7],[25,16],[70, 20]]
|
fiducial=param.pop('fiducial',((.1, .1), (.1, 2.2), (10.3, .1), (10.3, 2.2)))
|
||||||
locals().update(p)
|
|
||||||
fiducial=np.array(fiducial)
|
fiducial=np.array(fiducial)
|
||||||
gp=psi_device.shapepath.GenPath(); gp.swissfel_points(ofs=ofs, width=width,flipy=True)
|
gp=psi_device.shapepath.GenPath(); gp.swissfel_points(ofs=ofs, width=width,flipy=True,**param)
|
||||||
sz=gp.points.max(0)+np.array(ofs)*2
|
sz=gp.points.max(0)+np.array(ofs)*2
|
||||||
go=UsrGO.Path((fx-sz[0]/2, fy-sz[1]/2), sz, gp.points, fiducial, fidScl)
|
go=UsrGO.Path((fx-sz[0]/2, fy-sz[1]/2), sz, gp.points, fiducial, fidScl)
|
||||||
else:
|
else:
|
||||||
@@ -2187,19 +2180,20 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
#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(kwargs['num_pts'])
|
num_pts=kwargs['num_pts']
|
||||||
|
code_gen=kwargs['code_gen']
|
||||||
|
sp.setup_gather(num_pts)
|
||||||
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
|
dlg.setLabelText("Download motion program");dlg+=5
|
||||||
codeGen=kwargs['code_gen']
|
if code_gen==0:
|
||||||
if codeGen==0:
|
|
||||||
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10, points=kwargs['pts_trf'])
|
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10, points=kwargs['pts_trf'])
|
||||||
elif codeGen==1:
|
elif code_gen==1:
|
||||||
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10, points=kwargs['points'])
|
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10, points=kwargs['points'],trf=kwargs['trf'])
|
||||||
elif codeGen==2:
|
elif code_gen==2:
|
||||||
sp.setup_motion(fnPrg=fn+'.prg', mode=4, scale=1., dwell=10, grid=kwargs['grid'])
|
sp.setup_motion(fnPrg=fn+'.prg', mode=4, scale=1., dwell=10, grid=kwargs['grid'],trf=kwargs['trf'])
|
||||||
try:
|
try:
|
||||||
p=geo._fitPlane
|
p=geo._fitPlane
|
||||||
if codeGen==0:
|
if code_gen==0:
|
||||||
# X has inverted sign !
|
# X has inverted sign !
|
||||||
# Z is in um -> therefore the offset must be multiplied with 1000 ! Z motor has opposite sign !
|
# Z is in um -> therefore the offset must be multiplied with 1000 ! Z motor has opposite sign !
|
||||||
cz=f'{+p[0]:+.18g}X{-p[1]:+.18g}Y{-p[2]*1000:+.18g}'
|
cz=f'{+p[0]:+.18g}X{-p[1]:+.18g}Y{-p[2]*1000:+.18g}'
|
||||||
@@ -2209,17 +2203,16 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
cz='0'
|
cz='0'
|
||||||
_log.warning('no plane fitting done. z does not move')
|
_log.warning('no plane fitting done. z does not move')
|
||||||
|
|
||||||
trf=kwargs['trf']*1000 # fix shear/rotation mm->um
|
trf=kwargs['trf']
|
||||||
trf[:, 0]*=-1 # X axis has inverted sign !
|
if code_gen==0:
|
||||||
if codeGen==0:
|
|
||||||
fx='X';fy='Y'
|
fx='X';fy='Y'
|
||||||
else:
|
else:
|
||||||
fx=f'{trf[0,0]:+.18g}X{trf[1,0]:+.18g}Y{trf[2,0]:+.18g}'
|
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}'
|
fy=f'{trf[0,1]:+.18g}X{trf[1,1]:+.18g}Y{trf[2,1]:+.18g}'
|
||||||
|
|
||||||
print(f'pts_trf[0,:]={kwargs["pts_trf"][0, :]}')
|
_log.debug(f'pts_trf[0,:]={kwargs["pts_trf"][0, :]}')
|
||||||
print(f'points[0,:]={kwargs["points"][0, :]}')
|
_log.debug((f'points[0,:]={kwargs["points"][0, :]}')
|
||||||
print(f'trf=\n{trf}')
|
_log.debug((f'trf=\n{trf}')
|
||||||
|
|
||||||
sp.setup_coord_trf(fx, fy, cz) # reset to shape path system
|
sp.setup_coord_trf(fx, fy, cz) # reset to shape path system
|
||||||
|
|
||||||
@@ -2245,7 +2238,7 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
|
|||||||
sp.run() # start motion program
|
sp.run() # start motion program
|
||||||
sp.wait_armed() # wait until motors are at first position
|
sp.wait_armed() # wait until motors are at first position
|
||||||
#time.sleep(1.0) # wait armed does not wor yet ?!?
|
#time.sleep(1.0) # wait armed does not wor yet ?!?
|
||||||
jf.acquire(sp.points.shape[0])
|
jf.acquire(num_pts)
|
||||||
sp.trigger(0.5) # send a start trigger (if needed) after given time
|
sp.trigger(0.5) # send a start trigger (if needed) after given time
|
||||||
if not dt._comm is None:
|
if not dt._comm is None:
|
||||||
dlg.setLabelText("run motion/acquisition")
|
dlg.setLabelText("run motion/acquisition")
|
||||||
|
|||||||
Reference in New Issue
Block a user