Project

General

Profile

Revision 1958

Added more functionality to database for mapping things.

View differences:

trunk/code/projects/traffic_navigation/intersectData.h
1 1
#ifndef _NODE_DATABASE_
2 2
#define _NODE_DATABASE_
3 3

  
4
#define NUM_FEATURES 5
4
#define NUM_FEATURES 8
5 5

  
6 6

  
7 7
/****************************
8 8
 * Node Information: 5-bit Integer
9 9
 * 	3 bits of node type
10 10
 * 	2 bits of entry information
11
 * 	
12
 * Intersection Number stored in bits 6-12.
11 13
 *
12 14
 * Also contains a "feature id": 4 bits in positions 13,14,15,16
13 15
 * 
......
19 21
 *
20 22
 ********************************/
21 23
#define INTERSECTION_NODE	0
22
#define ROAD_NODE		1
24
#define ROAD_NODE			1
25
#define MAPPING_MARKER		NUM_FEATURES
26
//Used when mapping to signify return to previously visited intersection while driving on the wrong side of the road.
23 27
 
24 28
 /********************************
25 29
 *  Node TYPES:
......
30 34
 *  OFF_RAMP    2
31 35
 *  DOUBLE_C    3
32 36
 *  DOUBLE_T    4
33
 *
37
 *  ROAD		5
38
 * 
34 39
 ********************************/
35 40
 
36 41
 /********************************
37
 *  More Node TYPES:
38
 *
39
 ********************************/
40
#define ROAD	    5 
41
	/*placeholder for all roads atm, until we come up with a better solution */
42

  
43
 /********************************
44 42
 *  Turn TYPES:
45 43
 *  
46
 *  ISTRAIGHT		0
44
 *  ISTRAIGHT	0
47 45
 *  ILEFT		1
48 46
 *  IRIGHT		2
49 47
 *  IUTURN		3
......
64 62
 ********************************/
65 63

  
66 64
//DOUBLE_C intersection (Cross Intersection) positions
67
//use T-Junction positions
65
/*
66
	CTOP
67
	||
68
	||
69
	||
70
CLEFT=======CRIGHT
71
	||
72
	||
73
	||
74
	CBOT
75
*/
76
#define CTOP 0
77
#define CRIGHT 1
78
#define CBOT 2
79
#define CLEFT 3
68 80

  
69 81
//DOUBLE_T intersection (T-Junction) positions
70 82
/*
......
109 121
int NodeData[NUM_FEATURES];
110 122

  
111 123
void initializeData();
112
void insertNode(int key, int featureid, int node_type, int node_info);
113
void insertIntersection(int key, int intserction_type, int intersection_position);
114
void insertRoad(int key, int node_type, int road_type);
115 124

  
116 125
// Functions to get data from the Database:
117
int getFeatureId(int key);
118
int getIntersectType(int key);
119
int getIntersectPos(int key);
120
int getRoadType(int key);
121
int getRoadInfo(int key);
126
int getFeatureId(int key); //Returns value in Feature TYPES (see above)
127
int getIntersectType(int key); //Returns value in Node TYPE (values 0-4) (see above)
128
int getIntersectPos(int key); //Returns value in Intersect ENTRYPOINTS (see above)
129
int getRoadType(int key);  //Returns value in Node TYPE (values 5) (see above) 
130
int getRoadInfo(int key);  //Returns value in Road TYPES (see above) 
131
int getIntersectNum(int key); //Returns number of intersection
122 132

  
123 133
#endif
trunk/code/projects/traffic_navigation/intersectData.c
3 3

  
4 4
/*
5 5
 * This function serves to make the code for the intersection database
6
 * as reuseable as possible. This part initializes the data and is the
7
 * only one that needs to be rewritten for each map. 
8
 *
9
 */
10

  
11
void initializeData(){
12
	//insert all intersections that are in the map.
13
	//THIS DATA FOR THE DEMO MAP
14
	insertNode(0, INTERSECTION_NODE, DOUBLE_C, TMIDDLE);
15
	insertNode(1, ROAD_NODE, ROAD, ROAD_SINGLE);
16
	insertNode(2, INTERSECTION_NODE, DOUBLE_C, TMIDDLE);
17
	insertNode(4,ROAD_NODE,ROAD,HIGHWAY);
18
	insertNode(5,INTERSECTION_NODE,DOUBLE_C,TMIDDLE);	
19
	insertNode(8,ROAD_NODE,ROAD,ROAD_SINGLE);
20
	insertNode(10,ROAD_NODE,ROAD,ROAD_SINGLE);
21
	insertNode(16,INTERSECTION_NODE,DOUBLE_C, TMIDDLE);
22
	return;
23
}
24

  
25
/*
26
 * This function serves to make the code for the intersection database
27 6
 * as reuseable as possible. This part creates the implementation of the
28 7
 * database that can be copied over for all projects.  
29 8
 *
30 9
 */
31 10

  
32

  
33 11
// Does nothing if your indmax is out of bounds.
34
void insertNode(int key, int featureid, int node_type, int node_info){
35
//	if (key < sizeof(IntersectData)/sizeof(int))
12
void insertNode(int key, int featureid, int intersect_num, int node_type, int node_info){
36 13
	if(key < NUM_FEATURES)
37
	  NodeData[key] = (featureid<<12) + (node_type<<2) + node_info;
14
	  NodeData[key] = (featureid<<12) + (intersect_num<<5) + (node_type<<2) + node_info;
38 15
	return;
39 16
}
40 17

  
41
void insertIntersection(int key, int node_type, int intersection_position){
18
void insertIntersection(int key, int intersect_num, int node_type, int intersection_position){
42 19
	if(key < NUM_FEATURES)
43
	   NodeData[key] = (INTERSECTION_NODE<<12) + (node_type<<2)
20
	   NodeData[key] = (INTERSECTION_NODE<<12) + (intersect_num<<5) + (node_type<<2)
44 21
	       + intersection_position;
45 22
	return;
46 23
}
47 24

  
48
void insertRoad(int key, int node_type, int road_type){
25
void insertRoad(int key, int intersect_num, int node_type, int road_type){
49 26
	if(key < NUM_FEATURES)
50
	   NodeData[key] = (ROAD_NODE<<12) + (node_type<<2) + road_type;
27
	   NodeData[key] = (ROAD_NODE<<12) + (intersect_num<<5) + (node_type<<2) + road_type;
51 28
	return;
52 29
}
53 30

  
31
/*
32
 * This function serves to make the code for the intersection database
33
 * as reuseable as possible. This part initializes the data and is the
34
 * only one that needs to be rewritten for ech map. 
35
 *
36
 */
37
/**********************************************************************NEEDS TO BE FIXED*/
38
void initializeData(){
39
	//insert all intersections that are in the map.
40
	//THIS DATA FOR THE DEMO MAP
41
/*	insertNode(0, INTERSECTION_NODE, DOUBLE_C, TMIDDLE);
42
	insertNode(1, ROAD_NODE, ROAD, ROAD_SINGLE);
43
	insertNode(2, INTERSECTION_NODE, DOUBLE_C, TMIDDLE);
44
	insertNode(4,ROAD_NODE,ROAD,HIGHWAY);
45
	insertNode(5,INTERSECTION_NODE,DOUBLE_C,TMIDDLE);	
46
	insertNode(8,ROAD_NODE,ROAD,ROAD_SINGLE);
47
	insertNode(10,ROAD_NODE,ROAD,ROAD_SINGLE);
48
	insertNode(16,INTERSECTION_NODE,DOUBLE_C, TMIDDLE);
49
*/	return;
50
}
51

  
54 52
// Functions to get data from the Database:
55
//@TODO:Add some checks to make sure the key is less than NUM_FEATURES
56
//	also: figure out what to do when this happens.
57
//	Add checks to see if we call getIntersect...() on intersections
58
//	and getRoad...() on roads.
59 53

  
60 54
int getFeatureId(int key)
61 55
{
......
66 60

  
67 61
int getIntersectType(int key){
68 62
	if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
69
	  return (NodeData[key]>>2)&3;
63
		return (NodeData[key]>>2)&7;
70 64
	else return -1;
71 65
}
72 66

  
73 67
int getIntersectPos(int key){
74 68
	if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
75
	  return (NodeData[key])&3;
69
		return (NodeData[key])&3;
76 70
	else return -1;
77 71
}
78 72

  
79 73
int getRoadType(int key){
80 74
	if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
81
	  return (NodeData[key]>>2)&3;
75
		return (NodeData[key]>>2)&7;
82 76
	else return -1;
83 77
}
84 78

  
85 79
int getRoadInfo(int key){
86 80
	if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
87
	  return (NodeData[key])&3;
81
		return (NodeData[key])&3;
88 82
	else return -1;
89 83
}
90 84

  
85
int getIntersectNum(int key){
86
	if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE) 
87
		return (NodeData[key]>>5)&127;
88
	else return -1;
89
}
trunk/code/projects/traffic_navigation/validTurns.c
7 7
 *
8 8
 */
9 9

  
10

  
11
/******************************Random Num Gen Version of validTurns*/
12

  
13

  
14

  
15
#define GET16(s)( ((s)&0x8000)>>16 ) /*gets the 16 bit*/
16
#define GET14(s)( ((s)&0x2000)>>14 ) /*gets the 14thbit*/	
17
#define GET13(s)( ((s)&0x1000)>>13 ) /*you get the idea*/
18
#define GET11(s)( ((s)&0x400)>>11 )
19
#define CYCLES 10 /*the number of reseeds i perform before finally extracting my ranodm number*/
20
#define SHIFT(s)( (s)<<1)
21
#define RESEED(s)( (s)=( ( ((GET16(s)^GET14(s))^GET13(s))^GET11(s) ) | SHIFT(s) ) )/*reseeding the first bit of the number with bits from the number*/
22

  
23

  
10 24
unsigned int seed = 0xC0FFEE;
25
int randomNumGen(int max){
26
	int a = 0;
27
	int b = 0xBEEF;
28
	seed++;
29
	return seed%4;	
30
}
11 31

  
12
/******************************Random Num Gen Version of validTurns*/
13 32
/*
14 33
int randomNumGen(int max){
15 34
	return rtc_get() % max;

Also available in: Unified diff