SFELPHOTON-1128: debug stup-and-go motion(4)

This commit is contained in:
2024-05-24 15:22:02 +02:00
parent a0352036a0
commit 98b1d068b9
2 changed files with 28 additions and 31 deletions

View File

@@ -65,8 +65,13 @@ import matplotlib as mpl
import matplotlib.pyplot as plt
import subprocess as sprc
sys.path.insert(0,os.path.expanduser('~/Documents/prj/SwissFEL/PBTools/'))
sys.path.insert(0,os.path.expanduser('/tmp/zamofing_t/PBTools/'))
import socket
hostname=socket.gethostname()
if hostname=='ganymede':
sys.path.insert(0, os.path.expanduser('~/Documents/prj/SwissFEL/PBTools/'))
else:
sys.path.insert(0, os.path.expanduser('/sf/cristallina/applications/mx/zamofing_t/PBTools/'))
from pbtools.misc.pp_comm import PPComm
from pbtools.misc.gather import Gather
from MXMotion import MotionBase
@@ -711,8 +716,9 @@ class ShapePath(MotionBase):
common kwargs plus:
trf : transformation that will be done on 'grid points'
grid: grid parameters: {orig:(0,0),pitch(10,10),cnt:(10,10),mode:0}
tmove: time to move in ms
tmove: time to move in ms (move start on FEL-trigger
twait: time to wait in ms
(tmove+twait will be rounded to a multiple of fel_per)
'''
#scan=0 # snake motion X fast, Y slow
scan=1 # snake motion Y fast, X slow (default)
@@ -721,14 +727,15 @@ class ShapePath(MotionBase):
verb=self.verbose
comm=self.comm
meta=self.meta
try:
self.sync_prg
except AttributeError:
_log.warning('missing motion sync code!')
# this uses Coord[1].Tm and limits with MaxSpeed
if mode in (1,3,4,5): #### pvt motion
pt2pt_time=self.meta['fel_per']
ts=self.meta['srv_per']
if mode!=5:
pt2pt_time=meta['pt2pt_time']=meta['fel_per']
scale=kwargs.get('scale', 1.)
cnt=kwargs.get('cnt', 1) # move path multiple times
dwell=kwargs.get('dwell', 100) # wait time at end of motion
@@ -878,10 +885,16 @@ class ShapePath(MotionBase):
raise Exception('scan=0 not supported')
pass
else: # scan=1
if self.meta['sync_mode']==2:
if meta['sync_mode']==2:
_log.error('sync_mode=2 not allowed for stop-and-go motion !')
pt2tp_felpulse=kwargs['pt2tp_felpulse']
tmove=kwargs['tmove']
twait=kwargs['twait']
fel_per=meta['fel_per']
pt2tp_felpulse=round((tmove+twait)/fel_per) # number of fel-pulses for a whole cycle (tmove+twait)
meta['pt2pt_time']=fel_per*pt2tp_felpulse
twait_=round((tmove+twait)/fel_per)*fel_per-tmove
if twait!=twait_:
_log.warning(f'adjust twait({twait}) to {twait_} to match multiple of fel-cycles')
syncPlc=f'''\
close all buffers
disable plc 2
@@ -1194,33 +1207,14 @@ if __name__=='__main__':
#mode=3;scale=0
mode=5
if mode==5:
tmove=sp.meta['tmove']=20 # time to move in ms
pt2tp_felpulse=15 #numper of fel pulses from point to point move e.g. 15puls at 100Hz=10ms -> 15*10ms=150ms
pt2pt_time=pt2tp_felpulse*sp.meta['fel_per']
else:
pt2pt_time=sp.meta['fel_per']
sp.meta['pt2pt_time']=pt2pt_time
tmove=20 # time to move in ms
twait=130# time to move in ms
try:
num_pts=gp.points.shape[0]
except AttributeError as e:
num_pts=np.array(grid['count'], np.int32).prod()
if sp.comm:
gtMaxLn=int(sp.comm.gpascii.get_variable('Gather.MaxLines')) # 116508
if gtMaxLn==0:
sp.setup_gather(acq_per=1)
gtMaxLn=int(sp.comm.gpascii.get_variable('Gather.MaxLines')) # 116508
ovhdTime=100
acq_per=int(np.ceil((pt2pt_time*num_pts+ovhdTime)/(gtMaxLn*sp.meta['srv_per'])))
if args.verbose&0x01:
_log.info(f'''\
Gather.MaxLines:{gtMaxLn}
Gather.Period: {acq_per}
meta: {sp.meta}
Filename: {fn}.[prg|npz]
''')
sp.setup_gather(acq_per=acq_per)
sp.setup_sync(verbose=args.verbose&0x40,timeOfs=0.03,timeCor=0.0005)
sp.setup_coord_trf() # reset to shape path system
@@ -1231,7 +1225,10 @@ if __name__=='__main__':
elif mode==4:
sp.setup_motion(fnPrg=fn+'.prg',scale=1.,cnt=1,dwell=100,mode=4,grid=grid)
elif mode==5:
sp.setup_motion(fnPrg=fn+'.prg',scale=1.,cnt=1,dwell=100,mode=5,tmove=tmove, pt2tp_felpulse=pt2tp_felpulse, grid=grid)
sp.setup_motion(fnPrg=fn+'.prg',scale=1.,cnt=1,dwell=100,mode=5,tmove=tmove, twait=twait, grid=grid)
if sp.comm:
sp.setup_gather()
sp.homing() #homing if needed
sp.run() #start motion program