root / trunk / code / projects / traffic_navigation / intersectData.c @ 1992
History | View | Annotate | Download (3.01 KB)
1 |
#include "intersectData.h" |
---|---|
2 |
#include "../linefollowing/lineDrive.h" |
3 |
|
4 |
int NodeData[NUM_FEATURES];
|
5 |
|
6 |
/*
|
7 |
* This function serves to make the code for the intersection database
|
8 |
* as reuseable as possible. This part creates the implementation of the
|
9 |
* database that can be copied over for all projects.
|
10 |
*
|
11 |
*/
|
12 |
|
13 |
// Does nothing if your indmax is out of bounds.
|
14 |
void insertNode(int key, int featureid, int intersect_num, int node_type, int node_info){ |
15 |
if(key < NUM_FEATURES)
|
16 |
NodeData[key] = (featureid<<12) + (intersect_num<<5) + (node_type<<2) + node_info; |
17 |
return;
|
18 |
} |
19 |
|
20 |
void insertIntersection(int key, int intersect_num, int node_type, int intersection_position){ |
21 |
if(key < NUM_FEATURES)
|
22 |
NodeData[key] = (INTERSECTION_NODE<<12) + (intersect_num<<5) + (node_type<<2) |
23 |
+ intersection_position; |
24 |
return;
|
25 |
} |
26 |
|
27 |
void insertRoad(int key, int intersect_num, int node_type, int road_type){ |
28 |
if(key < NUM_FEATURES)
|
29 |
NodeData[key] = (ROAD_NODE<<12) + (intersect_num<<5) + (node_type<<2) + road_type; |
30 |
return;
|
31 |
} |
32 |
|
33 |
/*
|
34 |
* This function serves to make the code for the intersection database
|
35 |
* as reuseable as possible. This part initializes the data and is the
|
36 |
* only one that needs to be rewritten for ech map.
|
37 |
*
|
38 |
*/
|
39 |
void initializeData(){
|
40 |
//insert all intersections that are in the map.
|
41 |
//THIS DATA FOR THE DEMO MAP
|
42 |
insertIntersection(0, UNUSED_INTER, 0, 0); |
43 |
insertIntersection(1, 1, SINGLE, SACROSS); |
44 |
insertIntersection(2, UNUSED_INTER, 0, 0); |
45 |
insertIntersection(3, 3, DOUBLE_C, CBOT); |
46 |
insertIntersection(4, UNUSED_INTER, 0, 0); |
47 |
insertIntersection(5, 5, DOUBLE_T, TMIDDLE); |
48 |
insertIntersection(6, 3, DOUBLE_C, CLEFT); |
49 |
insertIntersection(7, 5, DOUBLE_T, TRIGHT); |
50 |
insertIntersection(8, UNUSED_INTER, 0, 0); |
51 |
insertIntersection(9, 5, DOUBLE_T, TLEFT); |
52 |
insertIntersection(10, UNUSED_INTER, 0, 0); |
53 |
insertIntersection(11, 1, SINGLE, SUP); |
54 |
insertIntersection(12, UNUSED_INTER, 0, 0); |
55 |
insertIntersection(13, 2, SINGLE, SUP); |
56 |
insertIntersection(14, 3, DOUBLE_C, CRIGHT); |
57 |
insertIntersection(15, 3, DOUBLE_C, CTOP); |
58 |
insertIntersection(16, 2, SINGLE, SACROSS); |
59 |
return;
|
60 |
} |
61 |
|
62 |
// Functions to get data from the Database:
|
63 |
|
64 |
int getFeatureId(int key) |
65 |
{ |
66 |
if(key < NUM_FEATURES)
|
67 |
return (NodeData[key]>>12)&15; |
68 |
else return -1; |
69 |
} |
70 |
|
71 |
int getIntersectType(int key){ |
72 |
if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
|
73 |
return (NodeData[key]>>2)&7; |
74 |
else return -1; |
75 |
} |
76 |
|
77 |
int getIntersectPos(int key){ |
78 |
if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
|
79 |
return (NodeData[key])&3; |
80 |
else return -1; |
81 |
} |
82 |
|
83 |
int getRoadType(int key){ |
84 |
if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
|
85 |
return (NodeData[key]>>2)&7; |
86 |
else return -1; |
87 |
} |
88 |
|
89 |
int getRoadInfo(int key){ |
90 |
if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
|
91 |
return (NodeData[key])&3; |
92 |
else return -1; |
93 |
} |
94 |
|
95 |
int getIntersectNum(int key){ |
96 |
if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
|
97 |
return (NodeData[key]>>5)&127; |
98 |
else return -1; |
99 |
} |