Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (3.03 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
#include <dragonfly_lib.h>
11

    
12
/******************************Random Num Gen Version of validTurns*/
13
int randomNumGen(int max){
14
        int x = rtc_get();
15
        if (x>0) return range_read_distance(IR2)%max;
16
        else return randomNumGen(max);
17
}
18
/*
19
int getIntersectType(int barcode)
20
{
21
        int x = randomNumGen(4);
22
        if (x == DOUBLE) {
23
                int y = randomNumGen(2);
24
                if (y == 0) x = DOUBLE_C;
25
                else x = DOUBLE_T;
26
        }
27
        return x;
28
}
29

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

    
40

    
41
#include "intersectData.h"
42
#include "validTurns.h"
43

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