Project

General

Profile

Revision 1881

Merged the types of doubles into the crossing type. Also fixed comments
that were never updated and implements things of type DOUBLE as DOUBLE_T's
if you dont specify because DOUBLE_T is more safe.

View differences:

trunk/code/projects/traffic_navigation/validTurns-test.c
3 3
#include "validTurns.h"
4 4

  
5 5
int main(){
6
/*barcode should be written as double type (DOUBLE_C or DOUBLE_T), crosstype, crosspos, turntype. 6-9 bit integers*/
6
/*barcode should be written as crosstype, crosspos. 5 bit integers*/
7 7

  
8 8
dragonfly_init(ALL_ON);
9 9
orb1_set_color(YELLOW);
10 10

  
11
int barcode1 = (DOUBLE_C<<4)+(DOUBLE<<2)+(TMIDDLE);
11
int barcode1 = (DOUBLE_C<<2)+(TMIDDLE);
12 12
if (validateTurn(barcode1, ILEFT)==ILEFT) orb1_set_color(GREEN);
13 13

  
14 14
delay_ms(100);
15 15
orb1_set_color(PINK);
16 16
delay_ms(50);
17 17

  
18
int barcode2 = (DOUBLE_C<<4)+(DOUBLE<<2)+(TMIDDLE);
18
int barcode2 = (DOUBLE_C<<2)+(TMIDDLE);
19 19
if (validateTurn(barcode2, IUTURN)==IUTURN) orb1_set_color(GREEN);
20 20

  
21 21
delay_ms(100);
22 22
orb1_set_color(RED);
23 23
delay_ms(50);
24 24

  
25
int barcode3 = (DOUBLE_T<<4)+(DOUBLE<<2)+(TMIDDLE);
25
int barcode3 = (DOUBLE_T<<2)+(TMIDDLE);
26 26
if (validateTurn(barcode3, IUTURN)==IUTURN) orb1_set_color(GREEN);
27

  
27
s
28 28
delay_ms(100);
29 29
orb1_set_color(PURPLE);
30 30
delay_ms(50);
31 31

  
32
int barcode4 = (DOUBLE_T<<4)+(DOUBLE<<2)+(TMIDDLE);
32
int barcode4 = (DOUBLE_T<<2)+(TMIDDLE);
33 33
if (validateTurn(barcode4, ISTRAIGHT)==IUTURN) orb1_set_color(GREEN);
34 34

  
35 35
while (1){}
trunk/code/projects/traffic_navigation/validTurns.c
1 1
/*
2
 * Deterministic turning implemented using randomness. Using a
3
 * random number generator, the robot decides to go straight, 
4
 * left, right, or u-turn.
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.
5 7
 *
6 8
 */
7 9

  
8 10
#include <dragonfly_lib.h>
9 11
#include "validTurns.h"
10 12

  
11
#define NOBARCODE -1
12
/*
13

  
14
/******************************Random Num Gen Version of validTurns
13 15
int randomNumGen(int max){
14 16
	int x = range_read_distance(IR2);
15 17
	if (x>0) return range_read_distance(IR2)%max;
......
40 42

  
41 43
int getCrossType(int barcode){
42 44
	int crosstype = (barcode>>2)&3;
43
	if (crosstype == DOUBLE) crosstype = (barcode>>4)&7;
44 45
	return crosstype;
45 46
}
46 47
int getCrossPos(int barcode, int max){
......
51 52
{
52 53
	int cross_type;
53 54
	int cross_pos;
54
	if( barcode == NOBARCODE ) return -1;
55 55
	cross_type = getCrossType(barcode);
56 56
	switch (cross_type)
57 57
	{
......
62 62
			return turn_type;
63 63
		break;
64 64
		}
65
		case DOUBLE:   //Implements DOUBLE as DOUBLE_T
65 66
		case DOUBLE_T:
66 67
		{
67 68
			cross_pos = getCrossPos(barcode, 3);

Also available in: Unified diff