This commit is contained in:
2018-11-27 11:24:39 +01:00
parent 53592c05a3
commit f08cba548e
6 changed files with 118 additions and 59 deletions

View File

@@ -73,11 +73,13 @@ class MotionBase:
self.sync_prg = prg
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
if mode==2:
#frequence jitter 50Hz Swissgrid:
#https://www.swissgrid.ch/de/home/operation/grid-data/current-data.html#
notFlag1 = 'Gate3[1].Chan[1].UserFlag!=0'
try:
prop=kwargs['prop'] #proportional value to adapt speed
except KeyError:
prop = 1E-4
prop = .5E-4
try:
maxJitter = kwargs['maxJitter'] # proportional value to adapt speed
except KeyError:
@@ -86,58 +88,67 @@ class MotionBase:
disable plc {plcId}
open plc {plcId}
Coord[1].DesTimeBase=Sys.ServoPeriod //reset to 100% timebase
Coord[1].Q[0]=0 //set CryPos counter to 0
Coord[1].Q[0]=0 //set syncCnt counter to 0
while({flag0}){{}} //wait Jungfrau start Trigger
while({flag1}){{}} //ESx detector trigger
L0=0 //CryPos counter
//L1 ServoCount event 1
//L2 jitter: neg:motion lags trigger,pos:motion leads trigger
{syncCnt}=0 //sync counter, sent when motion is on a crystal
//{evnt} current PhaseCount event
//{jitter} jitter: neg:motion lags trigger,pos:motion leads trigger
//{syncEnvt} Prev syncEnvt PhaseCount
{sync2sync}=0 // last syncEnvt-syncEnvt PhaseCount
{dtb}=Sys.ServoPeriod //DesTimeBase
//{tmp} temp variable
while(L0>=0) //as long we are not at the last point
while({syncCnt}>=0) //as long we are not at the last point
{{
L0=Coord[1].Q[0] //CryPos counter
while({flag1} && L0==Coord[1].Q[0]){{}} //wait for event
L1=Sys.ServoCount //a event happened
L2=1000
{syncCnt}=Coord[1].Q[0] //sync counter
while({flag1} && {syncCnt}==Coord[1].Q[0]){{}} //wait for event
{evnt}=Sys.PhaseCount //a event happened
{jitter}=1000
//send 1"event\\n"
if(L0==Coord[1].Q[0])
if({syncCnt}==Coord[1].Q[0])
{{//it was a trigger
//send 1"trigger %d %d\\n",L0,L1
while(Sys.ServoCount<L1+{maxJitter}) //wait half a trigger period for event
//send 1"trigger %d %d %d\\n",{syncCnt},{evnt},{sync2sync}
while(Sys.PhaseCount<{evnt}+{maxJitter}) //wait half a trigger period for event
{{
if(L0!=Coord[1].Q[0])
{{//event CryPos counter
L2=L1-Sys.ServoCount //jitter: neg:motion lags trigger
if({syncCnt}!=Coord[1].Q[0])
{{//event syncCnt
{tmp}=Sys.PhaseCount
{sync2sync}={tmp}-{syncEnvt};{syncEnvt}={tmp}
{jitter}={evnt}-{tmp} //jitter: neg:motion lags trigger
break
}}
}}
}}
else
{{//it was a CryPos counter
//send 1"CryPos%d %d\\n",L0,L1
while(Sys.ServoCount<L1+{maxJitter}) //wait half a trigger period for event
{{//it was a syncCnt
{sync2sync}={evnt}-{syncEnvt};{syncEnvt}={evnt}
//send 1"syncCnt %d %d %d\\n",{syncCnt},{evnt},{sync2sync}
while(Sys.PhaseCount<{evnt}+{maxJitter}) //wait half a trigger period for event
{{
if({notFlag1})
{{//event trigger
L2=Sys.ServoCount-L1 //jitter: pos:motion leads trigger
{jitter}=Sys.PhaseCount-{evnt} //jitter: pos:motion leads trigger
break
}}
}}
}}
if(L2!=1000)
if({jitter}!=1000 && {sync2sync}>0)
{{
L3=Sys.ServoPeriod*(1-{prop}*L2)
//send 1"jitter %d timebase: %f\\n",L2,L3
Coord[1].DesTimeBase=L3
{dtb}=Sys.ServoPeriod*(1-{prop}*{jitter})
//{dtb}={dtb}*(1-{jitter}/{sync2sync}*.5)
//send 1"syncCnt %d jitter %d sync2sync %d timebase: %f\\n",{syncCnt},{jitter},{sync2sync},{dtb}
Coord[1].DesTimeBase={dtb}
}}
}}
disable plc {plcId}
close
enable plc {plcId}
'''.format(plcId=plcId, crdId=crdId, flag0=flag0, flag1=flag1, notFlag1=notFlag1, prop=prop, maxJitter=maxJitter)
'''.format(plcId=plcId, crdId=crdId, flag0=flag0, flag1=flag1, notFlag1=notFlag1, prop=prop, maxJitter=maxJitter,
syncCnt='L0', evnt='L1', jitter='L2', syncEnvt='L3', sync2sync='L4', dtb='L5', tmp='L6')
comm=self.comm
if comm is not None:
gpascii=comm.gpascii