running sync !!!
This commit is contained in:
@@ -41,58 +41,60 @@ void trigsync_func(void *arg)
|
||||
rt_task_set_periodic(NULL, TM_NOW, LOOP_PERIOD);
|
||||
|
||||
int i;
|
||||
RTIME rtStart,rtLast,rtCur;
|
||||
unsigned scStart,scLast,diff,maxDiff;
|
||||
RTIME rtStart,rtLast,rtCur,rtDiff; //rt* is real time of the rt-process
|
||||
unsigned int scStart,scLast,scCur,scDiff; //sc* are servo counts of the motion
|
||||
float srvPer;
|
||||
float mtAct,mtDes; //mt* motion time. Actual and desired. this is the accumulated time that controls motion speed
|
||||
|
||||
float mtPt2Pt=40.f; //motion point to point time
|
||||
|
||||
unsigned int maxDiff;
|
||||
struct GateArray3* gate3_1=GetGate3MemPtr(1);
|
||||
|
||||
pshm = GetSharedMemPtr();
|
||||
|
||||
|
||||
/*
|
||||
//Start the task loop
|
||||
rtStart = rt_timer_read();
|
||||
for(i=0;i<20000;i++)
|
||||
{
|
||||
if (i%10==0)
|
||||
printf("Loop count: %d, Loop time: %.5f ms\n", i, (rt_timer_read() - tStart)/1000000.0);
|
||||
rt_task_wait_period(NULL);
|
||||
//int rt_task_sleep_until
|
||||
}
|
||||
*/
|
||||
srvPer=pshm->ServoPeriod;
|
||||
|
||||
if(pshm->Gather.Enable==1)
|
||||
pshm->Gather.Enable=2; //start record at flag0' trigger
|
||||
sleep(1);
|
||||
usleep(1000000); //wait 1 sec(record before motion)
|
||||
rtStart=rt_timer_read();
|
||||
printf("Wait for trigger:\n");
|
||||
printf("Wait for 'arm' event:\n");
|
||||
pshm->Coord[1].Q[0]=-10;
|
||||
while(!FLAG0)
|
||||
rt_task_wait_period(NULL);
|
||||
printf("Flag 0: %.5f ms\n", (rt_timer_read() - rtStart)/1000000.0);
|
||||
printf("Flag 0: %.5f ms\n", (rt_timer_read() - rtStart)/1E6);
|
||||
|
||||
pshm->Coord[1].Q[0]=-9;
|
||||
while(!FLAG1)
|
||||
rt_task_wait_period(NULL);
|
||||
//if(pshm->Gather.Enable==1)
|
||||
// pshm->Gather.Enable=2; //start record at flag1' trigger
|
||||
printf("Flag 1: %.5f ms\n", (rt_timer_read() - rtStart)/1000000.0);
|
||||
printf("Flag 1: %.5f ms\n", (rt_timer_read() - rtStart)/1E6);
|
||||
rtStart=rtLast=rt_timer_read();
|
||||
scStart=scLast=pshm->ServoCount;
|
||||
mtAct=0.f;
|
||||
pshm->Coord[1].Q[0]=1;
|
||||
pshm->Coord[1].DesTimeBase=pshm->ServoPeriod; //start motion at default speed
|
||||
while(FLAG1)
|
||||
rt_task_wait_period(NULL);
|
||||
pshm->Coord[1].DesTimeBase=srvPer; //start motion at default speed
|
||||
|
||||
for(i=0;pshm->Gather.Enable;i++)
|
||||
for(i=1;pshm->Gather.Enable;i++)
|
||||
{
|
||||
while(!FLAG1)
|
||||
rt_task_wait_period(NULL);
|
||||
rtLast = rt_timer_read();
|
||||
scLast=pshm->ServoCount;
|
||||
pshm->Coord[1].Q[0]++;
|
||||
while(FLAG1)
|
||||
rt_task_wait_period(NULL);
|
||||
printf("Trigger count: %d, time: %.5f ms ServoCount %d\n", i, (rtLast - rtStart)/1000000.0,scLast-scStart);
|
||||
|
||||
while(!FLAG1)
|
||||
rt_task_wait_period(NULL);
|
||||
//FEL shot arrived
|
||||
rtCur = rt_timer_read();
|
||||
scCur=pshm->ServoCount;
|
||||
rtDiff=rtCur-rtLast;
|
||||
scDiff=scCur-scLast;
|
||||
|
||||
mtAct+=scDiff*srvPer;
|
||||
mtDes=i*mtPt2Pt;
|
||||
srvPer=(mtPt2Pt+mtDes-mtAct)/scDiff;
|
||||
pshm->Coord[1].DesTimeBase=srvPer;
|
||||
pshm->Coord[1].Q[0]++;
|
||||
printf("Trigger count: %d, rtDiff: %.3f ms scDiff %d mtAct %.3f mtDes %.3f srvPer %.3f\n", i, rtDiff/1E6,scDiff, mtAct,mtDes,srvPer);
|
||||
rtLast=rtCur;
|
||||
scLast=scCur;
|
||||
}
|
||||
|
||||
/* float ang,pos;
|
||||
@@ -132,9 +134,12 @@ void trigsim_func(void *arg)
|
||||
|
||||
rtStart=rt_timer_read();
|
||||
|
||||
for(i=0;;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+=(rand()%(int)(1*1E6)); //0.1ms jitter
|
||||
|
||||
rt_task_sleep_until(rtSlice); //in ns
|
||||
pshm->P[1]=1;
|
||||
//while(rt_timer_read()-rtStart<1E6*40*i)
|
||||
|
||||
Reference in New Issue
Block a user