root / trunk / code / projects / test / test_rangefinder.c @ 1401
History | View | Annotate | Download (1.77 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 |
* - Position robot facing you
|
13 |
* - Move hand in front of IR2
|
14 |
* - Observe orbs
|
15 |
*
|
16 |
* Expected Behavior:
|
17 |
* - Orbs flash BLUE 3 times to signal start of test
|
18 |
* - During test
|
19 |
* - Orbs are GREEN when hand is at visible distance
|
20 |
* - Orbs are RED when hand is too close or too far to see
|
21 |
* - Orbs are never YELLOW
|
22 |
* - Orbs flash PURPLE 3 times to signal end of test
|
23 |
*/
|
24 |
|
25 |
#include <dragonfly_lib.h> |
26 |
|
27 |
#define TEST_TIME 10 // duration of test (in s) |
28 |
#define ON_DELAY 500 // duration of flashes at beginning and end (in ms) |
29 |
#define OFF_DELAY 250 // delay between flashes at beginning and end (in ms) |
30 |
|
31 |
int testrangefinder() {
|
32 |
int start_time; // rtc time when test starts |
33 |
int distance; // rangefinder reading |
34 |
int i; // index |
35 |
|
36 |
// flash orbs BLUE 3 times
|
37 |
for (i = 0; i < 3; i++) { |
38 |
orb_set_color(BLUE); |
39 |
delay_ms(ON_DELAY); |
40 |
orb_set_color(ORB_OFF); |
41 |
delay_ms(OFF_DELAY); |
42 |
} |
43 |
|
44 |
start_time = rtc_get(); // get test's start time
|
45 |
|
46 |
// orbs RED when IR2 reads -1
|
47 |
// orbs GREEN when IR2 gets a useable reading
|
48 |
// times out after TEST_TIME elapsed
|
49 |
while (1) { |
50 |
distance = range_read_distance(IR5); |
51 |
// unusable reading
|
52 |
if (distance == -1) |
53 |
orb_set_color(RED); |
54 |
// invalid reading
|
55 |
else if (distance < 101 || distance > 800) |
56 |
orb_set_color(YELLOW); |
57 |
// useable reading
|
58 |
else
|
59 |
orb_set_color(GREEN); |
60 |
} |
61 |
|
62 |
// flash orbs PURPLE 3 times
|
63 |
for (i = 0; i < 3; i++) { |
64 |
orb_set_color(PURPLE); |
65 |
delay_ms(ON_DELAY); |
66 |
orb_set_color(ORB_OFF); |
67 |
delay_ms(OFF_DELAY); |
68 |
} |
69 |
|
70 |
return 0; |
71 |
} |
72 |
|