root / scout / libscout / src / behaviors / trafficNavigation.h @ a8987cda
History | View | Annotate | Download (5.1 KB)
1 | 0e6831f5 | unknown | /**
|
---|---|---|---|
2 | * Copyright (c) 2011 Colony Project
|
||
3 | *
|
||
4 | * Permission is hereby granted, free of charge, to any person
|
||
5 | * obtaining a copy of this software and associated documentation
|
||
6 | * files (the "Software"), to deal in the Software without
|
||
7 | * restriction, including without limitation the rights to use,
|
||
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
9 | * copies of the Software, and to permit persons to whom the
|
||
10 | * Software is furnished to do so, subject to the following
|
||
11 | * conditions:
|
||
12 | *
|
||
13 | * The above copyright notice and this permission notice shall be
|
||
14 | * included in all copies or substantial portions of the Software.
|
||
15 | *
|
||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||
23 | * OTHER DEALINGS IN THE SOFTWARE.
|
||
24 | */
|
||
25 | |||
26 | #ifndef _trafficNavigation_H_
|
||
27 | #define _trafficNavigation_H_
|
||
28 | |||
29 | #include "../Behavior.h" |
||
30 | |||
31 | //from old trafficNavigation.h
|
||
32 | #ifndef trafficNavigation_H
|
||
33 | |||
34 | /* Debug Options - These must go before includes */
|
||
35 | #define MAIN_NEW
|
||
36 | //#define SENDGRAPH
|
||
37 | |||
38 | #include <dragonfly_lib.h> |
||
39 | #include <wl_basic.h> |
||
40 | #include "../linefollowing/lineDrive.h" |
||
41 | #include "highways.h" |
||
42 | #include "intersectData.h" |
||
43 | #include "validTurns.h" |
||
44 | |||
45 | /*States*/
|
||
46 | #define SROAD 0 |
||
47 | #define SINTERSECTION 9 /* for old version */ |
||
48 | #define SINTERSECTION_ENTER 10 |
||
49 | #define SINTERSECTION_ENTER_RESOLV 11 |
||
50 | #define SINTERSECTION_WAIT 12 |
||
51 | #define SINTERSECTION_DRIVE 13 |
||
52 | #define SHIGHWAY 20 |
||
53 | #define SCLEARPACKET 30 |
||
54 | |||
55 | /*Sign Codes
|
||
56 | * bitwise OR labels to create a barcode or read one
|
||
57 | * There should be macros to extract these probably
|
||
58 | * The bits will be stored in some variable (char or short)
|
||
59 | * Bits if road: ? ? ? NAME NAME NAME TYPE CROAD
|
||
60 | * Bits if intersection: ? ? ? ? DIR DIR #WAYS CINTERSECTION
|
||
61 | */
|
||
62 | #define CROAD 0x0 //0b |
||
63 | #define CINTERSECTION 0x1 //1b |
||
64 | #define CNORMALROAD 0x0 //00b |
||
65 | #define CHIGHWAYROAD 0x2 //10b |
||
66 | #define C4WAY 0x0 //00b |
||
67 | #define C3WAY 0x2 //10b |
||
68 | #define CNORTH 0x0 //0000b |
||
69 | #define CEAST 0x4 //0100b |
||
70 | #define CSOUTH 0x8 //1000b |
||
71 | #define CWEST 0x12 //1100b |
||
72 | |||
73 | /*Wireless Packet Types
|
||
74 | * The first byte of any wireless packet should be one of these types.
|
||
75 | * Each type will have its own structure
|
||
76 | * The second byte should be the id of the bot sending the packet
|
||
77 | * The third byte should be the number of the intersection or road that
|
||
78 | * the packet pertains to
|
||
79 | */
|
||
80 | #define PACKET_LENGTH 5 |
||
81 | #define WROADENTRY 0 //[type, bot, road] |
||
82 | #define WROADREPLY 1 //[type, fromBot, road, toBot] |
||
83 | #define WROADEXIT 2 //[type, bot, road] |
||
84 | #define WROADSTOP 3 //[type, bot, road] |
||
85 | #define WINTERSECTIONENTRY 10 //[type, bot, intersection, fromDir, toDir] |
||
86 | #define WINTERSECTIONREPLY 11 //[type, fromBot, intersection, toBot] |
||
87 | #define WINTERSECTIONEXIT 12 //[type, bot, intersection] |
||
88 | #define WINTERSECTIONGO 13 //[type, bot, intersection] |
||
89 | #define WINTERSECTIONPOLICEENTRY 14 |
||
90 | #define WINTERSECTIONRESOLVERACE 15 //[type, bot, intersection, num] |
||
91 | #define WHIGHWAYENTRY 20 //[type, bot, highway] |
||
92 | #define WHIGHWAYREPLY 21 //[type, fromBot, highway, toBot] |
||
93 | #define WHIGHWAYEXIT 22 //[type, bot, highway] |
||
94 | #define WPINGGLOBAL 30 //[type, bot] |
||
95 | #define WPINGBOT 31 //[type, fromBot, toBot] |
||
96 | #define WPINGQUEUE 32 //[type, fromBot, toBot] |
||
97 | #define WPINGREPLY 33 //[type, fromBot, toBot] |
||
98 | #define WCOLLISIONAVOID 41 //[type, bot, intersection, collision-int] //Note: collision is an int and thus takes two spaces |
||
99 | #define WGRAPHDATA 80 |
||
100 | |||
101 | /*Wireless Parsing Status
|
||
102 | * For wireless parsing - status codes describing various errors/statuses with wireless
|
||
103 | * parsing.
|
||
104 | * Errors begin with E - Note that all of these errors are actually returned as negative.
|
||
105 | * - values of >= 100 indicate a serious error
|
||
106 | * Non-Errors begin with K - returned as positive. (don't start with S because S
|
||
107 | * is for state)
|
||
108 | */
|
||
109 | #define ENOPACKET -10 //The received packet doesn't exist. |
||
110 | #define ENOACTION -15 //The received packet has no defined action, and this is OK |
||
111 | #define ENOIMPLEMENT -20 //The received packet has no defined action and needs to be implemented. |
||
112 | #define EPACKETLEN -100 //The received packet was the wrong length |
||
113 | #define KOK 1 |
||
114 | #define KPLACEDINQUEUE 20 |
||
115 | #define KFAILEDTOQUEUE 21 |
||
116 | #define KFIRSTINQUEUE 22 |
||
117 | #define KREPLIEDTOENTER 23 |
||
118 | #define KRESOLVINGENTER 24 //resolving a race between bots trying to enter intersection at the same time. |
||
119 | |||
120 | /*Macros
|
||
121 | */
|
||
122 | #define ISPING(p) ((p)[0]==WPINGGLOBAL || (p)[0]==WPINGBOT || (p)[0]==WPINGQUEUE) |
||
123 | |||
124 | #endif
|
||
125 | //
|
||
126 | |||
127 | #ifdef DEBUG_INTERSECTION
|
||
128 | #define DBG_USBS(str) usb_puts(str)
|
||
129 | #define DBG_USBI(x) usb_puti(x)
|
||
130 | #else
|
||
131 | #define DBG_USBS(str)
|
||
132 | #define DBG_USBI(x)
|
||
133 | #endif
|
||
134 | |||
135 | |||
136 | class trafficNavigation : Behavior |
||
137 | { |
||
138 | public:
|
||
139 | 31be19a6 | Priya | trafficNavigation(std::string scoutname) : Behavior(scoutname, "traffic_nav") {};
|
140 | 0e6831f5 | unknown | |
141 | void run();
|
||
142 | int wirelessPacketHandle(int state); |
||
143 | void enterIntersection(void); |
||
144 | void sendResolv(bool override); |
||
145 | unsigned char resolvRandomNumberGen(); |
||
146 | }; |
||
147 | |||
148 | #endif |