non adapting triggering with triggerSync.c

This commit is contained in:
2019-01-17 15:56:18 +01:00
parent 3e9485ee25
commit a11a3bce79
4 changed files with 106 additions and 57 deletions

View File

@@ -60,6 +60,9 @@ void trigsync_func(void *arg)
}
*/
if(pshm->Gather.Enable==1)
pshm->Gather.Enable=2; //start record at flag0' trigger
sleep(1);
rtStart=rt_timer_read();
printf("Wait for trigger:\n");
pshm->Coord[1].Q[0]=-10;
@@ -68,11 +71,10 @@ void trigsync_func(void *arg)
printf("Flag 0: %.5f ms\n", (rt_timer_read() - rtStart)/1000000.0);
pshm->Coord[1].Q[0]=-9;
if(!pshm->Gather.Enable)
pshm->Gather.Enable=2; //start record at flag0' trigger
while(!FLAG1)
rt_task_wait_period(NULL);
//pshm->Gather.Enable=2; //start record at flag1' trigger
//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);
rtStart=rtLast=rt_timer_read();
scStart=scLast=pshm->ServoCount;
@@ -81,7 +83,6 @@ void trigsync_func(void *arg)
while(FLAG1)
rt_task_wait_period(NULL);
while(pshm->Gather.Enable)
for(i=0;pshm->Gather.Enable;i++)
{
while(!FLAG1)
@@ -119,33 +120,45 @@ void trigsim_func(void *arg)
curtask = rt_task_self();
rt_task_inquire(curtask, &curtaskinfo);
//Print the info
printf("Starting task %s with period of %f ms ....\n", curtaskinfo.name,LOOP_PERIOD/1000000.f);
//printf("Starting task %s with period of %f ms ....\n", curtaskinfo.name,10*1E6/1E6);
//Make the task periodic with a specified loop period
rt_task_set_periodic(NULL, TM_NOW, LOOP_PERIOD);
//rt_task_set_periodic(NULL, TM_NOW, 10*1E6);
printf("Starting task %s \n", curtaskinfo.name);
int i;
RTIME rtStart;
RTIME rtStart,rtSlice;
printf("sizeof RTTIME %d\n",sizeof(rtStart));
pshm = GetSharedMemPtr();
rtStart=rt_timer_read();
rt_task_sleep(1000*1000*1000); //in ns
pshm->P[0]=1;
rt_task_sleep(100*1000*1000); //in ns
pshm->P[1]=1;
for(i=0;i<100&&pshm->Gather.Enable;i++)
for(i=0;;i++)
{
rtSlice=rtStart+i*40*1E6; // a slice is 40 ms
rt_task_sleep_until(rtSlice); //in ns
pshm->P[1]=1;
rt_task_sleep(1*1000*1000); //in ns
//while(rt_timer_read()-rtStart<1E6*40*i)
// rt_task_wait_period(NULL);
rt_task_sleep_until(rtSlice+5*1E6); //in ns
pshm->P[1]=0;
rt_task_sleep(39*1000*1000); //in ns
if(pshm->Coord[1].Q[0]==-10)
{
rt_task_sleep_until(rtSlice+10*1E6); //in ns
pshm->P[0]=1;
rt_task_sleep_until(rtSlice+20*1E6); //in ns
pshm->P[0]=0;
}
if(pshm->Coord[1].Q[0]==-1)
break;
putchar('.');fflush(stdout);
}
if(pshm->Gather.Enable)
{
pshm->Gather.Enable=0;
//pshm->Gather.Enable=0;
}
pshm->P[1]=1;
rt_task_sleep(1*1000*1000); //in ns
rt_task_sleep(1*1E6); //in ns
pshm->P[1]=0;
printf("trigsim_func done:\n");
}
@@ -176,11 +189,13 @@ void trigsync_run()
printf("Wait end of rt_task\n");
rt_task_join (&trigsim_task);
rt_task_join(&trigsync_task);
printf("trigsync_task done\n");
pshm->Coord[1].Q[0]=-1;
rt_task_join(&trigsim_task);
printf("trigsim_task done\n");
rt_task_join (&trigsync_task);
printf("trigsync_task done\n");
printf("rt_task ended\n");