root / trunk / code / projects / unit_tests / test_rangefinder.c @ 2009
History | View | Annotate | Download (2.17 KB)
1 | 791 | dsschult | /**
|
---|---|---|---|
2 | 1381 | alevkoy | * @file test_rangefinder.c
|
3 | * @brief Contains unit test for rangefinder.c module of libdragonfly
|
||
4 | 827 | dsschult | *
|
5 | 1381 | alevkoy | * 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 | 1414 | alevkoy | * - Place hand in front of orbs in 4, 3, 2, 1, 5 order
|
13 | 1381 | alevkoy | * - Observe orbs
|
14 | *
|
||
15 | * Expected Behavior:
|
||
16 | * - Orbs flash BLUE 3 times to signal start of test
|
||
17 | 1382 | alevkoy | * - During test
|
18 | 1414 | alevkoy | * - 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 | 1382 | alevkoy | * - Orbs flash PURPLE 3 times to signal end of test
|
21 | 791 | dsschult | */
|
22 | |||
23 | 1381 | alevkoy | #include <dragonfly_lib.h> |
24 | 1067 | nparis | |
25 | 1414 | alevkoy | #define TEST_TIME 500 // duration of success indicator (in ms) |
26 | 1382 | alevkoy | #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 | 1067 | nparis | |
29 | 1921 | alevkoy | int testrangefinder(void) |
30 | { |
||
31 | 1382 | alevkoy | int i; // index |
32 | 1414 | alevkoy | int sensor[5] = {IR4, IR3, IR2, IR1, IR5}; |
33 | int color[5] = {RED, ORANGE, YELLOW, GREEN, BLUE}; |
||
34 | 1461 | bneuman | int ret;
|
35 | 1381 | alevkoy | |
36 | // flash orbs BLUE 3 times
|
||
37 | 1921 | alevkoy | 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 | 1381 | alevkoy | } |
44 | |||
45 | 1921 | alevkoy | for (i = 0; i < 5; i++) |
46 | { |
||
47 | // indicate sensor under test
|
||
48 | orb2_set_color(color[i]); |
||
49 | 1382 | alevkoy | |
50 | 1921 | alevkoy | // 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 | 1414 | alevkoy | |
69 | 1921 | alevkoy | orb1_set_color(GREEN); |
70 | delay_ms(TEST_TIME); |
||
71 | 1381 | alevkoy | } |
72 | |||
73 | 1382 | alevkoy | // flash orbs PURPLE 3 times
|
74 | 1921 | alevkoy | 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 | 1382 | alevkoy | } |
81 | |||
82 | 1381 | alevkoy | return 0; |
83 | 791 | dsschult | } |