Revision 1843
Added the traffic_navigation directory to projects in trunk, and inserted my preliminary main function. As of now, it relies on the linefollowing code in the other project directory.
main.c | ||
---|---|---|
1 |
/* |
|
2 |
* main.c for Traffic Navigation |
|
3 |
* Runs the highest level behavior for the Dynamic Traffic Navigation (DTM) SURG |
|
4 |
* |
|
5 |
* Author: Colony Project, CMU Robotics Club |
|
6 |
*/ |
|
7 |
|
|
1 | 8 |
#include <dragonfly_lib.h> |
9 |
#include <wl_basic.h> |
|
10 |
#include "../linefollowing/lineFollow.h" |
|
2 | 11 |
|
3 |
int main(void) |
|
4 |
{ |
|
12 |
/*States*/ |
|
13 |
#define SROAD 0 |
|
14 |
#define SINTERSECTION 10 |
|
15 |
#define SHIGHWAY 20 |
|
5 | 16 |
|
6 |
/* initialize components, set wireless channel */ |
|
7 |
dragonfly_init(ALL_ON); |
|
8 |
|
|
9 |
int val; |
|
17 |
/*Sign Codes |
|
18 |
* bitwise OR labels to create a barcode or read one |
|
19 |
* There should be macros to extract these probably |
|
20 |
* The bits will be stored in some variable (char or short) |
|
21 |
* Bits if road: ? ? ? NAME NAME NAME TYPE CROAD |
|
22 |
* Bits if intersection: ? ? ? ? DIR DIR #WAYS CINTERSECTION |
|
23 |
*/ |
|
24 |
#define CROAD 0x0 //0b |
|
25 |
#define CINTERSECTION 0x1 //1b |
|
26 |
#define CNORMALROAD 0x0 //00b |
|
27 |
#define CHIGHWAYROAD 0x2 //10b |
|
28 |
#define C4WAY 0x0 //00b |
|
29 |
#define C3WAY 0x2 //10b |
|
30 |
#define CNORTH 0x0 //0000b |
|
31 |
#define CEAST 0x4 //0100b |
|
32 |
#define CSOUTH 0x8 //1000b |
|
33 |
#define CWEST 0x12 //1100b |
|
10 | 34 |
|
11 |
while (1) { |
|
12 | 35 |
|
13 |
usb_puts("Val: "); |
|
14 |
usb_puti(range_read_distance(IR2)); |
|
15 |
usb_putc('\n'); |
|
36 |
int main (void) { |
|
16 | 37 |
|
17 |
delay_ms(200);
|
|
38 |
int state, sign;
|
|
18 | 39 |
|
40 |
/* Initialize the dragonfly boards, the xbee, encoders, lineFollowing */ |
|
41 |
dragonfly_init(ALL_ON); |
|
42 |
xbee_init(); |
|
43 |
encoders_init(); |
|
44 |
lineFollow_init(); |
|
45 |
|
|
46 |
sign = 0; |
|
47 |
|
|
48 |
while (1) { |
|
49 |
/*DTM Finite State Machine*/ |
|
50 |
switch(state){ |
|
51 |
case SROAD:/*Following a normal road*/ |
|
52 |
linefollow(); |
|
53 |
//other road behaviors |
|
54 |
//tailgating? |
|
55 |
//read barcode |
|
56 |
if(sign & CINTERSECTION){ |
|
57 |
state = SINTERSECTION; |
|
58 |
} |
|
59 |
break; |
|
60 |
case SINTERSECTION:/*Entering, and in intersection*/ |
|
61 |
//Intersection behaviors |
|
62 |
//queueing |
|
63 |
//no-stop? |
|
64 |
//check wireless |
|
65 |
//read barcode |
|
66 |
if(!(sign & CINTERSECTION)){ |
|
67 |
if(sign & CHIGHWAYROAD){ |
|
68 |
state = SHIGHWAY; |
|
69 |
}else{ |
|
70 |
state = SROAD; |
|
71 |
} |
|
72 |
} |
|
73 |
break; |
|
74 |
case SHIGHWAY:/*On highway*/ |
|
75 |
linefollow(); |
|
76 |
//highway behaviors |
|
77 |
//merging |
|
78 |
//passing |
|
79 |
//read barcode |
|
80 |
break; |
|
81 |
default: |
|
82 |
usb_puts("I got stuck in an unknown state! My state is "); |
|
83 |
usb_puti(state); |
|
84 |
} |
|
19 | 85 |
} |
20 | 86 |
|
21 |
return 0; |
|
22 | 87 |
} |
23 |
|
Also available in: Unified diff