Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / test / test_rangefinder.c @ 1401

History | View | Annotate | Download (1.77 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
 * - Position robot facing you
13 1382 alevkoy
 * - Move hand in front of IR2
14 1381 alevkoy
 * - Observe orbs
15
 *
16
 * Expected Behavior:
17
 * - Orbs flash BLUE 3 times to signal start of test
18 1382 alevkoy
 * - 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 791 dsschult
 */
24
25 1381 alevkoy
#include <dragonfly_lib.h>
26 1067 nparis
27 1382 alevkoy
#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 1067 nparis
31 1383 alevkoy
int testrangefinder() {
32 1382 alevkoy
    int start_time; // rtc time when test starts
33
    int distance;    // rangefinder reading
34
    int i;  // index
35 1381 alevkoy
36
    // flash orbs BLUE 3 times
37
    for (i = 0; i < 3; i++) {
38
        orb_set_color(BLUE);
39 1382 alevkoy
        delay_ms(ON_DELAY);
40 1381 alevkoy
        orb_set_color(ORB_OFF);
41 1382 alevkoy
        delay_ms(OFF_DELAY);
42 1381 alevkoy
    }
43
44 1382 alevkoy
    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 1401 alevkoy
    while (1) {
50
        distance = range_read_distance(IR5);
51 1382 alevkoy
        // 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 1381 alevkoy
    }
61
62 1382 alevkoy
    // 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 1381 alevkoy
    return 0;
71 791 dsschult
}