Project

General

Profile

Revision 1966

Added test map data encoding to intersectData.c. Fixe a whole bunch of stuff so
that at least this traffic_navigation compiles without warnings. Symlinked to
needed files in linefollow. Changed function declaration style. Added
delclaration of read_line to analog.h. You're welcome. Fixed several #includes.
You're all welcome.

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 8
4
#define NUM_FEATURES 17
5 5

  
6 6

  
7 7
/****************************
8 8
 * Node Information: 5-bit Integer
9
 * 	3 bits of node type
10
 * 	2 bits of entry information
11
 * 	
9
 *     3 bits of node type
10
 *     2 bits of entry information
11
 *     
12 12
 * Intersection Number stored in bits 6-12.
13 13
 *
14 14
 * Also contains a "feature id": 4 bits in positions 13,14,15,16
......
20 20
 *  Feature TYPES:
21 21
 *
22 22
 ********************************/
23
#define INTERSECTION_NODE	0
24
#define ROAD_NODE			1
25
#define MAPPING_MARKER		NUM_FEATURES
23
#define INTERSECTION_NODE   0
24
#define ROAD_NODE           1
25
#define MAPPING_MARKER      NUM_FEATURES
26 26
//Used when mapping to signify return to previously visited intersection while driving on the wrong side of the road.
27 27
 
28 28
 /********************************
......
34 34
 *  OFF_RAMP    2
35 35
 *  DOUBLE_C    3
36 36
 *  DOUBLE_T    4
37
 *  ROAD		5
37
 *  ROAD        5
38 38
 * 
39 39
 ********************************/
40 40
 
41 41
 /********************************
42 42
 *  Turn TYPES:
43 43
 *  
44
 *  ISTRAIGHT	0
45
 *  ILEFT		1
46
 *  IRIGHT		2
47
 *  IUTURN		3
44
 *  ISTRAIGHT   0
45
 *  ILEFT       1
46
 *  IRIGHT      2
47
 *  IUTURN      3
48 48
 *
49 49
 ********************************/
50 50

  
......
52 52
 *  Road TYPES:
53 53
 *
54 54
 ********************************/
55
#define ROAD_DOUBLE	0
56
#define ROAD_SINGLE	1
57
#define HIGHWAY		2
55
#define ROAD_DOUBLE     0
56
#define ROAD_SINGLE     1
57
#define HIGHWAY         2
58 58

  
59 59
/********************************
60 60
 *  Intersection ENTRYPOINTS:
......
63 63

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

  
81 81
//DOUBLE_T intersection (T-Junction) positions
82 82
/*
83 83
TLEFT=======TRIGHT
84
	||
85
	||
86
	||
87
	TMIDDLE
84
    ||
85
    ||
86
    ||
87
    TMIDDLE
88 88
*/
89
#define TLEFT		0			
90
#define TRIGHT		1			
91
#define TMIDDLE		2
89
#define TLEFT       0
90
#define TRIGHT      1
91
#define TMIDDLE     2
92 92

  
93 93
//SINGLE intersection positions
94 94
/*
95
	   /\
96
	  /||\
97
	   ||
95
       /\
96
      /||\
97
       ||
98 98
SACROSS==========>
99
	   ||
100
	   ||
101
	   ||
102
	   SUP
99
       ||
100
       ||
101
       ||
102
       SUP
103 103
*/
104
#define SACROSS		0
105
#define SUP		1
104
#define SACROSS     0
105
#define SUP         1
106 106

  
107 107

  
108 108
//ON_RAMP and OFF_RAMP intersection positions
109 109
/*
110 110
R_LEFT================R_RIGHT
111
	    ||	
112
	    ||
113
	    ||
114
	  R_RAMP
111
        ||
112
        ||
113
        ||
114
      R_RAMP
115 115
*/
116
#define R_LEFT		0
117
#define R_RIGHT		1
118
#define R_RAMP		2
116
#define R_LEFT    0
117
#define R_RIGHT   1
118
#define R_RAMP    2
119 119

  
120 120
// Global variable for the intersection database.
121
int NodeData[NUM_FEATURES];
121
extern int NodeData[NUM_FEATURES];
122 122

  
123
void initializeData();
123
void initializeData(void);
124 124

  
125 125
// Functions to get data from the Database:
126 126
int getFeatureId(int key); //Returns value in Feature TYPES (see above)
trunk/code/projects/traffic_navigation/traffic_navigation.h
2 2

  
3 3
#include <dragonfly_lib.h>
4 4
#include <wl_basic.h>
5
#include "lineDrive.h"
5
#include "../linefollowing/lineDrive.h"
6 6
#include "highways.h"
7 7
#include "intersectData.h"
8 8
#include "validTurns.h"
trunk/code/projects/traffic_navigation/validTurns-test.c
1
#include <dragonfly_lib.h>
2
#include "intersectData.h"
3
#include "validTurns.h"
4
#include "lineDrive.h"
5

  
6
//#define TEST_VALIDTURNS
7

  
8
#ifdef TEST_VALIDTURNS
9

  
10
int main(){
11

  
12
	dragonfly_init(ALL_ON);
13
	orb1_set_color(YELLOW);
14

  
15
	initializeData();	
16
	
17
	if (getTurnIntType(INTERSECTION_DOUBLE_C) == DOUBLE) orb1_set_color(GREEN);
18

  
19
	delay_ms(500);
20
	orb1_set_color(PINK);
21
	delay_ms(500);
22

  
23
	if (getTurnIntType(INTERSECTION_DOUBLE_T) == DOUBLE) orb1_set_color(GREEN);
24

  
25
	delay_ms(500);
26
	orb1_set_color(BLUE);
27
	delay_ms(500);
28

  
29
	if (getTurnIntType(INTERSECTION_SINGLE) == SINGLE) orb1_set_color(GREEN);
30

  
31
	delay_ms(500);
32
	orb1_set_color(PINK);
33
	delay_ms(500);
34

  
35
	if (getTurnIntType(INTERSECTION_ON_RAMP) == ON_RAMP) orb1_set_color(GREEN);
36

  
37
	delay_ms(500);
38
	orb1_set_color(BLUE);
39
	delay_ms(500);
40

  
41
	if( getTurnIntType(getIntersectType(0)) == DOUBLE) orb1_set_color(GREEN);
42

  
43
	delay_ms(500);
44
	orb1_set_color(PINK);
45
	delay_ms(500);
46

  
47
/*****************************TEST FOR validTurns.c
48
	int barcode = 0;
49
	
50
	if (validateTurn(barcode, ILEFT)==ILEFT) orb1_set_color(GREEN);
51

  
52
	delay_ms(100);
53
	orb1_set_color(PINK);
54
	delay_ms(50);
55

  
56
	if (validateTurn(barcode, IUTURN)==IUTURN) orb1_set_color(GREEN);
57
	
58
	delay_ms(100);
59
	orb1_set_color(RED);
60
	delay_ms(50);
61
*/
62
	while (1){}
63

  
64
}
65

  
66
#endif
trunk/code/projects/traffic_navigation/lineFollow.c
1
link ../linefollowing/lineFollow.c
0 2

  
trunk/code/projects/traffic_navigation/collision_avoid.c
6 6
 *    (because some bot at another intersection entrance may be able to go before another bot at another
7 7
 *    intersection entrance, but their order in the queue may not allow this.).
8 8
*/
9

  
9 10
#include "collision_avoid.h"
10 11
#include "traffic_navigation.h"
12
#include "../linefollowing/lineDrive.h"
13

  
11 14
static unsigned int my_path = 0;
12 15
static unsigned int first_hop = 0;
13 16
static char intersection = 0;
......
108 111
 *
109 112
 * All this function does is clear some variables. I guess
110 113
 * this is optional but it is nice for debugging. */
111
void ca_ExitIntersection(){
114
void ca_ExitIntersection(void){
112 115
	my_path = 0;
113 116
	first_hop = -1; 
114 117
	intersection = -1;
trunk/code/projects/traffic_navigation/lineFollow.h
1
link ../linefollowing/lineFollow.h
0 2

  
trunk/code/projects/traffic_navigation/lineDrive.c
1
link ../linefollowing/lineDrive.c
0 2

  
trunk/code/projects/traffic_navigation/highways.c
1 1
#include "highways.h"
2
#include "lineDrive.h"
2
#include "../linefollowing/lineDrive.h"
3 3
#include <dragonfly_lib.h>
4 4

  
5
static int changeLanes(void);   // declared here to preserve static status
6

  
5 7
int counti =0;
6 8
long averagei = 0;
7 9
int states = 0;
......
10 12
void highwayStart(){
11 13
	canMerge = 1;
12 14
}
13
static int changeLanes(){
15

  
16
static int changeLanes()
17
{
14 18
        if(counti<10000){
15 19
		counti++;
16 20
		motor_r_set(FORWARD,232);
......
28 32
	counti = 0;
29 33
	return 1;
30 34
}
35

  
31 36
int highwayFSM(){
32 37
	switch(states){
33 38
	
trunk/code/projects/traffic_navigation/main.c
6 6
 */
7 7

  
8 8
#include "traffic_navigation.h"
9
#include "../linefollowing/lineDrive.h"
9 10

  
10 11
	static int state, sign, dataLength, pingWaitTime, turnDir;
11 12
	static char sendBuffer[PACKET_LENGTH], prevBot, nextBot, id, nextDir, nextPath, intersectionNum;
12 13
	static unsigned char *packet;
13 14

  
14 15
	void enterIntersectionQueue(int sign);
15
	void waitInIntersectionQueue();
16
	void waitInIntersectionQueue(void);
16 17
	void driveThroughIntersection(int sign);
17 18
	
18 19
int main (void) {
trunk/code/projects/traffic_navigation/lineDrive.h
1
link ../linefollowing/lineDrive.h
0 2

  
trunk/code/projects/traffic_navigation/intersectData.c
1 1
#include "intersectData.h"
2
#include "lineDrive.h"
2
#include "../linefollowing/lineDrive.h"
3 3

  
4
int NodeData[NUM_FEATURES];
5

  
4 6
/*
5 7
 * This function serves to make the code for the intersection database
6 8
 * as reuseable as possible. This part creates the implementation of the
......
10 12

  
11 13
// Does nothing if your indmax is out of bounds.
12 14
void insertNode(int key, int featureid, int intersect_num, int node_type, int node_info){
13
	if(key < NUM_FEATURES)
14
	  NodeData[key] = (featureid<<12) + (intersect_num<<5) + (node_type<<2) + node_info;
15
	return;
15
    if(key < NUM_FEATURES)
16
      NodeData[key] = (featureid<<12) + (intersect_num<<5) + (node_type<<2) + node_info;
17
    return;
16 18
}
17 19

  
18 20
void insertIntersection(int key, int intersect_num, int node_type, int intersection_position){
19
	if(key < NUM_FEATURES)
20
	   NodeData[key] = (INTERSECTION_NODE<<12) + (intersect_num<<5) + (node_type<<2)
21
	       + intersection_position;
22
	return;
21
    if(key < NUM_FEATURES)
22
       NodeData[key] = (INTERSECTION_NODE<<12) + (intersect_num<<5) + (node_type<<2)
23
           + intersection_position;
24
    return;
23 25
}
24 26

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

  
31 33
/*
......
34 36
 * only one that needs to be rewritten for ech map. 
35 37
 *
36 38
 */
37
/**********************************************************************NEEDS TO BE FIXED*/
38 39
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;
40
    //insert all intersections that are in the map.
41
    //THIS DATA FOR THE DEMO MAP
42
    insertIntersection(0, 1, SINGLE, SACROSS);
43
    insertIntersection(1, 1, SINGLE, SUP);
44
    insertIntersection(2, 2, SINGLE, SUP);
45
    insertIntersection(3, 2, SINGLE, SACROSS);
46
    insertIntersection(4, 3, DOUBLE_C, CLEFT);
47
    insertIntersection(5, 3, DOUBLE_C, CTOP);
48
    insertIntersection(6, 3, DOUBLE_C, CRIGHT);
49
    insertIntersection(7, 3, DOUBLE_C, CBOT);
50
    insertIntersection(8, 5, DOUBLE_T, TLEFT);
51
    insertIntersection(9, 5, DOUBLE_T, TMIDDLE);
52
    insertIntersection(10, 5, DOUBLE_T, TRIGHT);
53
    insertIntersection(11, 6, ON_RAMP, R_LEFT);
54
    insertIntersection(12, 6, ON_RAMP, R_RAMP);
55
    insertIntersection(13, 6, ON_RAMP, R_RIGHT);
56
    insertIntersection(14, 4, OFF_RAMP, R_RIGHT);
57
    insertIntersection(15, 4, OFF_RAMP, R_RAMP);
58
    insertIntersection(16, 4, OFF_RAMP, R_LEFT);
59
    return;
50 60
}
51 61

  
52 62
// Functions to get data from the Database:
53 63

  
54 64
int getFeatureId(int key)
55 65
{
56
	if(key < NUM_FEATURES)
57
	  return (NodeData[key]>>12)&15;
58
	else return -1;
66
    if(key < NUM_FEATURES)
67
      return (NodeData[key]>>12)&15;
68
    else return -1;
59 69
}
60 70

  
61 71
int getIntersectType(int key){
62
	if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
63
		return (NodeData[key]>>2)&7;
64
	else return -1;
72
    if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
73
    	return (NodeData[key]>>2)&7;
74
    else return -1;
65 75
}
66 76

  
67 77
int getIntersectPos(int key){
68
	if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
69
		return (NodeData[key])&3;
70
	else return -1;
78
    if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
79
    	return (NodeData[key])&3;
80
    else return -1;
71 81
}
72 82

  
73 83
int getRoadType(int key){
74
	if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
75
		return (NodeData[key]>>2)&7;
76
	else return -1;
84
    if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
85
    	return (NodeData[key]>>2)&7;
86
    else return -1;
77 87
}
78 88

  
79 89
int getRoadInfo(int key){
80
	if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
81
		return (NodeData[key])&3;
82
	else return -1;
90
    if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
91
    	return (NodeData[key])&3;
92
    else return -1;
83 93
}
84 94

  
85 95
int getIntersectNum(int key){
86
	if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE) 
87
		return (NodeData[key]>>5)&127;
88
	else return -1;
96
    if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE) 
97
    	return (NodeData[key]>>5)&127;
98
    else return -1;
89 99
}
trunk/code/projects/traffic_navigation/validTurns.c
10 10

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

  
13
#include "intersectData.h"
14
#include "../linefollowing/lineDrive.h"
15
#include "validTurns.h"
13 16

  
14

  
15 17
#define GET16(s)( ((s)&0x8000)>>16 ) /*gets the 16 bit*/
16 18
#define GET14(s)( ((s)&0x2000)>>14 ) /*gets the 14thbit*/	
17 19
#define GET13(s)( ((s)&0x1000)>>13 ) /*you get the idea*/
......
20 22
#define SHIFT(s)( (s)<<1)
21 23
#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 24

  
23

  
24
unsigned int seed = 0xC0FFEE;
25
unsigned int seed = 0xC0DE;
25 26
int randomNumGen(int max){
26
	int a = 0;
27
	int b = 0xBEEF;
27
	//int a = 0;    // not currently in use
28
	//int b = 0xBEEF;
28 29
	seed++;
29 30
	return seed%4;	
30 31
}
......
33 34
int randomNumGen(int max){
34 35
	return rtc_get() % max;
35 36
}
36
*/
37 37
int randomNumGen(int max){
38 38
	int a = 1337;
39 39
	int b = 0xDEADBEEF;
40 40
	seed++;
41 41
	return seed%max;	
42 42
}
43
*/
43 44

  
44

  
45 45
/*
46 46
int getIntersectType(int barcode)
47 47
{
......
53 53
	return randomNumGen(max);
54 54
}
55 55
*/
56

  
56 57
int getTurnType(int barcode)
57 58
{
58 59
	return randomNumGen(4);
59 60
}
60 61

  
61

  
62
#include "intersectData.h"
63
#include "lineDrive.h"
64
#include "validTurns.h"
65

  
66 62
int validateTurn(int barcode, int turn_type)
67 63
{
68 64
	int intersect_type;
......
177 173
			}
178 174
		break;
179 175
		}
180
	default:
181
		return -1;
176
        default:
177
            return -1;
178
    }
179

  
180
    return -1;
182 181
}
183
}

Also available in: Unified diff