MIT_MatlabToolbox/trunk/embcode/rsedu_of.c
/*
 * @input is the result of optical flow computations, this functions then dumps these into a fifo to make them available to the control code
 *
 * Called 60 times per second.
 */
@input is the result of optical flow computations, this functions then dumps these into a fifo to make them available to the control code
Called 60 times per second.
@input is the result of optical flow computations this functions then dumps these into a fifo to make them available to the control code Called 60 times per second .
void RSEDU_optical_flow(float vx, float vy, float vz,int defined,float qualityIndicator)
{
	static int counter = 0;
	static float of_data[5];
	int status;
	static int of_fifo;
	long long start;
	static FILE *ptfile;
	ptimer_start(FEAT_TIME,counter,&(start));
	counter++;
	of_data[0] = vx;
	of_data[1] = vy;
	of_data[2] = vz;
	of_data[3] = (float)(defined*1.0);
	of_data[4] = qualityIndicator;
	if(counter==1)
	{
		if( access( "/tmp/of_fifo", F_OK ) != -1 )
		{
		printf("rsedu_of(): SUCCESS optical flow FIFO exists! \n");
		}
		else
		{
			printf("rsedu_of(): ERROR opening optical flow-fifo!\n");
		}
		 ptimer_init(FEAT_TIME,__func__,&(ptfile),NULL);
	}
	of_fifo = open("/tmp/of_fifo",O_WRONLY);
	if(of_fifo)
	{
		write(of_fifo,(float*)(&of_data),sizeof(of_data));
		close(of_fifo);
	}
	usleep(4000);
	ptimer_stopstore(FEAT_TIME, counter,start, ptfile);
}
void RSEDU_optical_flow ( float vx , float vy , float vz , int defined , float qualityIndicator ) { static int counter = 0 ; static float of_data [ 5 ] ; int status ; static int of_fifo ; long long start ; static FILE * ptfile ; ptimer_start ( FEAT_TIME , counter , & ( start ) ) ; counter ++ ; of_data [ 0 ] = vx ; of_data [ 1 ] = vy ; of_data [ 2 ] = vz ; of_data [ 3 ] = ( float ) ( defined * 1.0 ) ; of_data [ 4 ] = qualityIndicator ; if ( counter == 1 ) { if ( access ( " " , F_OK ) != -1 ) { printf ( " \n " ) ; } else { printf ( " \n " ) ; } ptimer_init ( FEAT_TIME , __func__ , & ( ptfile ) , NULL ) ; } of_fifo = open ( " " , O_WRONLY ) ; if ( of_fifo ) { write ( of_fifo , ( float * ) ( & of_data ) , sizeof ( of_data ) ) ; close ( of_fifo ) ; } usleep ( 4000 ) ; ptimer_stopstore ( FEAT_TIME , counter , start , ptfile ) ; }
@input is the result of optical flow computations, this functions then dumps these into a fifo to make them available to the control code
 Called 60 times per second.
@input is the result of optical flow computations this functions then dumps these into a fifo to make them available to the control code Called 60 times per second .
//process control //communication /*
	 * PROGRAM
	 */ //ptiming - declare and start //------------ //------------ //process control //Compile data //printf("rsedu_of(): flow: (%f, %f, %f, %f, %f)\n",of_data[0],of_data[1],of_data[2],of_data[3],of_data[4]); //Setup thread communication //create fifo to transmit optical flow to control code - now done by shell-script that starts a flight /*if ((status = mkfifo("/tmp/of_fifo", S_IRWXU)) < 0) {
			//printf("optical_flow(): ERROR makingf fifo!\n");

		}
		*/ //ptiming - init file //------------ //------------ //usleep(10000); //FIFO handling and writing //ptiming - store //---------- //---------- //printf("rsedu_of(): cycle %d\n", counter);