root / trunk / code / projects / test / test_rangefinder.c @ 1461
History | View | Annotate | Download (1.86 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 |
int i; // index |
31 |
int sensor[5] = {IR4, IR3, IR2, IR1, IR5}; |
32 |
int color[5] = {RED, ORANGE, YELLOW, GREEN, BLUE}; |
33 |
int ret;
|
34 |
|
35 |
// flash orbs BLUE 3 times
|
36 |
for (i = 0; i < 3; i++) { |
37 |
orb_set_color(BLUE); |
38 |
delay_ms(ON_DELAY); |
39 |
orb_set_color(ORB_OFF); |
40 |
delay_ms(OFF_DELAY); |
41 |
} |
42 |
|
43 |
for (i = 0; i < 5; i++) { |
44 |
// indicate sensor under test
|
45 |
orb2_set_color(color[i]); |
46 |
|
47 |
// wait for sensor interaction
|
48 |
while ((ret = range_read_distance(sensor[i])) == -1) { |
49 |
// stay RED until IR4 sees something
|
50 |
orb1_set_color(RED); |
51 |
if(ret == -3) { //library not init'd |
52 |
while(1) { |
53 |
orb2_set_color(GREEN); |
54 |
orb1_set_color(RED); |
55 |
delay_ms(250);
|
56 |
orb1_set_color(GREEN); |
57 |
orb2_set_color(RED); |
58 |
delay_ms(250);
|
59 |
} |
60 |
} |
61 |
} |
62 |
|
63 |
orb1_set_color(GREEN); |
64 |
delay_ms(TEST_TIME); |
65 |
} |
66 |
|
67 |
// flash orbs PURPLE 3 times
|
68 |
for (i = 0; i < 3; i++) { |
69 |
orb_set_color(PURPLE); |
70 |
delay_ms(ON_DELAY); |
71 |
orb_set_color(ORB_OFF); |
72 |
delay_ms(OFF_DELAY); |
73 |
} |
74 |
|
75 |
return 0; |
76 |
} |
77 |
|