Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.6 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
 * - Wait for initial BLUE flashes
14
 * - Position hand at ~12cm from leftmost, rearmost rangefinder (IR4)
15
 * - Sweep hand around front of robot, maintaining distance from rangefinders
16
 * - Observe orbs
17
 *
18
 * Expected Behavior:
19
 * - Orbs flash BLUE 3 times to signal start of test
20
 * - Orbs turn RED when IR4 gets a useable reading
21
 * - Orbs turn ORANGE when IR1 gets a useable reading
22
 * - Orbs turn YELLOW when IR2 gets a useable reading
23
 * - Orbs turn GREEN when IR3 gets a useable reading
24
 * - Orbs turn BLUE when IR5 gets a useable reading
25
 */
26

    
27
#include <dragonfly_lib.h>
28

    
29
#define delay 750   // delay between sensors (in ms)
30

    
31
int test_rangefinder() {
32
    uint8_t i, ir, color;   // plain old index, rangefinder index, color index
33
    int detectors[5] = {IR4, IR1, IR2, IR3, IR5};   // rangefinders L to R
34
    int colors[5] = {RED, ORANGE, YELLOW, GREEN, BLUE};        // colors of rainbow
35

    
36
    // flash orbs BLUE 3 times
37
    for (i = 0; i < 3; i++) {
38
        orb_set_color(BLUE);
39
        delay_ms(500);
40
        orb_set_color(ORB_OFF);
41
        delay_ms(250);
42
    }
43

    
44
    // show appropriate color when sensor gets a good read, then wait a second
45
    // do this for each sensor in left-to-right order
46
    for (ir = 1, color = 0; ir <= 5; ir++, color++) {
47
        while (range_read_distance(ir) == -1);
48
        orb_set_color(color);
49
        delay_ms(DELAY);
50
    }
51

    
52
    return 0;
53
}
54