Project

General

Profile

Revision 1381

Changed name of rangefinder test to reflect name of rangefinder module. Updated main.c to reflect this.

View differences:

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

  
77

  
78 0

  
trunk/code/projects/test/test_rangefinder.c
1
/**
2
 * @file test_rangefinder.c
3
 * @brief Contains unit test for rangefinder.c module of libdragonfly
4
 *
5
 * Contains a function allowing the user to test whether the rangefinder module
6
 * works correctly.
7
 *
8
 * @author Colony Project, CMU Robotics Club
9
 **/
10

  
11
/* Testing Procedure
12
 * - Position robot facing you
13
 * - Wait for initial BLUE flashes
14
 * - Position hand at ~12cm from leftmost, rearmost rangefinder (IR4)
15
 * - Sweep hand around front of robot, maintaining distance from rangefinders
16
 * - Observe orbs
17
 *
18
 * Expected Behavior:
19
 * - Orbs flash BLUE 3 times to signal start of test
20
 * - Orbs turn RED when IR4 gets a useable reading
21
 * - Orbs turn ORANGE when IR1 gets a useable reading
22
 * - Orbs turn YELLOW when IR2 gets a useable reading
23
 * - Orbs turn GREEN when IR3 gets a useable reading
24
 * - Orbs turn BLUE when IR5 gets a useable reading
25
 */
26

  
27
#include <dragonfly_lib.h>
28

  
29
#define delay 750   // delay between sensors (in ms)
30

  
31
int test_rangefinder() {
32
    uint8_t i, ir, color;   // plain old index, rangefinder index, color index
33
    int detectors[5] = {IR4, IR1, IR2, IR3, IR5};   // rangefinders L to R
34
    int colors[5] = {RED, ORANGE, YELLOW, GREEN, BLUE};	// colors of rainbow
35

  
36
    // flash orbs BLUE 3 times
37
    for (i = 0; i < 3; i++) {
38
	orb_set_color(BLUE);
39
	delay_ms(500);
40
	orb_set_color(ORB_OFF);
41
	delay_ms(250);
42
    }
43

  
44
    // show appropriate color when sensor gets a good read, then wait a second
45
    // do this for each sensor in left-to-right order
46
    for (ir = 1, color = 0; ir <= 5; ir++, color++) {
47
	while (range_read_distance(ir) == -1);
48
	orb_set_color(color);
49
	delay_ms(DELAY);
50
    }
51

  
52
    return 0;
53
}
54

  
0 55

  
trunk/code/projects/test/main.c
15 15
    //    RUN_TEST(testlcd);
16 16
    RUN_TEST(testlights);
17 17
    RUN_TEST(testmotors);
18
    RUN_TEST(testrangefinders);
18
    RUN_TEST(testrangefinder);
19 19
    RUN_TEST(testtokenring);
20 20

  
21 21
  }

Also available in: Unified diff