Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / traffic_navigation / validTurns.c @ 1929

History | View | Annotate | Download (2.91 KB)

1
/*
2
 * Deterministic turning implemented using table lookup. Using a
3
 * table, the function looks up a value from the table using the 
4
 * barcode value, and then the robot decides to go straight, 
5
 * left, right, or u-turn depending on the valid turn types
6
 * for the intersection it is at.
7
 *
8
 */
9

    
10
unsigned int seed = 0xC0FFEE;
11

    
12
/******************************Random Num Gen Version of validTurns*/
13
/*
14
int randomNumGen(int max){
15
        return rtc_get() % max;
16
}
17
*/
18
int randomNumGen(int max){
19
        int a = 1337;
20
        int b = 0xDEADBEEF;
21
        seed++;
22
        return seed%max;        
23
}
24

    
25

    
26
/*
27
int getIntersectType(int barcode)
28
{
29
        return randomNumGen(5);
30
}
31

32
int getIntersectPos(int barcode, int max)
33
{
34
        return randomNumGen(max);
35
}
36
*/
37
int getTurnType(int barcode)
38
{
39
        return randomNumGen(4);
40
}
41

    
42

    
43
#include "intersectData.h"
44
#include "lineDrive.h"
45
#include "validTurns.h"
46

    
47
int validateTurn(int barcode, int turn_type)
48
{
49
        int intersect_type;
50
        int intersect_pos;
51
        intersect_type = getIntersectType(barcode);
52
        switch (intersect_type)
53
        {
54
                case DOUBLE_C:
55
                {
56
                        intersect_pos = getIntersectPos(barcode);
57
                        if (0<=intersect_pos && intersect_pos<=3)
58
                        return turn_type;
59
                break;
60
                }
61
                case DOUBLE_T:
62
                {
63
                        intersect_pos = getIntersectPos(barcode);
64
                        switch (intersect_pos)
65
                        {
66
                                case TLEFT:
67
                                {
68
                                        if (turn_type == ILEFT) turn_type = ISTRAIGHT;
69
                                        return turn_type;        
70
                                break;
71
                                }
72
                                case TRIGHT:
73
                                {
74
                                        if (turn_type == IRIGHT) turn_type = ISTRAIGHT;
75
                                        return turn_type;                        
76
                                break;
77
                                }
78
                                case TMIDDLE:
79
                                {
80
                                        if (turn_type == ISTRAIGHT) turn_type = IUTURN;
81
                                        return turn_type;
82
                                break;
83
                                }
84
                                default:
85
                                        return -1;
86
                        }
87
                        break;
88
                }
89
                case SINGLE:
90
                {
91
                        intersect_pos = getIntersectPos(barcode);
92
                        switch (intersect_pos)
93
                        {
94
                                case SACROSS:
95
                                {
96
                                        if (turn_type == IRIGHT || turn_type == IUTURN) turn_type = ISTRAIGHT;
97
                                        return turn_type;        
98
                                break;
99
                                }
100
                                case SUP:
101
                                {
102
                                        if (turn_type == ILEFT || turn_type == IUTURN) turn_type = ISTRAIGHT;
103
                                        return turn_type;                        
104
                                break;
105
                                }
106
                                default:
107
                                        return -1;
108
                        }
109
                break;
110
                }
111
                case ON_RAMP:
112
                {
113
                        intersect_pos = getIntersectPos(barcode);
114
                        switch (intersect_pos)
115
                        {
116
                                case R_LEFT:
117
                                {
118
                                        if (turn_type == ILEFT || turn_type == IUTURN) turn_type = ISTRAIGHT;
119
                                        return turn_type;        
120
                                break;
121
                                }
122
                                case R_RIGHT:
123
                                {
124
                                        if (turn_type == IRIGHT || turn_type == IUTURN) turn_type = ISTRAIGHT;
125
                                        return turn_type;                        
126
                                break;
127
                                }
128
                                default:
129
                                        return -1;
130
                        }
131
                break;
132
                }
133
                case OFF_RAMP:
134
                {
135
                        intersect_pos = getIntersectPos(barcode);
136
                        switch (intersect_pos)
137
                        {
138
                                case R_LEFT:
139
                                {
140
                                        int turn_type = ISTRAIGHT;
141
                                        return turn_type;        
142
                                break;
143
                                }
144
                                case R_RIGHT:
145
                                {
146
                                        int turn_type = ISTRAIGHT;
147
                                        return turn_type;                        
148
                                break;
149
                                }
150
                                case R_RAMP:
151
                                {
152
                                        if (turn_type == ISTRAIGHT || turn_type == IUTURN) turn_type = ILEFT;
153
                                        return turn_type;
154
                                break;
155
                                }
156
                                default:
157
                                        return -1;
158
                        }
159
                break;
160
                }
161
        default:
162
                return -1;
163
}
164
}