Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / slam.bak2 / robot / stat_gather.c @ 722

History | View | Annotate | Download (1.26 KB)

1
#include "dragonfly_lib.h"
2
#include "serial.h"
3

    
4
int main(void){
5
  int i;
6
  int ranges[] = {IR1, IR2, IR3, IR4, IR5};
7
  unsigned long eval[] = {0,0,0,0,0};
8
  unsigned long square_eval[] = {0,0,0,0,0};
9
  unsigned int count[] = {0,0,0,0,0};
10
  int range;
11
  int distance;
12
  
13
  //Correspond to 4 cm to 30 cm  THIS COULD BE GETTING A BIT RIDICULOUSLY HUGE.
14
  int distance_values[26][5];
15
  while(1){
16
    //Expects a value from 4 to 30.
17
    distance = (usb_getc()-'0')*10 + usb_getc()-'0';
18
    
19
    if(distance > 30 || distance < 4){
20
      usb_puts("Expected a value in the range of the IR sensor. (4 cm - 30 cm), try again.\n");
21
      continue;
22
    }
23

    
24
    while(!button1_read()){
25
      for(i = 0; i < 5; i++){
26
        count[i]++;
27
        range = range_read_distance(ranges[i]); 
28
        if(range==-1)
29
          count[i]--; 
30
        else{
31
          sum[i] += range;
32
          square_sum[i] += range*range;
33
        }
34
      }
35
    }
36
    
37
    for(i=0;i<5;i++){
38
      eval[i] /= count;
39
      square_eval[i] /= count
40
    }
41
  
42
    usb_puts("Average, variance for this run:\n");
43
    for(i=0;i<5;i++){
44
      usb_puts("IR"); usb_puti(i); usb_puts(":\t");
45
      usb_puti(eval[i]); usb_puts("\t");
46
      usb_puti(square_eval[i]-eval[i]*eval[i]);
47
      usb_puts("\n");
48
    }
49
    while(!button2_read());
50
  }
51
}