root / trunk / code / projects / traffic_navigation / mapping.c @ 1980
History | View | Annotate | Download (3.84 KB)
1 |
#include "mapping.h" |
---|---|
2 |
#include "lineDrive.h" |
3 |
#include <dragonfly_lib.h> |
4 |
#include <wl_basic.h> |
5 |
|
6 |
//The last intersection that we encountered
|
7 |
int lastInt;
|
8 |
|
9 |
/* This array holds all of the intersections that are represented in the graph
|
10 |
* after its creation, the graph is transmitted wirelessly */
|
11 |
node intersections[NUM_FEATURES]; |
12 |
|
13 |
/*
|
14 |
* Traverses the map using DFS
|
15 |
* Returns 0 if all of the intersections in the database were seen
|
16 |
* 1 otherwise
|
17 |
*/
|
18 |
int createEdge(edge* newEdge){
|
19 |
char barcode;
|
20 |
char time;
|
21 |
rtc_init(SIXTEENTH_SECOND, NULL);
|
22 |
rtc_reset(); |
23 |
do
|
24 |
{ |
25 |
barcode = (char) doDrive(200); |
26 |
} while(barcode == NOBARCODE);
|
27 |
time = rtc_get(); |
28 |
newEdge->to = barcode; |
29 |
newEdge->dist = time; |
30 |
return 0; |
31 |
} |
32 |
|
33 |
int createMap(){
|
34 |
|
35 |
int seenout_count = 0; /* The number of intersections we have completely seen */ |
36 |
//int hist_count = 0; /* The size of our history stack */
|
37 |
|
38 |
char seen[NUM_FEATURES]; /* Have we seen this node? */ |
39 |
char seenout[NUM_FEATURES]; /* Have we seen the outoging edges of this node? */ |
40 |
|
41 |
int i;
|
42 |
int outEdges, currInt, chosenEdge;
|
43 |
|
44 |
|
45 |
/* Initialize all of these arrays */
|
46 |
for(i = 0; i<NUM_FEATURES; i++) { |
47 |
seen[i] = 0;
|
48 |
seenout[i] = 0;
|
49 |
intersections[i].type = 0;
|
50 |
intersections[i].intNum = 0;
|
51 |
intersections[i].numOut = 0;
|
52 |
intersections[i].outSeen = 0;
|
53 |
intersections[i].outgoingEdges[0].to = 0; |
54 |
intersections[i].outgoingEdges[0].dist = 0; |
55 |
intersections[i].outgoingEdges[1].to = 0; |
56 |
intersections[i].outgoingEdges[1].dist = 0; |
57 |
intersections[i].outgoingEdges[2].to = 0; |
58 |
intersections[i].outgoingEdges[2].dist = 0; |
59 |
intersections[i].outgoingEdges[3].to = 0; |
60 |
intersections[i].outgoingEdges[3].dist = 0; |
61 |
} |
62 |
|
63 |
|
64 |
/* Drives to the nearest intersection */
|
65 |
int barcode = nextInt();
|
66 |
|
67 |
while(seenout_count < NUM_FEATURES)
|
68 |
{ |
69 |
currInt = getIntersectNum(barcode); |
70 |
seen[currInt] = 1;
|
71 |
|
72 |
/* Get the number of outgoing edges */
|
73 |
outEdges = getNumOut(getIntersectType(currInt)); |
74 |
|
75 |
/* Randomly choose an outgoing edge that we have not seen to go down
|
76 |
* if no such edge exists */
|
77 |
// TODO: include the appropriate header file for rand()
|
78 |
chosenEdge = rand() % outEdges; |
79 |
|
80 |
/* We have not seen all the outgoing edges */
|
81 |
if(!seenout[currInt]){
|
82 |
intersections[currInt].outSeen++; |
83 |
/* We have finished seeing all outgoing edges of the intersection */
|
84 |
if(intersections[currInt].numOut == intersections[currInt].outSeen){
|
85 |
seenout[currInt] = 1;
|
86 |
seenout_count ++; |
87 |
} |
88 |
} |
89 |
/* Traverses edge, stores information in struct */
|
90 |
/* TODO: Define traverseEdge, then uncomment this line
|
91 |
traverseEdge(chosenEdge, &(intersections[currInt].outgoingEdges[chosenEdge])); */
|
92 |
} |
93 |
|
94 |
/* We are done traversing send the graph to the robots */
|
95 |
sendIntersectionGraph(); |
96 |
|
97 |
|
98 |
return 0; |
99 |
} |
100 |
|
101 |
/* Given an intersection type, returns the number of outgoing edges */
|
102 |
int getNumOut(int type) { |
103 |
switch(type){
|
104 |
case 0: |
105 |
return 0; |
106 |
case 1: |
107 |
return 1; |
108 |
case 2: |
109 |
return 2; |
110 |
case 3: |
111 |
return 3; |
112 |
case 4: |
113 |
return 4; |
114 |
} |
115 |
|
116 |
return -1; |
117 |
} |
118 |
|
119 |
|
120 |
/* Creates an edge in the graph */
|
121 |
int insertEdge(){
|
122 |
return 0; |
123 |
} |
124 |
|
125 |
|
126 |
/*
|
127 |
* Drives to the next intersection and returns its ID
|
128 |
* If we are at a dead end, returns -1
|
129 |
*/
|
130 |
int nextInt(){
|
131 |
return 0; |
132 |
} |
133 |
|
134 |
|
135 |
/*
|
136 |
* Given an intersection node returns an integer that
|
137 |
* can be sent wirelessly
|
138 |
*
|
139 |
*/
|
140 |
int encodeNode(node n){
|
141 |
return 0; |
142 |
} |
143 |
|