root / trunk / code / projects / test / test_rangefinder.c @ 1452
History | View | Annotate | Download (1.64 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 |
|
34 |
// flash orbs BLUE 3 times
|
35 |
for (i = 0; i < 3; i++) { |
36 |
orb_set_color(BLUE); |
37 |
delay_ms(ON_DELAY); |
38 |
orb_set_color(ORB_OFF); |
39 |
delay_ms(OFF_DELAY); |
40 |
} |
41 |
|
42 |
for (i = 0; i < 5; i++) { |
43 |
// indicate sensor under test
|
44 |
orb2_set_color(color[i]); |
45 |
|
46 |
// wait for sensor interaction
|
47 |
while (range_read_distance(sensor[i]) == -1) |
48 |
// stay RED until IR4 sees something
|
49 |
orb1_set_color(RED); |
50 |
|
51 |
orb1_set_color(GREEN); |
52 |
delay_ms(TEST_TIME); |
53 |
} |
54 |
|
55 |
// flash orbs PURPLE 3 times
|
56 |
for (i = 0; i < 3; i++) { |
57 |
orb_set_color(PURPLE); |
58 |
delay_ms(ON_DELAY); |
59 |
orb_set_color(ORB_OFF); |
60 |
delay_ms(OFF_DELAY); |
61 |
} |
62 |
|
63 |
return 0; |
64 |
} |
65 |
|