Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / test / testrangefinders.c @ 1067

History | View | Annotate | Download (1.31 KB)

1
#include <dragonfly_lib.h>
2

    
3

    
4
/**
5
 * RangeFinder Rules
6
 * - analog_init() is needed
7
 * - value 100 - under 5cm is not detected
8
 * - value 800 - over ~30cm is not detected
9
 * - at ~20cm values become increasingly erroneous
10
 *
11
 */
12
 
13
int to_mm(int rangeFinder) 
14
{
15

    
16
        if(rangeFinder != -1)
17
                return (int)(rangeFinder/15.112*10);
18
        else
19
                return -1;
20

    
21
}
22

    
23
int testrangefinders(void) {
24
  dragonfly_init(ANALOG);
25
  usb_init();
26
        usb_puts("usb turned on\r\n");
27
  range_init();
28
  usb_puts("rangefinders turned on\r\n");
29
  int d1,d2,d3,d4,d5;
30
  delay_ms(1000);
31
  
32
  //int sum = 0;
33
  //int count = 0;
34
  //int average = 0;
35
  
36
  // start testing rangefinders
37
  while(1) {
38
        //if(count == 10000)
39
        //{
40
        //        average = sum/count;
41
        //        count = 0;
42
        //}
43
        
44
    // get ranges
45
    //d1 = range_read_distance(IR1);
46
    d2 = range_read_distance(IR2);
47
    //d3 = range_read_distance(IR3);
48
    //d4 = range_read_distance(IR4);
49
    //d5 = range_read_distance(IR5);
50
    //usb_puts("d1=");
51
    //usb_puti(d1);
52
        
53
        //sum += d2;
54
        
55
    //usb_puts("\taverage of 10000=");
56
    //usb_puti(d2);
57
        
58
    //usb_puts("\td3=");
59
    //usb_puti(d3);
60
    //usb_puts("\td4=");
61
    //usb_puti(d4);
62
    //usb_puts("\td5=");
63
    //usb_puti(d5);
64
        
65
        usb_puts("\tIn mm=");
66
        usb_puti(to_mm(d2));
67
    usb_puts("\r\n");   
68
        
69
        //count++;
70
        
71
    delay_ms(100);
72
  }
73
  
74
  // end testing rangefinders
75
        return 0;
76
}
77

    
78