first running sync with rt-C-code

This commit is contained in:
2019-01-22 14:41:16 +00:00
parent 7c2a2c5fe6
commit 66e2d038ba
5 changed files with 217 additions and 136 deletions

View File

@@ -45,6 +45,11 @@ class MotionBase:
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
flag=0 : real start and frame trigger
flag=1 : simulated start and real frame trigger
flag=2 : real start and simulated frame trigger
flag=3 : simulated start and frame trigger
pt2pt_time : time point to point (needed sor sync code)
'''
if mode==0:
try:
@@ -53,15 +58,15 @@ class MotionBase:
pass
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, crdId=crdId)
elif mode==1:
# code block to insert in the program
# - waits untis <flag> is false
# - waits raising edge of <flag> and the sets DesTimeBase=ServoPeriod
# flag ='PowerBrick[0].GpioData[0].0.1==1'
flag0='Gate3[1].Chan[0].UserFlag'
flag1='Gate3[1].Chan[1].UserFlag'
flag0='P0';flag1='P1'
prg = '''
elif mode in(1,2):
#frequence jitter 50Hz Swissgrid:
#https://www.swissgrid.ch/de/home/operation/grid-data/current-data.html#
flag=kwargs.get('flag',0);
pt2pt_time=kwargs.get('pt2pt_time',40);
flag0='Coord[1].Q[10]' if flag&1 else 'Gate3[1].Chan[0].UserFlag'
flag1='Coord[1].Q[11]' if flag&2 else 'Gate3[1].Chan[1].UserFlag'
if mode==1:
prg = '''
Coord[1].Q[1]=-2
Coord[1].TimeBaseSlew=1 //1E-4 is default
Coord[1].DesTimeBase=0
@@ -71,36 +76,41 @@ class MotionBase:
while({flag1}==0){{}}
Coord[1].DesTimeBase=Sys.ServoPeriod
'''.format(plcId=plcId, crdId=crdId, flag0=flag0, flag1=flag1)
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[1]=-1
'''.format(plcId=plcId, crdId=crdId, flag0=flag0, flag1=flag1)
self.sync_prg = prg
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
elif mode==2:
#frequence jitter 50Hz Swissgrid:
#https://www.swissgrid.ch/de/home/operation/grid-data/current-data.html#
flag0='Gate3[1].Chan[0].UserFlag'
flag1='Gate3[1].Chan[1].UserFlag'
flag0='P0';flag1='P1'
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[1]=-1
'''.format(plcId=plcId, crdId=crdId, flag0=flag0, flag1=flag1)
self.sync_prg=prg
self.sync_run='&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
#download and start triggerSync code
comm=self.comm
sftp=comm.sftp
dst='/tmp/triggerSync'
src=os.path.abspath(os.path.join(os.path.dirname(__file__), '../src/triggerSync/triggerSync'))
sftp.put(src, dst)
sftp.chmod(dst, 0o755)
self.cmdSync=cmd='LD_LIBRARY_PATH=/opt/ppmac/libppmac/ '+dst
#self.syncShell=comm.shell_channel(cmd)
self.syncChan=sc=comm._client.exec_command(cmd)
#ch=sc[1].channel
#ch.settimeout(1)
print ('starting '+cmd)
trigMode=0;
if mode==2:trigMode+=1 #synchronize
trigMode+=flag*2 #simulated or real triggers
trigMode+=8 # verbose
if mode==2 or trigMode&4:
sftp = comm.sftp
dst = '/tmp/triggerSync'
src = os.path.abspath(os.path.join(os.path.dirname(__file__), '../src/triggerSync/triggerSync'))
sftp.put(src, dst)
sftp.chmod(dst, 0o755)
cmd = 'LD_LIBRARY_PATH=/opt/ppmac/libppmac/ ' + dst
cmd+=' %g %d'%(pt2pt_time,trigMode)
self.cmdSync = cmd
print ('starting '+cmd)
self.syncShell=comm.shell_channel(cmd)
#self.syncChan=sc=comm._client.exec_command(cmd)
#ch=sc[1].channel
#ch.settimeout(1)
#sc[1].channel.setblocking(False)
#sc[1].read(100)
if flag&1:
print('set Coord[1].Q[10]=1 to start motion')
def run(self):
'runs the code sync_run which has been generated with setup_sync()'
@@ -112,17 +122,4 @@ class MotionBase:
raise 'Need to call setup sync before'
gpascii.send_block(cmd)
dst='/tmp/triggerSync'
src=os.path.abspath(os.path.join(os.path.dirname(__file__), '../src/triggerSync/triggerSync'))
cmd='LD_LIBRARY_PATH=/opt/ppmac/libppmac/ '+dst
# self.syncShell=comm.shell_channel(cmd)
try:
cmd=self.cmdSync
except AttributeError: pass
else:
import time
time.sleep(1)
self.syncChan=sc=comm._client.exec_command(cmd)