enhance triggering

This commit is contained in:
2019-03-20 14:34:12 +01:00
parent eda8caf985
commit 399282cba9
9 changed files with 36 additions and 23 deletions

View File

@@ -1140,6 +1140,7 @@ zamofing_t@ganymede:~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python$
cp -farL ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/*.py \ cp -farL ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/*.py \
~/Documents/prj/SwissFEL/PBTools/pbtools/ \ ~/Documents/prj/SwissFEL/PBTools/pbtools/ \
~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/src/triggerSync/triggerSync \
/sf/bernina/config/swissmx/zamofing_t/ /sf/bernina/config/swissmx/zamofing_t/
cp -farL ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/ShapePathAnalyser/*.py \ cp -farL ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/ShapePathAnalyser/*.py \
/sf/bernina/config/swissmx/zamofing_t/ShapePathAnalyser/ /sf/bernina/config/swissmx/zamofing_t/ShapePathAnalyser/

View File

@@ -44,7 +44,7 @@ class MotionBase:
self.meta={'srv_per':ServoPeriod,'pt2pt_time':40,'sync_flag':0,'sync_mode':2} self.meta={'srv_per':ServoPeriod,'pt2pt_time':40,'sync_flag':0,'sync_mode':2}
self.meta.update(kwargs) self.meta.update(kwargs)
def setup_sync(self, crdId=1, prgId=2,verbose=False): def setup_sync(self, crdId=1, prgId=2,verbose=False, timeOfs=0.):
'''setup the timing synchronization for the motion program '''setup the timing synchronization for the motion program
kwargs: kwargs:
sync_mode : default=2 sync_mode : default=2
@@ -122,7 +122,7 @@ class MotionBase:
sftp.put(src, dst) sftp.put(src, dst)
sftp.chmod(dst, 0o755) sftp.chmod(dst, 0o755)
cmd = 'LD_LIBRARY_PATH=/opt/ppmac/libppmac/ ' + dst cmd = 'LD_LIBRARY_PATH=/opt/ppmac/libppmac/ ' + dst
cmd+=' %g %d'%(pt2pt_time,arg) cmd+=' %g %g %d'%(pt2pt_time,timeOfs,arg)
self.cmdSync = cmd self.cmdSync = cmd
print ('starting '+cmd) print ('starting '+cmd)
self.syncShell=comm.shell_channel(cmd) self.syncShell=comm.shell_channel(cmd)

View File

@@ -56,7 +56,8 @@ class MPLCanvasErr(FigureCanvas):
hl += ax.plot(erry, 'g-',label='y-error') hl += ax.plot(erry, 'g-',label='y-error')
hl += ax.plot(err, 'r-',label='error') hl += ax.plot(err, 'r-',label='error')
ax.xaxis.set_label_text('datapoint (timebase: %g ms per data point)'%meta['timebase']) tb=meta['srv_per']*meta['acq_per']
ax.xaxis.set_label_text('datapoint (timebase: %g ms per data point)'%tb)
ax.yaxis.set_label_text('pos-error um') ax.yaxis.set_label_text('pos-error um')
legend = ax.legend(loc='upper right', shadow=True) legend = ax.legend(loc='upper right', shadow=True)
ax.plot([.5,.5],[0.01, 0.99],'k',transform=ax.transAxes) ax.plot([.5,.5],[0.01, 0.99],'k',transform=ax.transAxes)

View File

@@ -59,7 +59,8 @@ class MPLCanvasVelo(FigureCanvas):
hl += ax.plot(velAct, 'r-',label='vel act') hl += ax.plot(velAct, 'r-',label='vel act')
hl += ax.plot(velDes, 'r--',label='vel des') hl += ax.plot(velDes, 'r--',label='vel des')
ax.xaxis.set_label_text('datapoint (timebase: %g ms per data point)'%meta['timebase']) tb=meta['srv_per']*meta['acq_per']
ax.xaxis.set_label_text('datapoint (timebase: %g ms per data point)'%tb)
ax.yaxis.set_label_text('um/ms') ax.yaxis.set_label_text('um/ms')
legend = ax.legend(loc='upper right', shadow=True) legend = ax.legend(loc='upper right', shadow=True)
#axvline(linewidth=4, color='r') #axvline(linewidth=4, color='r')
@@ -143,9 +144,9 @@ class MAVelocityFrame(wx.Frame):
try: try:
vel=doc.vel vel=doc.vel
except AttributeError: except AttributeError:
tb=meta['timebase'] tb=meta['srv_per']*meta['acq_per']
#data points are um #data points are um
#datapoint timebase: 2 ms () per data point #datapoint tb= timebase of datapoint sampling
#velocity: um/ms (deltatau desVel= motor units per serco cycle) #velocity: um/ms (deltatau desVel= motor units per serco cycle)
rec=doc.fh['rec'] rec=doc.fh['rec']
velyAct = np.diff(rec[:, 0])/tb velyAct = np.diff(rec[:, 0])/tb

View File

@@ -289,7 +289,7 @@ class DebugPlot:
idxTrigger = np.where(np.diff(idxTrigger) == 1)[0] + 1 idxTrigger = np.where(np.diff(idxTrigger) == 1)[0] + 1
if idxTrigger.shape[0] > 0: if idxTrigger.shape[0] > 0:
hl += ax.plot(rec[idxTrigger, 1], rec[idxTrigger, 0], 'xr', label='trig') # actual path hl += ax.plot(rec[idxTrigger, 1], rec[idxTrigger, 0], 'xr', label='trig') # actual path
hl2 += ax2.plot(rec[:, 4], 'b-', label='trigger') hl2 += ax2.plot(rec[:, 4]*10, 'b-', label='trigger')
ax.xaxis.set_label_text('x-pos um') ax.xaxis.set_label_text('x-pos um')
ax.yaxis.set_label_text('y-pos um') ax.yaxis.set_label_text('y-pos um')
@@ -854,7 +854,8 @@ if __name__=='__main__':
#sp.gen_closed_shifted() #sp.gen_closed_shifted()
#sp.gen_swissmx_points(width=1000,ofs=(-500,0)) #sp.gen_swissmx_points(width=1000,ofs=(-500,0))
#sp.gen_swissfel_points(width=1000,ofs=(-500,0)) #sp.gen_swissfel_points(width=1000,ofs=(-500,0))
sp.gen_rand_points(n=2000, scale=1000);sp.sort_points(xy=False) #sp.gen_rand_points(n=20, scale=100,ofs=(-950,+2780));sp.sort_points(xy=False)
sp.gen_rand_points(n=200, scale=100,ofs=(0,+2000));sp.sort_points(xy=False)
#sp.gen_swissmx_points(width=1000, ofs=(-500, 0)); #sp.gen_swissmx_points(width=1000, ofs=(-500, 0));
#sp.gen_spiral_points(rStart=100,rInc=10,numSeg=4,numCir=60, ofs=(0, 0)) #sp.gen_spiral_points(rStart=100,rInc=10,numSeg=4,numCir=60, ofs=(0, 0))
#sp.gen_spiral_points(rStart=100,rInc=130,numSeg=4,numCir=2, ofs=(0, 0)) #sp.gen_spiral_points(rStart=100,rInc=130,numSeg=4,numCir=2, ofs=(0, 0))
@@ -868,7 +869,7 @@ if __name__=='__main__':
gtMaxLn=116508;ovhdTime=100 gtMaxLn=116508;ovhdTime=100
acq_per=int(np.ceil((sp.meta['pt2pt_time']*sp.points.shape[0]+ovhdTime)/(gtMaxLn*sp.meta['srv_per']))) acq_per=int(np.ceil((sp.meta['pt2pt_time']*sp.points.shape[0]+ovhdTime)/(gtMaxLn*sp.meta['srv_per'])))
sp.setup_gather(acq_per=acq_per) sp.setup_gather(acq_per=acq_per)
sp.setup_sync(verbose=args.verbose&32) sp.setup_sync(verbose=args.verbose&32,timeOfs=0.55)
sp.setup_coord_trf() # reset to shape path system sp.setup_coord_trf() # reset to shape path system
#sp.meta['pt2pt_time']=10 #put between setup_sync and setup_motion to have more motion points than FEL syncs #sp.meta['pt2pt_time']=10 #put between setup_sync and setup_motion to have more motion points than FEL syncs
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1.,dwell=10) sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1.,dwell=10)

1
python/triggerSync Symbolic link
View File

@@ -0,0 +1 @@
../src/triggerSync/triggerSync

BIN
src/triggerSync/triggerSync Executable file

Binary file not shown.

View File

@@ -33,7 +33,7 @@
extern struct SHM *pshm; extern struct SHM *pshm;
static char mode=0; static char mode=0;
static float mtPt2Pt=40.f; //motion point to point time static float mtPt2Pt=40.f; //motion point to point time
static float timeOfs=0.f; //time ofset
#define CLOCK_RES 1e-9 //Clock resolution is 1 ns by default #define CLOCK_RES 1e-9 //Clock resolution is 1 ns by default
#define SIMFLAG0 (pshm->Coord[1].Q[10]) #define SIMFLAG0 (pshm->Coord[1].Q[10])
@@ -115,10 +115,11 @@ void trigsync_func(void *arg)
scStart=scLast=pshm->ServoCount; scStart=scLast=pshm->ServoCount;
mtAct=0.f; mtAct=0.f;
pshm->Coord[1].Q[0]=0; pshm->Coord[1].Q[0]=0;
pshm->Coord[1].DesTimeBase=srvPer; //start motion at default speed srvPer=0.2f;
//pshm->Coord[1].DesTimeBase=srvPer; //start motion at default speed
pshm->Coord[1].DesTimeBase=srvPer*(mtPt2Pt+timeOfs)/mtPt2Pt; //start motion at default speed
if(mode&8) if(mode&8)
printf("Start: %d, rtDiff: %.3f ms scDiff %d mtAct %.3f mtDes %.3f srvPer %.6f\n", i, rtLast/1E6,scLast, mtAct,mtDes,srvPer); printf("Start: rtStart:%.3f ms scStart:%d mtAct:%.3f mtDes:%.3f srvPer:%.6f\n", i, rtLast/1E6,scLast, mtAct,mtDes,srvPer);
for(i=1;pshm->Gather.Enable;i++) for(i=1;pshm->Gather.Enable;i++)
{ {
@@ -145,12 +146,12 @@ void trigsync_func(void *arg)
scDiff=scCur-scLast; scDiff=scCur-scLast;
mtAct+=scDiff*srvPer; mtAct+=scDiff*srvPer;
mtDes=i*mtPt2Pt; mtDes=i*mtPt2Pt+timeOfs;
srvPer=(mtPt2Pt+mtDes-mtAct)/scDiff; srvPer=(mtPt2Pt+mtDes-mtAct)/scDiff;
pshm->Coord[1].DesTimeBase=srvPer; pshm->Coord[1].DesTimeBase=srvPer;
pshm->Coord[1].Q[0]++; pshm->Coord[1].Q[0]++;
if(mode&8) if(mode&8)
printf("Trigger count: %d, rtDiff: %.3f ms scDiff %d mtAct %.3f mtDes %.3f srvPer %.6f\n", i, rtDiff/1E6,scDiff, mtAct,mtDes,srvPer); printf("Trigger count:%d, rtDiff:%.3fms scDiff:%d mtAct:%.3f mtDes:%.3f srvPer:%.6f\n", i, rtDiff/1E6,scDiff, mtAct,mtDes,srvPer);
rtLast=rtCur; rtLast=rtCur;
scLast=scCur; scLast=scCur;
} }
@@ -179,8 +180,8 @@ void trigsim_func(void *arg)
for(i=0,rtSlice=rtStart;;i++) for(i=0,rtSlice=rtStart;;i++)
{ {
//rtSlice=rtStart+i*40*1E6; // a slice is 40 ms rtSlice=rtStart+i*40*1E6; // a slice is 40 ms
rtSlice=rtStart+i*40.2*1E6; // a slice is 40 ms //rtSlice=rtStart+i*40.2*1E6; // a slice is 40 ms
//rtSlice+=(rand()%(int)(1*1E6)); //0.1ms jitter //rtSlice+=(rand()%(int)(1*1E6)); //0.1ms jitter
rt_task_sleep_until(rtSlice); //in ns rt_task_sleep_until(rtSlice); //in ns
if(mode&4) if(mode&4)
@@ -296,7 +297,7 @@ Coord[1].Q[0]= 0 : got frame trigger 0\n\
Coord[1].Q[0] is incremented at each trigger\n\ Coord[1].Q[0] is incremented at each trigger\n\
sync task ends when Gather.Enable==0\n\ sync task ends when Gather.Enable==0\n\
"; ";
printf("usage:\n%s pt2ptTime mode\n",cmd); printf("usage:\n%s pt2ptTime timeOfs mode\n",cmd);
puts(s); puts(s);
return -1; return -1;
} }
@@ -307,15 +308,22 @@ int main(int argc, char *argv[])
int initialized=0; int initialized=0;
int i; int i;
char *s; char *s;
if(argc!=3) if(argc!=4)
return usage(argv[0]); return usage(argv[0]);
mtPt2Pt= strtof(argv[1], &s); mtPt2Pt=strtof(argv[1], &s);
if (argv[1]==s) if (argv[1]==s)
return usage(argv[0]); return usage(argv[0]);
mode= (int)strtol(argv[2], &s, 10); timeOfs=strtof(argv[2], &s);
if (argv[2]==s) if (argv[2]==s)
return usage(argv[0]); return usage(argv[0]);
mode=(int)strtol(argv[3], &s, 10);
if (argv[3]==s)
return usage(argv[0]);
puts(argv[0]);
puts(argv[1]);
puts(argv[2]);
puts(argv[3]);
printf("mtPt2Pt:%g timeOfs:%g mode:%d\n",mtPt2Pt,timeOfs,mode);
if ((err = InitLibrary()) != 0) { if ((err = InitLibrary()) != 0) {
abort(); abort();
} }

View File

@@ -4,7 +4,7 @@
<ActiveTarget name="Debug" /> <ActiveTarget name="Debug" />
<File name="triggerSync.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="triggerSync.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="3035" topLine="181" /> <Cursor1 position="6215" topLine="189" />
</Cursor> </Cursor>
</File> </File>
<File name="Makefile" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="Makefile" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">