This commit is contained in:
2019-01-24 10:59:36 +00:00
parent dab7fb940c
commit 92a88d8463
2 changed files with 175 additions and 190 deletions

View File

@@ -23,7 +23,7 @@ Gather.Enable : 1: after .setup_gather() called
Gather.Samples : number af gathered data samples Gather.Samples : number af gathered data samples
''' '''
import os, sys import os,sys,time
sys.path.insert(0,os.path.expanduser('~/Documents/prj/SwissFEL/PBTools/')) sys.path.insert(0,os.path.expanduser('~/Documents/prj/SwissFEL/PBTools/'))
#import pbtools.misc.pp_comm as pp_comm -> pp_comm.PPComm #import pbtools.misc.pp_comm as pp_comm -> pp_comm.PPComm
from pbtools.misc.pp_comm import PPComm from pbtools.misc.pp_comm import PPComm
@@ -31,86 +31,114 @@ from pbtools.misc.gather import Gather
class MotionBase: class MotionBase:
def __init__(self, comm, gather, verbose): def __init__(self, comm, gather, verbose,**kwargs):
self.comm=comm self.comm=comm
self.gather=gather self.gather=gather
self.verbose=verbose self.verbose=verbose
#ServoPeriod=0.2 #ms, Sys.ServoPeriod is dependent of !common() macro
ServoPeriod=comm.gpascii.servo_period*1000
def setup_sync(self, crdId=1, prgId=2, plcId=2, encId=8, mode=0, **kwargs): self.meta={'srv_per':ServoPeriod,'pt2pt_time':40,'sync_flag':0,'sync_mode':2}
self.meta.update(kwargs)
def setup_sync(self, crdId=1, prgId=2,verbose=False):
'''setup the timing synchronization for the motion program '''setup the timing synchronization for the motion program
mode=0 : no sync at all kwargs:
mode=1 : synchronize start sync_mode : default=2
mode=2 : synchronize start and adapt motion speed 0 : no sync at all
this function generates the code blocks: 1 : synchronize start
self.sync_wait and self.sync_run 2 : synchronize start and adapt motion speed
sync_wait can be put in the program to force a timing sync this function generates the code blocks:
sync_run are the commands to run the whole program self.sync_wait and self.sync_run
flag=0 : real start and frame trigger sync_wait can be put in the program to force a timing sync
flag=1 : simulated start and real frame trigger sync_run are the commands to run the whole program
flag=2 : real start and simulated frame trigger
flag=3 : simulated start and frame trigger sync_flag : default=0
bit 0=1 : simulated start trigger
bit 1=2 : simulated frame trigger
0 : real start and frame trigger
1 : simulated start and real frame trigger
2 : real start and simulated frame trigger
3 : simulated start and frame trigger
pt2pt_time : time point to point (needed sor sync code) pt2pt_time : time point to point (needed sor sync code)
''' '''
if mode==0: sync_mode=self.meta['sync_mode']
sync_flag=self.meta['sync_flag']
pt2pt_time=self.meta['pt2pt_time']
print({0:'no sync at all',1:'sync at start only',2:'sync on each shot'}[sync_mode])
if sync_mode!=0:
print({0: 'real start trigger', 1: 'simulated start trigger'}[sync_flag&1])
print({0: 'real frame trigger', 2: 'simulated frame trigger'}[sync_flag&2])
if sync_mode==0:
try: try:
del self.sync_prg del self.sync_prg
except AttributeError: except AttributeError:
pass pass
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, crdId=crdId) self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, crdId=crdId)
elif mode in(1,2): elif sync_mode in(1,2):
#frequence jitter 50Hz Swissgrid: #frequence jitter 50Hz Swissgrid:
#https://www.swissgrid.ch/de/home/operation/grid-data/current-data.html# #https://www.swissgrid.ch/de/home/operation/grid-data/current-data.html#
flag=kwargs.get('flag',0); flag0='Coord[1].Q[10]' if sync_flag&1 else 'Gate3[1].Chan[0].UserFlag'
pt2pt_time=kwargs.get('pt2pt_time',40); flag1='Coord[1].Q[11]' if sync_flag&2 else 'Gate3[1].Chan[1].UserFlag'
flag0='Coord[1].Q[10]' if flag&1 else 'Gate3[1].Chan[0].UserFlag' if sync_mode==1:
flag1='Coord[1].Q[11]' if flag&2 else 'Gate3[1].Chan[1].UserFlag'
if mode==1:
prg = ''' prg = '''
Coord[1].Q[1]=-2 Coord[1].Q[1]=-2
Coord[1].TimeBaseSlew=1 //1E-4 is default Coord[1].TimeBaseSlew=1 //1E-4 is default
Coord[1].DesTimeBase=0 Coord[1].DesTimeBase=0
while({flag0}==0){{}} while({flag0}==0){{}}
Coord[1].Q[1]=-1 Coord[1].Q[1]=-1
Gather.Enable=2 Gather.Enable=2
while({flag1}==0){{}} while({flag1}==0){{}}
Coord[1].DesTimeBase=Sys.ServoPeriod Coord[1].DesTimeBase=Sys.ServoPeriod
'''.format(plcId=plcId, crdId=crdId, flag0=flag0, flag1=flag1) '''.format(crdId=crdId, flag0=flag0, flag1=flag1)
else: else:
prg = ''' prg = '''
//Gather.Enable=2 is done in the sync program //Gather.Enable=2 is done in the sync program
Coord[1].TimeBaseSlew=1 //1E-4 is default Coord[1].TimeBaseSlew=1 //1E-4 is default
Coord[1].DesTimeBase=0 Coord[1].DesTimeBase=0
Coord[1].Q[1]=-1 Coord[1].Q[1]=-1
'''.format(plcId=plcId, crdId=crdId, flag0=flag0, flag1=flag1) '''.format(crdId=crdId, flag0=flag0, flag1=flag1)
self.sync_prg = prg self.sync_prg = prg
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId) self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, crdId=crdId)
#download and start triggerSync code #download and start triggerSync code
comm=self.comm comm=self.comm
trigMode=0; arg=0 #argument to pass to triggerSync program
if mode==2:trigMode+=1 #synchronize if sync_mode==2:arg+=1 #synchronize
trigMode+=flag*2 #simulated or real triggers arg+=sync_flag*2 #simulated or real triggers
trigMode+=8 # verbose if verbose: arg+=8
if mode==2 or trigMode&4: if sync_mode==2 or arg&4:
sftp = comm.sftp sftp = comm.sftp
dst = '/tmp/triggerSync' dst = '/tmp/triggerSync'
src = os.path.abspath(os.path.join(os.path.dirname(__file__), '../src/triggerSync/triggerSync')) src = os.path.abspath(os.path.join(os.path.dirname(__file__), '../src/triggerSync/triggerSync'))
sftp.put(src, dst) sftp.put(src, dst)
sftp.chmod(dst, 0o755) sftp.chmod(dst, 0o755)
cmd = 'LD_LIBRARY_PATH=/opt/ppmac/libppmac/ ' + dst cmd = 'LD_LIBRARY_PATH=/opt/ppmac/libppmac/ ' + dst
cmd+=' %g %d'%(pt2pt_time,trigMode) cmd+=' %g %d'%(pt2pt_time,arg)
self.cmdSync = cmd self.cmdSync = cmd
print ('starting '+cmd) print ('starting '+cmd)
self.syncShell=comm.shell_channel(cmd) self.syncShell=comm.shell_channel(cmd)
#self.syncChan=sc=comm._client.exec_command(cmd) #syncChan=sc=comm._client.exec_command(cmd) #this is less simple to communicate with
#ch=sc[1].channel
#ch.settimeout(1) def homing(self):
#sc[1].channel.setblocking(False) if self.comm is None: return
#sc[1].read(100) comm = self.comm
if flag&1: gpascii = comm.gpascii
print('set Coord[1].Q[10]=1 to start motion') #Motor[1].HomeComplete
if gpascii.get_variable('Motor[1].HomeComplete', int)==0:
gpascii.send_block('enable plc 1')
while(True):
sys.stdout.write('.');sys.stdout.flush()
time.sleep(1)
if gpascii.get_variable('Motor[1].HomeComplete', int)==1:
break
print('homing done')
def run(self): def run(self):
'runs the code sync_run which has been generated with setup_sync()' 'runs the code sync_run which has been generated with setup_sync()'
@@ -122,4 +150,18 @@ class MotionBase:
raise 'Need to call setup sync before' raise 'Need to call setup sync before'
gpascii.send_block(cmd) gpascii.send_block(cmd)
def trigger(self,wait=.5):
if self.meta['sync_mode']==0:
return # no trigger at all
time.sleep(wait)
if self.meta['sync_flag']&1:
comm = self.comm
gpascii = comm.gpascii
gpascii.send_block('Coord[1].Q[10]=1')
else:
import CaChannel
pvTrigger = CaChannel.CaChannel('SAR-CVME-TIFALL5-EVG0:SoftEvt-EvtCode-SP.VAL')
pvTrigger.searchw()
pvTrigger.putw(254)

View File

@@ -15,6 +15,7 @@ verbose bits:
4 upload progress 4 upload progress
8 plot gather path 8 plot gather path
16 plot pvt trajectory (before motion) 16 plot pvt trajectory (before motion)
32 print sync details
Gather motor order Gather motor order
@@ -40,7 +41,7 @@ Enc 7: Interferometer X
''' '''
from __future__ import print_function from __future__ import print_function
import os, sys, time import os, sys
import numpy as np import numpy as np
import matplotlib as mpl import matplotlib as mpl
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
@@ -62,9 +63,9 @@ def gen_pvt(p,v, p2pt, ts):
!!! it is assumed, that the time intervals are constant !!! !!! it is assumed, that the time intervals are constant !!!
''' '''
n=int(p2pt/ts) n=int(p2pt/ts)
pvt=np.ndarray((p.shape[0]-1)*n)*0 pvt=np.ndarray((p.shape[0]-1)*n)
tt=np.arange(0,p2pt,ts) tt=np.arange(0,p2pt,ts)[:n]
for i in range(p.shape[0]-1): for i in range(p.shape[0]-1):
d=p[i] d=p[i]
c=v[i] c=v[i]
@@ -75,21 +76,20 @@ def gen_pvt(p,v, p2pt, ts):
return pvt return pvt
class DebugPlot: class DebugPlot:
def __init__(self,spObj=None,fn=None): def __init__(self,obj=None):
if spObj is not None: if obj is None:
self.set_data(spObj)
elif fn is not None:
self.load_npz(fn)
else:
self.load_npz() self.load_npz()
elif type(obj)==str:
self.load_npz(obj)
else:
self.set_data(obj)
@staticmethod
def plot_gen_pvt(self,pv): def plot_gen_pvt(self,pv):
# pv is an array of posx posy velx vely # pv is an array of posx posy velx vely
#pv=pv[5:10,:] #pv=pv[5:10,:]
#pv=pv[5:-4,:] #pv=pv[5:-4,:]
p2pt=self.meta['pt2pt_time'] # ms step between samples p2pt=self.meta['pt2pt_time'] # ms step between samples
ts=self.meta['timebase'] # sampling time in ms ts=self.meta['srv_per'] # sampling time in ms
n=int(p2pt/ts) # servo cycle between samples n=int(p2pt/ts) # servo cycle between samples
k=pv.shape[0] # number of unique samples k=pv.shape[0] # number of unique samples
t=np.arange(0, p2pt*k, p2pt) # time array of trajectory t=np.arange(0, p2pt*k, p2pt) # time array of trajectory
@@ -183,24 +183,27 @@ class DebugPlot:
l2=l[:,0]**2+l[:,1]**2 l2=l[:,0]**2+l[:,1]**2
try: try:
ofs=l2.argmin() ofs=l2.argmin()
except ValueError: except ValueError as e:
break#print(l2[ofs]) raise e #should never happen
break
idx+=ofs idx+=ofs
idxInPos.append(idx) idxInPos.append(idx)
idxInPos = np.array(idxInPos) idxInPos = np.array(idxInPos)
#select only triggers on a target point #select only triggers on a target point
i=np.abs(idxTrigger - idxInPos[1]).argmin() i=max(0,np.abs(idxTrigger-idxInPos[1]).argmin()-1)
j=np.abs(idxTrigger - idxInPos[-2]).argmin()+1 j=i+idxInPos.shape[0]
self.idxTrigger=idxTrigger[i:j] idxTrigger=idxTrigger[i:j]
self.idxInPos=idxInPos[1:-1] self.idxInPos=idxInPos
self.idxTrigger=idxTrigger
def plot_trigger_jitter(self): def plot_trigger_jitter(self):
self.analyze_trigger() self.analyze_trigger()
ts=self.meta['timebase'] ts=self.meta['srv_per']*self.meta['acq_per']
idxTrigger=self.idxTrigger idxTrigger=self.idxTrigger
idxInPos=self.idxInPos idxInPos=self.idxInPos
jitter = idxTrigger-idxInPos n=min(idxTrigger.shape[0],idxInPos.shape[0])-1
jitter = idxTrigger[1:n]-idxInPos[1:n]
pts=self.pts # X,Y array pts=self.pts # X,Y array
rec=self.rec # yA,xA,yD,xD,trig rec=self.rec # yA,xA,yD,xD,trig
@@ -213,14 +216,15 @@ class DebugPlot:
rec = self.rec # yA,xA,yD,xD,trig rec = self.rec # yA,xA,yD,xD,trig
ts=self.meta['timebase'] ts=self.meta['srv_per']*self.meta['acq_per']
fig = plt.figure('shot position error') fig = plt.figure('shot position error')
ax = fig.add_subplot(1, 1, 1) ax = fig.add_subplot(1, 1, 1)
#errx = rec[idxTrigger, 1] - rec[idxInPos, 3] #errx = rec[idxTrigger, 1] - rec[idxInPos, 3]
#erry = rec[idxTrigger, 0] - rec[idxInPos, 2] #erry = rec[idxTrigger, 0] - rec[idxInPos, 2]
errx = rec[idxTrigger, 1] - pts[1:-1, 0] n=idxTrigger.shape[0]
erry = rec[idxTrigger, 0] - pts[1:-1, 1] errx = rec[idxTrigger, 1] - pts[:n, 0]
erry = rec[idxTrigger, 0] - pts[:n, 1]
err = np.sqrt(errx ** 2 + erry ** 2) err = np.sqrt(errx ** 2 + erry ** 2)
hl = [] hl = []
@@ -239,7 +243,7 @@ class DebugPlot:
def plot_pos_error(self): def plot_pos_error(self):
rec = self.rec # yA,xA,yD,xD,trig rec = self.rec # yA,xA,yD,xD,trig
ts=self.meta['timebase'] ts=self.meta['srv_per']*self.meta['acq_per']
fig = plt.figure('position error') fig = plt.figure('position error')
ax = fig.add_subplot(1, 1, 1) ax = fig.add_subplot(1, 1, 1)
@@ -340,7 +344,7 @@ class DebugPlot:
pts=self.pts # X,Y array pts=self.pts # X,Y array
rec = self.rec # yA,xA,yD,xD,trig rec = self.rec # yA,xA,yD,xD,trig
strMot=('FY.act','FX.act','FY.des','FX.des') strMot=('FY.act','FX.act','FY.des','FX.des')
ts=meta['timebase']*1E-3 #0.2ms ts=self.meta['srv_per']*self.meta['acq_per']*1E-3 #0.2ms
num=rec.shape[0] num=rec.shape[0]
#rngMin=int(.01/ts);rngMax=int(num-1.001/ts) #0.01s from start 1.01 sec before end #rngMin=int(.01/ts);rngMax=int(num-1.001/ts) #0.01s from start 1.01 sec before end
rngMin=int(.01/ts);rngMax=rngMin+int((pts.shape[0]-2)*.01/ts) rngMin=int(.01/ts);rngMax=rngMin+int((pts.shape[0]-2)*.01/ts)
@@ -417,14 +421,15 @@ class DebugPlot:
def set_data(self,spObj): def set_data(self,spObj):
self.meta=spObj.meta self.meta=spObj.meta
self.pts=spObj.points self.pts=spObj.points
self.rec=spObj.rec try: self.rec=spObj.rec
try: pvt=self.pvt except AttributeError: pass
try: self.pvt=spObj.pvt
except AttributeError: pass except AttributeError: pass
class ShapePath(MotionBase): class ShapePath(MotionBase):
def __init__(self,comm, gather, verbose): def __init__(self,comm, gather, verbose,**kwargs):
MotionBase.__init__(self,comm, gather, verbose) MotionBase.__init__(self,comm, gather, verbose, **kwargs)
def gen_swissmx_points(self,flipx=False,flipy=False,ofs=(0,0),width=1000): def gen_swissmx_points(self,flipx=False,flipy=False,ofs=(0,0),width=1000):
'generathe a path that writes swissfel' 'generathe a path that writes swissfel'
@@ -607,7 +612,7 @@ class ShapePath(MotionBase):
self.ptsCorr=ptsCorr self.ptsCorr=ptsCorr
print(ptsCorr) print(ptsCorr)
def setup_gather(self,acq_per=1,sim=False): def setup_gather(self,acq_per=1):
''' '''
setup the channels to gather setup the channels to gather
kwargs: kwargs:
@@ -617,16 +622,14 @@ class ShapePath(MotionBase):
comm=self.comm comm=self.comm
gt=self.gather gt=self.gather
gt.set_phasemode(False) gt.set_phasemode(False)
if sim: if self.meta['sync_flag']&2:
address=("Motor[1].ActPos","Motor[2].ActPos","Motor[1].DesPos","Motor[2].DesPos","Coord[1].Q[11]") address=("Motor[1].ActPos","Motor[2].ActPos","Motor[1].DesPos","Motor[2].DesPos","Coord[1].Q[11]")
else: else:
address=("Motor[1].ActPos","Motor[2].ActPos","Motor[1].DesPos","Motor[2].DesPos","Gate3[1].Chan[1].UserFlag") address=("Motor[1].ActPos","Motor[2].ActPos","Motor[1].DesPos","Motor[2].DesPos","Gate3[1].Chan[1].UserFlag")
gt.set_address(*address) gt.set_address(*address)
gt.set_property(MaxSamples=1000000, Period=acq_per) gt.set_property(MaxSamples=1000000, Period=acq_per)
ServoPeriod= .2 #0.2ms #Sys.ServoPeriod is dependent of !common() macro self.meta.update({'acq_per':acq_per,'address':address})
#ServoPeriod=comm.gpascii.servo_period
self.meta = {'timebase': ServoPeriod*acq_per,'address':address}
def setup_coord_trf(self): def setup_coord_trf(self):
if self.comm is None: return if self.comm is None: return
@@ -666,9 +669,9 @@ class ShapePath(MotionBase):
if comm is not None: if comm is not None:
gpascii=comm.gpascii gpascii=comm.gpascii
# this uses Coord[1].Tm and limits with MaxSpeed # this uses Coord[1].Tm and limits with MaxSpeed
elif mode in (1,3): #### pvt motion if mode in (1,3): #### pvt motion
pt2pt_time=self.meta['pt2pt_time'] pt2pt_time=self.meta['pt2pt_time']
ts=self.meta['timebase'] ts=self.meta['srv_per']
scale=kwargs.get('scale', 1.) scale=kwargs.get('scale', 1.)
cnt=kwargs.get('cnt', 1) # move path multiple times cnt=kwargs.get('cnt', 1) # move path multiple times
dwell=kwargs.get('dwell', 100) # synchronization mark all n points dwell=kwargs.get('dwell', 100) # synchronization mark all n points
@@ -707,7 +710,7 @@ class ShapePath(MotionBase):
pv[ 1:-1,(2,3)] = v[:n]*scale pv[ 1:-1,(2,3)] = v[:n]*scale
verb=self.verbose verb=self.verbose
if verb&16: if verb&16:
self.pvt=DebugPlot(self).plot_gen_pvt(pv) dp=DebugPlot(self);self.pvt=dp.plot_gen_pvt(pv)
plt.show() plt.show()
pv[1:-1, (2, 3)]*=CoordFeedTime #scaling for Deltatau pv[1:-1, (2, 3)]*=CoordFeedTime #scaling for Deltatau
@@ -784,23 +787,47 @@ if __name__=='__main__':
# '%(levelname)-8s %(message)s'), # '%(levelname)-8s %(message)s'),
# datefmt='%m-%d %H:%M', # datefmt='%m-%d %H:%M',
# ) # )
def trigger(wait=.5):
import CaChannel def unique_filename(fnBase):
time.sleep(wait) i = 0;
pvTrigger = CaChannel.CaChannel('SAR-CVME-TIFALL5-EVG0:SoftEvt-EvtCode-SP.VAL') while (True):
pvTrigger.searchw() fn=fnBase+('%0.3d'%i)
pvTrigger.putw(254) i+=1
if not os.path.exists(fn+'.npz'):
print('save to '+fn+'.*')
break
return fn
def run_test(args): def run_test(args):
dp=DebugPlot();dp.plot_gather();return #dp=DebugPlot();dp.plot_gather();return
#args.host=None #args.host=None
if args.host is None: if args.host is None:
comm=gather=None comm=gather=None
else: else:
comm = PPComm(host=args.host) comm = PPComm(host=args.host)
gather = Gather(comm) gather = Gather(comm)
sp = ShapePath(comm, gather, args.verbose) #real start and frame trigger with sync
#sp = ShapePath(comm, gather, args.verbose)
# direct start
#sp = ShapePath(comm, gather, args.verbose,sync_mode=0)
#simulated start and frame trigger no sync
#sp = ShapePath(comm, gather, args.verbose,sync_mode=1,sync_flag=3)
#simulated start and frame trigger with sync
#sp = ShapePath(comm, gather, args.verbose,sync_mode=2,sync_flag=3)
#simulated start real frame trigger no sync
#sp = ShapePath(comm, gather, args.verbose,sync_mode=1,sync_flag=1)
#simulated start real frame trigger with sync
sp = ShapePath(comm, gather, args.verbose,sync_mode=2,sync_flag=1)
fn='/tmp/shapepath'
#fn =unique_filename('ShapePathAnalyser/records/19_01_24/spiral')
# Gather.MaxLines=116508 # Gather.MaxLines=116508
# ts=0.2ms # ts=0.2ms
# max_num_points=(MaxLines*ts-1000ms)/(+acq_per*pt2pt_time*ts) # max_num_points=(MaxLines*ts-1000ms)/(+acq_per*pt2pt_time*ts)
@@ -814,128 +841,44 @@ if __name__=='__main__':
# 10ms 3 6860 # 10ms 3 6860
# 10ms 4 9180 # 10ms 4 9180
#sp.gen_swissmx_points(width=1000,ofs=(-500,0)) #xy=False
#sp.gen_swissfel_points(width=1000,ofs=(-500,0)) #sp.gen_grid_points(w=6,h=6,pitch=100,rnd=0,ofs=(0,0));sp.sort_points(False);
#fn='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/PBMotionAnalyzer/records/mode1'
#fn='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/record/grid_delay_0002'
# /home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/record/chip000_sortedXXXX_9x9'
#fn='/sf/bernina/data/p17592/res/20181203/imprints/chip000_preloc_min10um_sortedX_refs_goaround/chip000_sortedY_9x9.npz'
#fn='PBMotionAnalyzer/records/rand50um_25Hz'
#sp.setup_coord_trf()
#sp.points=np.zeros((2,2))
sp.meta={'timebase':.2,'pt2pt_time':40}
#sp.gather_upload(fnRec=fn+'.npz')
#Tools.plot_gather(sp)
#return
xy=False
#sp.gen_rand_points(n=14, scale=1000);sp.sort_points(xy=xy)
#print(sp.points[:,0])
#sp.gen_swissmx_points(width=1000, ofs=(-500, 0));
#sp.gen_spiral_points(rStart=100,rInc=10,numSeg=4,numCir=60, ofs=(0, 0))
sp.gen_spiral_points(rStart=100,rInc=130,numSeg=4,numCir=2, ofs=(0, 0))
#sp.gen_spiral_points(rStart=100,rInc=20,numSeg=8,numCir=32, ofs=(0, 0))
#sp.gen_closed_shifted()
#sp.gen_grid_points(w=10,h=10,pitch=100,rnd=0,ofs=(0,0));sp.sort_points(False);
#sp.gen_grid_points(w=1,h=10,pitch=100,rnd=0,ofs=(0,0))
#sp.setup_motion(fnPrg=fn + '.prg', mode=1, scale=0)
#sp.setup_motion(fnPrg=fn + '.prg', mode=1, scale=1)
#works: direct start
#sp.setup_gather(acq_per=1)
#sp.setup_sync(mode=0)
#works: simulated start and frame trigger no sync
#sp.setup_gather(acq_per=1,sim=True)
#sp.setup_sync(mode=1,flag=3)
#works: simulated start and frame trigger with sync
#sp.setup_gather(acq_per=1,sim=True)
#sp.setup_sync(mode=2,flag=3)
#works: simulated start real frame trigger no sync
#sp.setup_gather(acq_per=1)
#sp.setup_sync(mode=1,flag=1)
#works: simulated start real frame trigger with sync
sp.setup_gather(acq_per=1)
sp.setup_sync(mode=2,flag=1)
sp.setup_coord_trf() # reset to shape path system
sp.setup_motion(fnPrg=fn + '.prg', mode=3, scale=1,dwell=10)
#sp.setup_motion(fnPrg=fn + '.prg', mode=1, scale=0,dwell=10)
sp.run()
sp.gather_upload(fnRec=fn+'.npz')
dp=DebugPlot(obj=sp);dp.plot_gather(mode=11)
exit(0)
# fn='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/data/'+time.strftime('%y-%m-%d-%H_%M_%S')
#>>>point source and sorting<<<
#sp.points = np.array([[100,523],[635,632],[756,213]])
#sp.points = np.array([[0, 0],[100, 0],[200, 0],[300, 0],[400, 0],[400, 100],[300, 100],[200, 100],[100, 100],[0, 100],[10, 200],[100, 200],[200, 200],[300, 200],[400, 200],[410, 300],[300, 300],[200, 300],[100, 300],[0, 300],[0, 400],[100, 400],[200, 400],[300, 400],[400, 400]])
#sp.gen_rand_points(n=107, scale=1000);sp.sort_points(xy=xy)
#sp.gen_rand_points(n=107, scale=1000);sp.sort_points(xy=xy)
#fh=np.load('/sf/bernina/data/p17592/res/20181203/imprints/chip000_preloc_min10um_sortedX_refs_goaround/chip000_preloc_min10um_sortedX_refs_goaround_0529.npz')
#sp.points=fh['pts']
sp.gen_grid_points(w=6,h=6,pitch=100,rnd=0,ofs=(0,0));sp.sort_points(False);
sp.gen_closed_shifted()
sp.points=sp.points-+sp.points[0,:]+(-967,1446)
#1412.33 -2862.37
#1446.62 -967.7128125
#sp.plot_points(sp.points);plt.show()
#sp.gen_grid_points(w=100,h=100,pitch=10,rnd=.2) #sp.gen_grid_points(w=100,h=100,pitch=10,rnd=.2)
#sp.gen_swissfel_points(width=1000,ofs=(-500,0));sp.sort_points(xy=xy) #sp.gen_swissfel_points(width=1000,ofs=(-500,0));sp.sort_points(xy=xy)
#sp.gen_grid_points(w=10,h=10,pitch=50,rnd=.2) #sp.gen_grid_points(w=10,h=10,pitch=50,rnd=.2)
#sp.gen_grid_points(w=100,h=100,pitch=50,rnd=.2) #sp.gen_grid_points(w=100,h=100,pitch=50,rnd=.2)
#sp.gen_closed_shifted()
#sp.gen_swissmx_points(width=1000,ofs=(-500,0))
#sp.gen_swissfel_points(width=1000,ofs=(-500,0))
#sp.gen_rand_points(n=14, scale=1000);sp.sort_points(xy=xy)
#sp.gen_swissmx_points(width=1000, ofs=(-500, 0));
#sp.gen_spiral_points(rStart=100,rInc=10,numSeg=4,numCir=60, ofs=(0, 0))
#sp.gen_spiral_points(rStart=100,rInc=130,numSeg=4,numCir=2, ofs=(0, 0))
#sp.gen_grid_points(w=10,h=10,pitch=100,rnd=0,ofs=(0,0));sp.sort_points(False);
#sp.gen_grid_points(w=1,h=10,pitch=100,rnd=0,ofs=(0,0))
sp.gen_spiral_points(rStart=100,rInc=20,numSeg=8,numCir=32, ofs=(0, 0))
#sp.gen_closed_shifted()
sp.setup_gather(acq_per=1)
sp.setup_sync(verbose=args.verbose&32)
#sp.setup_gather(acq_per=1) #Gather.MaxLines=116508 580pts
sp.setup_gather(acq_per=2)
#setup_sync(self, crdId=1, prgId=2, plcId=2, mode=0, **kwargs):
#sp.setup_sync() #no sync at all
#sp.setup_sync(mode=1) #sync with timing system (PROG)
sp.setup_sync(mode=2) #sync with timing system and PLC to sync speed (PROG)
sp.setup_coord_trf() # reset to shape path system sp.setup_coord_trf() # reset to shape path system
sp.setup_motion(fnPrg=fn + '.prg', mode=1) sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1,dwell=10)
#sp.gen_grid_points(w=2,h=2,pitch=50,rnd=.2);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,acq_per=1) #sp.setup_motion(fnPrg=fn + '.prg', mode=1, scale=1,dwell=10)
#sp.gen_swissmx_points(width=1000,ofs=(-500,0));sp.setup_motion(fnPrg=fn+'.prg',mode=1,acq_per=1) #sp.setup_motion(fnPrg=fn + '.prg', mode=1, scale=0,dwell=10)
sp.homing()
sp.run()
sp.trigger(0.5) #send a start trigger (if needed) ater given time
sp.gather_upload(fnRec=fn+'.npz')
dp=DebugPlot(sp);dp.plot_gather(mode=11)
#sp.gen_grid_points(w=30,h=30,pitch=50,rnd=.2);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1) #sp.plot_points(sp.points);plt.show()
#sp.gen_grid_points(w=200,h=200,pitch=50,rnd=.2);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1)
#sp.gen_grid_points(w=2,h=20,pitch=50,rnd=0);sp.setup_motion(fnPrg=fn+'.prg',mode=1,acq_per=1)
#sp.gen_rand_points(n=500, scale=1000);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,acq_per=1)
#sp.gen_grid_points(w=30,h=30,pitch=50,rnd=0.2);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,)
#sp.gen_rand_points(n=400, scale=1000);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1)
#sp.gen_swissmx_points(width=2000,flipx=True,flipy=True,ofs=(1014,-281));sp.setup_motion(fnPrg=fn+'.prg',mode=1)
#sp.gen_grid_points(w=20,h=20,pitch=20,rnd=0,ofs=(-464,1754));sp.sort_points(True);sp.setup_motion(fnPrg=fn+'.prg',mode=1)
#sp.gen_grid_points(w=20,h=20,pitch=20,rnd=0,ofs=(-160,3700));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1)
#sp.gen_grid_points(w=5,h=5,pitch=100,rnd=0,ofs=(-1590,-1070));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1)
#sp.gen_grid_points(w=5,h=5,pitch=100,rnd=0,ofs=(-1580,-1070));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1)
#sp.gen_grid_points(w=5,h=5,pitch=100,rnd=0,ofs=(-1580,-1060));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1)
#sp.gen_grid_points(w=5,h=5,pitch=100,rnd=0,ofs=(-1590,-1060));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1)
#>>>setup gather and sync<<<
#sp.setup_gather()
#sp.setup_sync()
#>>>setup motion program<<<
#sp.setup_motion(fnPrg=fn+'.prg',mode=1)
#>>>run gather and plot trajectory<<< #>>>run gather and plot trajectory<<<
#return #return
sp.run()
#trigger(0.5)
sp.gather_upload(fnRec=fn+'.npz')
Tools.plot_gather(sp,mode=11)
from optparse import OptionParser, IndentedHelpFormatter from optparse import OptionParser, IndentedHelpFormatter