root / trunk / code / projects / hunter_prey / main.c @ 1373
History | View | Annotate | Download (1.26 KB)
1 | 1373 | bneuman | #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 | bom_init(BOM15); |
||
21 | |||
22 | //use a specific channel to avoid interfering with other tasks
|
||
23 | wl_set_channel(CHAN); |
||
24 | |||
25 | orb_set_color(BLUE); |
||
26 | color = BLUE; |
||
27 | |||
28 | while(1) { |
||
29 | |||
30 | bom_refresh(BOM_ALL); |
||
31 | |||
32 | frontRange = range_read_distance (IR2); |
||
33 | |||
34 | usb_puti(frontRange); |
||
35 | usb_putc('\n');
|
||
36 | |||
37 | //BUG: when get_max_bom is called, the rangefinder seems to stop
|
||
38 | //working
|
||
39 | angle = get_max_bom(); |
||
40 | angle = 4;
|
||
41 | |||
42 | if(angle == 4 && frontRange > 0 && frontRange < TAG_RANGE) { |
||
43 | if(onTarget == 0) { |
||
44 | onTarget = TAG_TIME; |
||
45 | if(color != GREEN) {
|
||
46 | color = GREEN; |
||
47 | orb_set_color(GREEN); |
||
48 | } |
||
49 | usb_puts("On target!\n");
|
||
50 | } |
||
51 | else {
|
||
52 | if(--onTarget <= 0) { |
||
53 | orb_set_color(RED); |
||
54 | color = RED; |
||
55 | usb_puts("TAG!\n");
|
||
56 | while(1); |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | else{
|
||
61 | if(color != BLUE) {
|
||
62 | color = BLUE; |
||
63 | orb_set_color(BLUE); |
||
64 | } |
||
65 | |||
66 | //don't reset onTarget because the robot got too close
|
||
67 | if(frontRange > 0) |
||
68 | onTarget = 0;
|
||
69 | } |
||
70 | |||
71 | |||
72 | wl_do(); |
||
73 | } |
||
74 | |||
75 | return 0; |
||
76 | } |