root / trunk / code / projects / unit_tests / test_rangefinder.c @ 2009
History | View | Annotate | Download (2.17 KB)
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 |
* - Place hand in front of orbs in 4, 3, 2, 1, 5 order
|
13 |
* - Observe orbs
|
14 |
*
|
15 |
* Expected Behavior:
|
16 |
* - Orbs flash BLUE 3 times to signal start of test
|
17 |
* - During test
|
18 |
* - Orb 1 changes to reflect which sensor is under test
|
19 |
* - Orb 2 stays RED until that sensor gets a usable reading, i.e. within visible distance
|
20 |
* - Orbs flash PURPLE 3 times to signal end of test
|
21 |
*/
|
22 |
|
23 |
#include <dragonfly_lib.h> |
24 |
|
25 |
#define TEST_TIME 500 // duration of success indicator (in ms) |
26 |
#define ON_DELAY 500 // duration of flashes at beginning and end (in ms) |
27 |
#define OFF_DELAY 250 // delay between flashes at beginning and end (in ms) |
28 |
|
29 |
int testrangefinder(void) |
30 |
{ |
31 |
int i; // index |
32 |
int sensor[5] = {IR4, IR3, IR2, IR1, IR5}; |
33 |
int color[5] = {RED, ORANGE, YELLOW, GREEN, BLUE}; |
34 |
int ret;
|
35 |
|
36 |
// flash orbs BLUE 3 times
|
37 |
for (i = 0; i < 3; i++) |
38 |
{ |
39 |
orb_set_color(BLUE); |
40 |
delay_ms(ON_DELAY); |
41 |
orb_set_color(ORB_OFF); |
42 |
delay_ms(OFF_DELAY); |
43 |
} |
44 |
|
45 |
for (i = 0; i < 5; i++) |
46 |
{ |
47 |
// indicate sensor under test
|
48 |
orb2_set_color(color[i]); |
49 |
|
50 |
// wait for sensor interaction
|
51 |
while ((ret = range_read_distance(sensor[i])) == -1) |
52 |
{ |
53 |
// stay RED until IR4 sees something
|
54 |
orb1_set_color(RED); |
55 |
if (ret == -3) // library not init'd |
56 |
{ |
57 |
while(1) |
58 |
{ |
59 |
orb2_set_color(GREEN); |
60 |
orb1_set_color(RED); |
61 |
delay_ms(250);
|
62 |
orb1_set_color(GREEN); |
63 |
orb2_set_color(RED); |
64 |
delay_ms(250);
|
65 |
} |
66 |
} |
67 |
} |
68 |
|
69 |
orb1_set_color(GREEN); |
70 |
delay_ms(TEST_TIME); |
71 |
} |
72 |
|
73 |
// flash orbs PURPLE 3 times
|
74 |
for (i = 0; i < 3; i++) |
75 |
{ |
76 |
orb_set_color(PURPLE); |
77 |
delay_ms(ON_DELAY); |
78 |
orb_set_color(ORB_OFF); |
79 |
delay_ms(OFF_DELAY); |
80 |
} |
81 |
|
82 |
return 0; |
83 |
} |
84 |
|