SFELPHOTON-1335:rework triggerSync
This commit is contained in:
@@ -45,16 +45,17 @@ class MotionBase:
|
||||
self.meta.update(kwargs)
|
||||
|
||||
def setup_sync(self, crdId=1, prgId=2,verbose=False, timeOfs=0.,timeCor=0.):
|
||||
'''setup the timing synchronization for the motion program
|
||||
kwargs:
|
||||
'''setup the timing synchronization code snipplets for the motion program
|
||||
- sync_run: command to start the motion program
|
||||
- sync_prg: code snipplet at top of the motion program used for synchronization if required
|
||||
- sync_cmd: Deltatau command to excutable for synchronization if required
|
||||
starts the triggerSync on the Deltatau if required
|
||||
|
||||
args in self.meta:
|
||||
sync_mode : default=2
|
||||
0 : no sync at all
|
||||
1 : synchronize start
|
||||
2 : synchronize start and adapt motion speed
|
||||
this function generates the code blocks:
|
||||
self.sync_wait and self.sync_run
|
||||
sync_wait can be put in the program to force a timing sync
|
||||
sync_run are the commands to run the whole program
|
||||
|
||||
sync_flag : default=0
|
||||
bit 0=1 : simulated start trigger
|
||||
@@ -63,7 +64,7 @@ class MotionBase:
|
||||
1 : simulated start and real frame trigger
|
||||
2 : real start and simulated frame trigger
|
||||
3 : simulated start and frame trigger
|
||||
fel_per : FEL-period: time FEL-pulse to FEL-pulse in ms (needed for sync code)
|
||||
fel_per : FEL-period: time FEL-pulse to FEL-pulse in ms (needed for triggerSync executable)
|
||||
'''
|
||||
sync_mode=self.meta['sync_mode']
|
||||
sync_flag=self.meta['sync_flag']
|
||||
@@ -74,62 +75,68 @@ class MotionBase:
|
||||
_log.info({0: 'real start trigger', 1: 'simulated start trigger'}[sync_flag&1])
|
||||
_log.info({0: 'real frame trigger', 2: 'simulated frame trigger'}[sync_flag&2])
|
||||
|
||||
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, crdId=crdId)
|
||||
self.sync_run = f'&{crdId}b{prgId}r'
|
||||
|
||||
if sync_mode==0:
|
||||
try:
|
||||
del self.sync_prg
|
||||
del self.sync_cmd
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
elif sync_mode in(1,2):
|
||||
else: # sync_mode 1,2
|
||||
#frequence jitter 50Hz Swissgrid:
|
||||
#https://www.swissgrid.ch/de/home/operation/grid-data/current-data.html#
|
||||
flag0='Coord[{crdId}].Q[10]'.format(crdId=crdId) if sync_flag&1 else 'Gate3[1].Chan[0].UserFlag'
|
||||
flag1='Coord[{crdId}].Q[11]'.format(crdId=crdId) if sync_flag&2 else 'Gate3[1].Chan[1].UserFlag'
|
||||
if sync_mode==1:
|
||||
prg = f'\n{flag0}=0\n' if sync_flag&1 else ''
|
||||
prg += f'''
|
||||
Coord[{crdId}].Q[0]=-2 // motion program started and armed
|
||||
|
||||
# Gather.Enable=2 is done in the triggerSync executable
|
||||
# triggerSync waits for Coord[1].Q[0]=-3 and then sets Coord[1].DesTimeBase to continue motion
|
||||
# triggerSync set Coord[1].DesTimeBase to the servoPeriod to match last interval of frame triggers if sync_mode==1
|
||||
# triggerSync modifies Coord[1].DesTimeBase if sync_mode==2
|
||||
|
||||
if sync_mode==1: # triggerSync:trigsync_func not called, therefore need to make own start synchronization
|
||||
flag0=f'Coord[{crdId}].Q[10]' if sync_flag&1 else 'Gate3[1].Chan[0].UserFlag'
|
||||
flag1=f'Coord[{crdId}].Q[11]' if sync_flag&2 else 'Gate3[1].Chan[1].UserFlag'
|
||||
prg= f'''
|
||||
Coord[{crdId}].TimeBaseSlew=1 //1E-4 is default
|
||||
Coord[{crdId}].DesTimeBase=0
|
||||
Coord[{crdId}].Q[0]=-3 // motion program waiting at start position
|
||||
Coord[{crdId}].Q[0]=-2 // motion program started and armed
|
||||
while({flag0}==0){{}}
|
||||
Coord[{crdId}].Q[0]=-1
|
||||
Gather.Enable=2
|
||||
while({flag1}==0){{}}
|
||||
Coord[1].DesTimeBase=Sys.ServoPeriod
|
||||
Coord[{crdId}].Q[0]=0 //
|
||||
'''
|
||||
else:
|
||||
else: #sync_mode==2: triggerSync:trigsync_func called
|
||||
prg = f'''
|
||||
//Gather.Enable=2 is done in the triggerSync program
|
||||
Coord[1].TimeBaseSlew=1 //1E-4 is default
|
||||
Coord[1].DesTimeBase=0
|
||||
Coord[1].Q[0]=-3 //motion program started and waits. Arm(-2) is done in triggerSync program
|
||||
Coord[{crdId}].TimeBaseSlew=1 //1E-4 is default
|
||||
Coord[{crdId}].DesTimeBase=0
|
||||
Coord[{crdId}].Q[0]=-3 //motion program waiting at start position
|
||||
'''
|
||||
|
||||
self.sync_prg = prg
|
||||
#download and start triggerSync code
|
||||
comm=self.comm
|
||||
if comm is None:
|
||||
_log.info('simulated');return
|
||||
|
||||
mode=0 #mode to pass to triggerSync program
|
||||
mode=0 #for triggerSync
|
||||
# mode: (triggerSync executable)
|
||||
# bit0:1: sync mode
|
||||
# bit1:2: simulate start trigger
|
||||
# bit2:4: simulate frame trigger
|
||||
# bit3:8: verbose
|
||||
if sync_mode==2:mode+=1 #synchronize
|
||||
mode+=sync_flag*2 #simulated or real triggers
|
||||
if verbose: mode+=8
|
||||
if sync_mode==2 or mode&4:
|
||||
sftp = comm.sftp
|
||||
dst = '/tmp/triggerSync'
|
||||
src = os.path.abspath(os.path.join(os.path.dirname(__file__), 'triggerSync'))
|
||||
sftp.put(src, dst)
|
||||
sftp.chmod(dst, 0o755)
|
||||
cmd = 'LD_LIBRARY_PATH=/opt/ppmac/libppmac/ ' + dst
|
||||
#cmd+=' %d %g %g %g'%(mode,pt2pt_time,timeOfs,timeCor)
|
||||
cmd+=' %d %g %g'%(mode,fel_per+timeCor,timeOfs)
|
||||
self.cmdSync = cmd
|
||||
print ('starting '+cmd)
|
||||
self.syncShell=comm.shell_channel(cmd)
|
||||
#syncChan=sc=comm._client.exec_command(cmd) #this is less simple to communicate with
|
||||
sftp = comm.sftp
|
||||
dst = '/tmp/triggerSync'
|
||||
src = os.path.abspath(os.path.join(os.path.dirname(__file__), 'triggerSync'))
|
||||
sftp.put(src, dst)
|
||||
sftp.chmod(dst, 0o755)
|
||||
cmd = 'LD_LIBRARY_PATH=/opt/ppmac/libppmac/ ' + dst
|
||||
#cmd+=' %d %g %g %g'%(mode,pt2pt_time,timeOfs,timeCor)
|
||||
cmd+=' %d %g %g'%(mode,fel_per+timeCor,timeOfs)
|
||||
self.sync_cmd = cmd
|
||||
|
||||
def homing(self):
|
||||
if self.comm is None: return
|
||||
@@ -143,21 +150,30 @@ Coord[1].Q[0]=-3 //motion program started and waits. Arm(-2) is done in triggerS
|
||||
time.sleep(1)
|
||||
if gpascii.get_variable('Motor[1].HomeComplete', int)==1:
|
||||
break
|
||||
print('homing done')
|
||||
|
||||
|
||||
|
||||
_log.info('homing done')
|
||||
|
||||
def run(self, crdId=1):
|
||||
'runs the code sync_run which has been generated with setup_sync()'
|
||||
try:
|
||||
run=self.sync_run
|
||||
except AttributeError:
|
||||
raise 'Need to call setup sync before'
|
||||
|
||||
comm = self.comm
|
||||
if comm is None: return
|
||||
gpascii = comm.gpascii
|
||||
|
||||
try:
|
||||
cmd=self.sync_run
|
||||
cmd=self.sync_cmd
|
||||
except AttributeError:
|
||||
raise 'Need to call setup sync before'
|
||||
gpascii.send_block(cmd)
|
||||
pass
|
||||
else:
|
||||
if gpascii.get_variable('Gather.Enable', type_=int)==0:
|
||||
raise 'Gather.Enable must be !=0'
|
||||
_log.info('starting '+cmd)
|
||||
self.sync_shell=comm.shell_channel(cmd)
|
||||
#syncChan=sc=comm._client.exec_command(cmd) #this is less simple to communicate with
|
||||
gpascii.send_block(run)
|
||||
|
||||
def wait_armed(self,crdId=1): #wait until motors are at first position
|
||||
sm=self.meta['sync_mode']
|
||||
@@ -168,7 +184,7 @@ Coord[1].Q[0]=-3 //motion program started and waits. Arm(-2) is done in triggerS
|
||||
if comm is None: return
|
||||
gpascii = comm.gpascii
|
||||
while (True):
|
||||
val = gpascii.get_variable('Coord[{crdId}].Q[0]'.format(crdId=crdId), type_=int)
|
||||
val = gpascii.get_variable(f'Coord[{crdId}].Q[0]', type_=int)
|
||||
if val==-2:
|
||||
break
|
||||
time.sleep(.1)
|
||||
@@ -196,9 +212,9 @@ Coord[1].Q[0]=-3 //motion program started and waits. Arm(-2) is done in triggerS
|
||||
if comm is None: return
|
||||
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)
|
||||
#else:
|
||||
# import CaChannel
|
||||
# pvTrigger = CaChannel.CaChannel('SAR-CVME-TIFALL5-EVG0:SoftEvt-EvtCode-SP.VAL')
|
||||
# pvTrigger.searchw()
|
||||
# pvTrigger.putw(254) # ??? does this send a trigger or just set the event code ???
|
||||
|
||||
|
||||
Reference in New Issue
Block a user