enhance syncronization -> parameters in setup_sync

-> sp.setup_sync(verbose=args.verbose&0x40,timeOfs=0.03,timeCor=0.0005)
- cleanup code
- add motion markers
- add debug data
- rework triggerSync
- BUT nothing should change in Sync
This commit is contained in:
2022-10-04 16:39:13 +02:00
parent 7a968aac96
commit 20c6d690e8
6 changed files with 438 additions and 202 deletions

View File

@@ -7,6 +7,8 @@
# *-----------------------------------------------------------------------*
'''
Coord[1].Q[0] : sync points when using setup_sync(mode=2)
-3: when armed (at start position)
-2: triggerSync waiting for start trigger
0: after setup_sync(mode=2) call
idx: index of position during run
-1: pvt motion is finished
@@ -44,7 +46,7 @@ class MotionBase:
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, timeOfs=0.):
def setup_sync(self, crdId=1, prgId=2,verbose=False, timeOfs=0.,timeCor=0.):
'''setup the timing synchronization for the motion program
kwargs:
sync_mode : default=2
@@ -88,41 +90,43 @@ class MotionBase:
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 = '''
Coord[{crdId}].Q[0]=-2
Coord[{crdId}].TimeBaseSlew=1 //1E-4 is default
Coord[{crdId}].DesTimeBase=0
while({flag0}==0){{}}
Coord[{crdId}].Q[0]=-1
Gather.Enable=2
while({flag1}==0){{}}
Coord[1].DesTimeBase=Sys.ServoPeriod
'''.format(crdId=crdId, flag0=flag0, flag1=flag1)
prg = f'\n{flag0}=0\n' if sync_flag&1 else ''
prg += f'''
Coord[{crdId}].Q[0]=-2 motion program started and armed
Coord[{crdId}].TimeBaseSlew=1 //1E-4 is default
Coord[{crdId}].DesTimeBase=0
while({flag0}==0){{}}
Coord[{crdId}].Q[0]=-1
Gather.Enable=2
while({flag1}==0){{}}
Coord[1].DesTimeBase=Sys.ServoPeriod
'''
else:
prg = '''
//Gather.Enable=2 is done in the sync program
Coord[1].TimeBaseSlew=1 //1E-4 is default
Coord[1].DesTimeBase=0
//Coord[1].Q[0]=-1 is done in the sync program
'''.format(crdId=crdId, flag0=flag0, flag1=flag1)
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
'''
self.sync_prg = prg
#download and start triggerSync code
comm=self.comm
if comm is None: return
arg=0 #argument to pass to triggerSync program
if sync_mode==2:arg+=1 #synchronize
arg+=sync_flag*2 #simulated or real triggers
if verbose: arg+=8
if sync_mode==2 or arg&4:
mode=0 #mode to pass to triggerSync program
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+=' %g %g %d'%(pt2pt_time,timeOfs,arg)
#cmd+=' %d %g %g %g'%(mode,pt2pt_time,timeOfs,timeCor)
cmd+=' %d %g %g'%(mode,pt2pt_time+timeCor,timeOfs)
self.cmdSync = cmd
print ('starting '+cmd)
self.syncShell=comm.shell_channel(cmd)