Project

General

Profile

Revision 1382

Created rangefinder unit test.

View differences:

trunk/code/projects/test/test_rangefinder.c
10 10

  
11 11
/* Testing Procedure
12 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
13
 * - Move hand in front of IR2
16 14
 * - Observe orbs
17 15
 *
18 16
 * Expected Behavior:
19 17
 * - 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
18
 * - 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
25 23
 */
26 24

  
27 25
#include <dragonfly_lib.h>
28 26

  
29
#define delay 750   // delay between sensors (in ms)
27
#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 30

  
31 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
32
    int start_time; // rtc time when test starts
33
    int distance;    // rangefinder reading
34
    int i;  // index
35 35

  
36 36
    // flash orbs BLUE 3 times
37 37
    for (i = 0; i < 3; i++) {
38 38
	orb_set_color(BLUE);
39
	delay_ms(500);
39
	delay_ms(ON_DELAY);
40 40
	orb_set_color(ORB_OFF);
41
	delay_ms(250);
41
	delay_ms(OFF_DELAY);
42 42
    }
43 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);
44
    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
    while (rtc_get() - start_time < TEST_TIME) {
50
	distance = range_read_distance(IR2);
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);
50 60
    }
51 61

  
62
    // 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

  
52 70
    return 0;
53 71
}
54 72

  
trunk/code/projects/test/main.c
3 3
#define RUN_TEST(f) extern int f(void); f();
4 4

  
5 5
int main(void) {
6

  
7 6
  dragonfly_init(ALL_ON);
8 7

  
9
  while(1) {
10

  
11
    RUN_TEST(testusb);
12
    RUN_TEST(testanalog);
13
    //    RUN_TEST(testeeprom);
14
    RUN_TEST(testencoders);
15
    //    RUN_TEST(testlcd);
16
    RUN_TEST(testlights);
17
    RUN_TEST(testmotors);
18
    RUN_TEST(testrangefinder);
19
    RUN_TEST(testtokenring);
20

  
8
  while (1) {
9
    // RUN_TEST(testusb);
10
    // RUN_TEST(testanalog);
11
    // RUN_TEST(testeeprom);
12
    // RUN_TEST(testencoders);
13
    // RUN_TEST(testlcd);
14
    // RUN_TEST(testlights);
15
    // RUN_TEST(testmotors);
16
    RUN_TEST(test_rangefinder);
17
    // RUN_TEST(testtokenring);
21 18
  }
22 19

  
23 20
  return 0;

Also available in: Unified diff