diff --git a/python/MXMotion.py b/python/MXMotion.py index 2387c55..a944174 100644 --- a/python/MXMotion.py +++ b/python/MXMotion.py @@ -186,8 +186,8 @@ Coord[1].Q[0]=-3 //motion program started and waits. Arm(-2) is done in triggerS cnt = gpascii.get_variable('Gather.Samples', type_=int) try: cnt*=self.meta['srv_per']*self.meta['acq_per']/self.meta['pt2pt_time'] - except KeyError: - pass + except KeyError as e: + _log.error(f'{e} -> failed') return cnt def trigger(self,wait=.5): diff --git a/python/shapepath.py b/python/shapepath.py index 7907fba..73dc423 100755 --- a/python/shapepath.py +++ b/python/shapepath.py @@ -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