Project

General

Profile

Revision 1414

Changed rangefinder unit test to use all orbs and not take forever.

View differences:

test_rangefinder.c
9 9
 **/
10 10

  
11 11
/* Testing Procedure
12
 * - Position robot facing you
13
 * - Move hand in front of IR2
12
 * - Place hand in front of orbs in 4, 3, 2, 1, 5 order
14 13
 * - Observe orbs
15 14
 *
16 15
 * Expected Behavior:
17 16
 * - Orbs flash BLUE 3 times to signal start of test
18 17
 * - 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
18
 *  - 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
22 20
 * - Orbs flash PURPLE 3 times to signal end of test
23 21
 */
24 22

  
25 23
#include <dragonfly_lib.h>
26 24

  
27
#define TEST_TIME 10	// duration of test (in s)
25
#define TEST_TIME 500	// duration of success indicator (in ms)
28 26
#define ON_DELAY 500	// duration of flashes at beginning and end (in ms)
29 27
#define OFF_DELAY 250	// delay between flashes at beginning and end (in ms)
30 28

  
31 29
int testrangefinder() {
32
    int start_time; // rtc time when test starts
33
    int distance;    // rangefinder reading
34 30
    int i;  // index
31
    int sensor[5] = {IR4, IR3, IR2, IR1, IR5};
32
    int color[5] = {RED, ORANGE, YELLOW, GREEN, BLUE};
35 33

  
36 34
    // flash orbs BLUE 3 times
37 35
    for (i = 0; i < 3; i++) {
......
41 39
	delay_ms(OFF_DELAY);
42 40
    }
43 41

  
44
    start_time = rtc_get(); // get test's start time
42
    for (i = 0; i < 5; i++) {
43
	// indicate sensor under test
44
	orb2_set_color(color[i]);
45 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);
46
	// wait for sensor interaction
47
	while (range_read_distance(sensor[i]) == -1)
48
	    // stay RED until IR4 sees something
49
	    orb1_set_color(RED);
50

  
51
	orb1_set_color(GREEN);
52
	delay_ms(TEST_TIME);
60 53
    }
61 54

  
62 55
    // flash orbs PURPLE 3 times

Also available in: Unified diff