towards new communication

This commit is contained in:
2018-10-16 10:28:20 +02:00
parent 40246e95e0
commit f4575e5be0
2 changed files with 94 additions and 87 deletions

View File

@@ -144,51 +144,21 @@ class ShapePath(MotionBase):
#ServoPeriod=comm.gpascii.servo_period
self.meta = {'timebase': ServoPeriod*acq_per}
def setup_sync(self,crdId=1,prgId=2,plcId=2,mode=0,**kwargs):
'''setup the timing synchronization for the motion program
mode=0 : no sync at all
mode=1 : first sync test
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
'''
gpascii=self.comm.gpascii
if mode==0:
try:
del self.sync_wait
except AttributeError:
pass
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, crdId=crdId)
elif mode==1:
# changes the Timebase of coord system
# modifies the timebase to start/stop a running program
# this can also be used to adjust the execution speed
# the plc for now
# - waits untis <flag> is false
# - waits raising edge of <flag> and the sets DesTimeBase=ServoPeriod
#flag ='PowerBrick[0].GpioData[0].0.1==1'
flag ='Gate3[1].Chan[0].UserFlag==1'
prg='''close all buffers
open plc {plcId}
Coord[{crdId}].DesTimeBase=0 // freezes timebase at boot
while(flag){{}}
while(1)
{{
if({flag})
{{
PowerBrick[0].GpioData[0].16.8=255
Coord[{crdId}].DesTimeBase=Sys.ServoPeriod
break
}}
}}
close
'''.format(plcId=plcId,crdId=crdId,flag=flag)
gpascii.send_block(prg)
self.sync_wait='Coord[{crdId}].DesTimeBase=0;enable plc {plcId}'.format(plcId=plcId,crdId=crdId)
self.sync_run='Coord[{crdId}].DesTimeBase=0;&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
def setup_coord_trf(self):
comm = self.comm
gpascii = comm.gpascii
prg = '''&1a
#1-> Y
#2-> X
#3-> A
#4->0
#5->0
#6->0
#7->0
#8->0
#1..8j/
'''
gpascii.send_block(prg)
def setup_motion(self,prgId=2,fnPrg=None,mode=0,**kwargs):
'''
@@ -327,31 +297,13 @@ close
# retval = p.wait()
self.prg=prg
def run(self):
'runs the code sync_run which has been generated with setup_sync()'
comm = self.comm
gpascii = comm.gpascii
try:
cmd=self.sync_run
except AttributeError:
raise 'Need to call setup sync before'
gpascii.send_block(cmd)
def gather_upload(self,fnRec=None):
#gather -u /var/ftp/gather/out.txt
#cmd ='PBGatherPlot -m24 -v7 --host '+self.host
#print(cmd)
#p = sprc.Popen(cmd, shell=True)#, stdout=sprc.PIPE, stderr=sprc.STDOUT)
#retval = p.wait()
#fnLoc='/tmp/gather.txt'
#self.rec =rec = np.genfromtxt(fnLoc, delimiter=' ')
gt=self.gather
gt.wait_stopped(verbose=True)
self.rec=rec=gt.upload()
pts=self.points
#rec=Motor[1].ActPos,Motor[2].ActPos,Motor[3].ActPos,Motor[1].DesPos,Motor[2].DesPos,Motor[3].DesPos
#res=rot.ActPos,x.ActPos,y.ActPos,rot.DesPos,x.DesPos,y.DesPos
#idx 0 1 2 3 4 5
@@ -466,7 +418,7 @@ if __name__=='__main__':
comm = PPComm(host=args.host)
gather = Gather(comm)
sp = ShapePath(comm, gather, args.verbose)
sp.host=args.host #temporary
sp.setup_coord_trf()
fn='/tmp/shapepath'
xy=False