128 lines
3.8 KiB
Python
128 lines
3.8 KiB
Python
#some further usefull PMAC commands:
|
|
# list pc , 10 //list program counter during motion exec
|
|
# buffer //list allocated buffers
|
|
#the rotary stuff only works from gpascii, not gpasciiCommander
|
|
#delete rotary
|
|
#define rotary 4096 //allocates mem
|
|
#open rotary //same as open prog 0
|
|
#
|
|
# X100 Y100
|
|
# X200 Y300
|
|
# X600 Y500
|
|
# adding lines alway are acknowledged with ACK,
|
|
# if not, it means that the buffer is full
|
|
# it will acknowlegde when there is again free space.
|
|
# close
|
|
# delete rotary
|
|
|
|
|
|
#from other gpascii
|
|
#list rotary
|
|
#rotfree
|
|
#size
|
|
#b0s //start the rotary buffer in single step mode
|
|
|
|
import os, sys
|
|
sys.path.insert(0,os.path.expanduser('~/Documents/prj/SwissFEL/PBTools/'))
|
|
#import pbtools.misc.pp_comm as pp_comm -> pp_comm.PPComm
|
|
from pbtools.misc.pp_comm import PPComm
|
|
from pbtools.misc.gather import Gather
|
|
|
|
|
|
class MotionBase:
|
|
def __init__(self, comm, gather, verbose):
|
|
self.comm=comm
|
|
self.gather=gather
|
|
self.verbose=verbose
|
|
|
|
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
|
|
'''
|
|
if mode == 0:
|
|
try:
|
|
del self.sync_prg
|
|
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==0'
|
|
prg = '''close all buffers
|
|
disable plc {plcId}
|
|
open plc {plcId}
|
|
L0=Sys.PhaseCount
|
|
send 1"sync0 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L0
|
|
while({flag}){{}}
|
|
send 1"sync1 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L0
|
|
L1=Sys.PhaseCount
|
|
while(1)
|
|
{{
|
|
if({flag})
|
|
{{
|
|
PowerBrick[0].GpioData[0].16.1=1
|
|
Coord[{crdId}].DesTimeBase=Sys.ServoPeriod
|
|
send 1"sync2 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L1
|
|
break
|
|
}}
|
|
}}
|
|
disable plc {plcId}
|
|
close
|
|
'''.format(plcId=plcId, crdId=crdId, flag=flag)
|
|
comm=self.comm
|
|
if comm is not None:
|
|
gpascii=comm.gpascii
|
|
gpascii.send_block(prg)
|
|
self.sync_prg = 'Coord[{crdId}].DesTimeBase=0'.format(prgId=prgId, plcId=plcId, crdId=crdId)
|
|
self.sync_run = 'enable plc {plcId};&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
|
|
|
|
elif mode == 2:
|
|
# 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'
|
|
flag = 'Gate3[1].Chan[0].UserFlag==0'
|
|
prg = '''
|
|
//L0=Sys.PhaseCount
|
|
//send 1"sync0 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L0
|
|
while({flag}){{}}
|
|
//send 1"sync1 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L0
|
|
//L1=Sys.PhaseCount
|
|
while(1)
|
|
{{
|
|
if({flag})
|
|
{{
|
|
//PowerBrick[0].GpioData[0].16.8=255
|
|
//send 1"sync2 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L1
|
|
break
|
|
}}
|
|
}}
|
|
'''.format(plcId=plcId, crdId=crdId, flag=flag)
|
|
self.sync_prg = prg
|
|
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
|
|
|
|
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)
|
|
|