Subversion Repositories svnkaklik

Rev

Rev 509 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log

Rev 509 Rev 510
Line 21... Line 21...
21
	pom=(fi-(*deg))*60;
21
	pom=(fi-(*deg))*60;
22
	*min=(u08)trunc(pom);
22
	*min=(u08)trunc(pom);
23
	*sec=(u08)round((pom-(*min))*60);
23
	*sec=(u08)round((pom-(*min))*60);
24
}
24
}
25
 
25
 
26
inline double quadraticerror(double average, double buf[], u16 size)
26
inline double quadraticerror(double average, double buf[], u16 size) // compute average quadratic error
27
{
27
{
28
  u16 i;
28
  u16 i;
29
  double err=0;
29
  double err=0;
30
 
30
 
31
	for(i=0; i<size; i++) err += square(buf[i]-average);		// sum quadratic errors
31
	for(i=0; i<size; i++) err += square(buf[i]-average);		// sum quadratic errors	
32
	err = sqrt(err/(size-1))/sqrt(size);	// compute average quadratic error
32
	err = sqrt((1/size)*err);
33
	return err;
33
	return err;
34
}
34
}
35
 
35
 
36
int main(void)
36
int main(void)
37
{
37
{
38
	u16 i,x,y;
38
	u16 i,x,y;
39
	double fi, err, fibuf[BUFLEN];
39
	double fi, err, fibuf[BUFLEN];		// buffer for recorded and computed values
40
	u08 fi_min, fi_sec, err_min, err_sec;
40
	u08 fi_min, fi_sec, err_min, err_sec;	// computed angles
41
	u16 fi_deg, err_deg;
41
	u16 fi_deg, err_deg;		// computed angles in whole degrees
42
 
42
 
43
	// initialize our libraries
43
	// initialize some libraries
44
	// initialize the UART (serial port)
44
	// initialize the UART (serial port)
45
	uartInit();
45
	uartInit();
46
	uartSetBaudRate(0,9600);
46
	uartSetBaudRate(0,9600);
47
	// make all rprintf statements use uart for output
47
	// make all rprintf statements use uart for output
48
	rprintfInit(uart0SendByte);
48
	rprintfInit(uart0SendByte);
Line 84... Line 84...
84
			fibuf[i] = atan2((double)x-511,(double)y-511);		// record computed angles to buffer for post processing
84
			fibuf[i] = atan2((double)x-511,(double)y-511);		// record computed angles to buffer for post processing
85
		}
85
		}
86
		for(i=0; i<BUFLEN; i++) fi += fibuf[i];		// sum recorded angles
86
		for(i=0; i<BUFLEN; i++) fi += fibuf[i];		// sum recorded angles
87
		fi = (fi/BUFLEN)+PI;		// average recorded angles and expand product to whole circle
87
		fi = (fi/BUFLEN)+PI;		// average recorded angles and expand product to whole circle
88
 
88
		
89
/*for(i=0; i<BUFLEN; i++)
-
 
90
{
-
 
91
	fibuf[i]=i;
-
 
92
}*/
-
 
93
		
-
 
94
		err=quadraticerror(fi,fibuf,BUFLEN);
89
		err=quadraticerror(fi,fibuf,BUFLEN);
95
		radtodeg(fi,&fi_deg,&fi_min,&fi_sec);
90
		radtodeg(fi,&fi_deg,&fi_min,&fi_sec);
96
		radtodeg(err,&err_deg,&err_min,&err_sec);
91
		radtodeg(err,&err_deg,&err_min,&err_sec);
97
		
92
		
98
		rprintf("fi:%d.%d.%d  +- %d.%d.%d \r\n", fi_deg, fi_min, fi_sec, err_deg, err_min, err_sec);
93
		rprintf("fi:%d.%d.%d  +- %d.%d.%d \r\n", fi_deg, fi_min, fi_sec, err_deg, err_min, err_sec);