Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / hunter_prey / main.c @ 1374

History | View | Annotate | Download (1.28 KB)

1
#include <dragonfly_lib.h>
2
#include <wireless.h>
3

    
4
#define CHAN 0xF
5
#define TAG_TIME 3000
6
#define TAG_RANGE 150
7

    
8
int main(void) {
9

    
10
  int frontRange;
11
  uint8_t angle;
12
  uint8_t i;
13
  uint8_t isPrey = 0;
14
  int onTarget = 0;
15
  uint8_t color;
16
  
17
  //intialize the robot and wireless
18
  dragonfly_init(ALL_ON);
19
  wl_init();
20

    
21
  analog_init(1);
22

    
23
  bom_init(BOM15);
24

    
25
  //use a specific channel to avoid interfering with other tasks
26
  wl_set_channel(CHAN);
27

    
28
  orb_set_color(BLUE);
29
  color = BLUE;
30

    
31
  while(1) {
32

    
33
    bom_refresh(BOM_ALL);
34

    
35
    frontRange = range_read_distance (IR2);
36

    
37
    usb_puti(frontRange);
38
    usb_putc('\n');
39

    
40
    //BUG: when get_max_bom is called, the rangefinder seems to stop
41
    //working
42
    angle = get_max_bom();
43
    angle = 4;
44

    
45
    if(angle == 4 && frontRange > 0 && frontRange < TAG_RANGE) {
46
      if(onTarget == 0) {
47
        onTarget = TAG_TIME;
48
        if(color != GREEN) {
49
          color = GREEN;
50
          orb_set_color(GREEN);
51
        }
52
        usb_puts("On target!\n");
53
      }
54
      else {
55
        if(--onTarget <= 0) {
56
          orb_set_color(RED);
57
          color = RED;
58
          usb_puts("TAG!\n");
59
          while(1);
60
        }
61
      }
62
    }
63
    else{
64
      if(color != BLUE) {
65
        color = BLUE;
66
        orb_set_color(BLUE);
67
      }
68

    
69
      //don't reset onTarget because the robot got too close
70
      if(frontRange > 0)
71
        onTarget = 0;
72
    }
73

    
74

    
75
    wl_do();
76
  }
77

    
78
  return 0;
79
}