Project

General

Profile

Statistics
| Revision:

root / branches / wireless / code / projects / unit_tests / test_rangefinder.c @ 1935

History | View | Annotate | Download (1.86 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 1452 dsschult
int testrangefinder(void) {
30 1382 alevkoy
    int i;  // index
31 1414 alevkoy
    int sensor[5] = {IR4, IR3, IR2, IR1, IR5};
32
    int color[5] = {RED, ORANGE, YELLOW, GREEN, BLUE};
33 1461 bneuman
    int ret;
34 1381 alevkoy
35
    // flash orbs BLUE 3 times
36
    for (i = 0; i < 3; i++) {
37
        orb_set_color(BLUE);
38 1382 alevkoy
        delay_ms(ON_DELAY);
39 1381 alevkoy
        orb_set_color(ORB_OFF);
40 1382 alevkoy
        delay_ms(OFF_DELAY);
41 1381 alevkoy
    }
42
43 1414 alevkoy
    for (i = 0; i < 5; i++) {
44
        // indicate sensor under test
45
        orb2_set_color(color[i]);
46 1382 alevkoy
47 1414 alevkoy
        // wait for sensor interaction
48 1461 bneuman
        while ((ret = range_read_distance(sensor[i])) == -1) {
49 1414 alevkoy
            // stay RED until IR4 sees something
50
            orb1_set_color(RED);
51 1461 bneuman
            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 1414 alevkoy
63
        orb1_set_color(GREEN);
64
        delay_ms(TEST_TIME);
65 1381 alevkoy
    }
66
67 1382 alevkoy
    // 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 1381 alevkoy
    return 0;
76 791 dsschult
}