Revision 1853
improved turning
trunk/code/projects/linefollowing/main.c | ||
---|---|---|
14 | 14 |
{ |
15 | 15 |
//for(int q=0; q<500; q++) |
16 | 16 |
barCode = lineFollow(200); |
17 |
if(barCode==-25)while(turnLeft());
|
|
17 |
if(barCode==-25)while(turnRight());
|
|
18 | 18 |
continue; |
19 | 19 |
if(barCode != -2 && barCode != LINELOST) |
20 | 20 |
{ |
trunk/code/projects/linefollowing/lineFollow.c | ||
---|---|---|
12 | 12 |
int barCodePosition=0; |
13 | 13 |
|
14 | 14 |
int turnDistance=0; |
15 |
int intersection=0; |
|
15 |
int intersectionFilter=0;
|
|
16 | 16 |
int disableBarCode=0; |
17 | 17 |
|
18 | 18 |
|
... | ... | |
20 | 20 |
{ |
21 | 21 |
analog_init(0); |
22 | 22 |
lost = 0; |
23 |
intersection=0; |
|
23 |
intersectionFilter=0;
|
|
24 | 24 |
disableBarCode=0; |
25 | 25 |
} |
26 | 26 |
|
... | ... | |
47 | 47 |
} |
48 | 48 |
else if(position == FULL_LINE) |
49 | 49 |
{ |
50 |
if(intersection++>4) |
|
50 |
if(intersectionFilter++>4)
|
|
51 | 51 |
{ |
52 | 52 |
orb2_set_color(RED); |
53 | 53 |
barCodePosition=0; |
54 |
disableBarCode=15; |
|
55 |
return INTERSECTION; |
|
54 |
disableBarCode=50; |
|
56 | 55 |
} |
57 | 56 |
} |
58 | 57 |
//on line |
... | ... | |
63 | 62 |
motorLeft(min(speed+position, 255)); |
64 | 63 |
motorRight(min(speed-position, 255)); |
65 | 64 |
lost=0; |
66 |
intersection=0; |
|
65 |
intersectionFilter=0;
|
|
67 | 66 |
} |
68 | 67 |
|
69 |
if(disableBarCode) |
|
68 |
if(disableBarCode--)
|
|
70 | 69 |
{ |
71 |
disableBarCode--;
|
|
72 |
return NOBARCODE;
|
|
70 |
if(disableBarCode)return NOBARCODE;
|
|
71 |
return INTERSECTION;
|
|
73 | 72 |
} |
74 | 73 |
updateBarCode(); |
75 | 74 |
return getBarCode(); |
... | ... | |
83 | 82 |
int colors[5]; |
84 | 83 |
updateLine(colors); |
85 | 84 |
int position = lineLocate(colors); |
86 |
if(position==NOLINE)turnDistance++; |
|
87 |
else if(turnDistance>10) return 0;//turnDistance = 0; |
|
85 |
if(position>2 || position<-2)turnDistance++; |
|
86 |
|
|
87 |
if(turnDistance>1) |
|
88 |
{ |
|
89 |
if(position<3 && position>-3) |
|
90 |
{ |
|
91 |
turnDistance = 0; |
|
92 |
return 0; |
|
93 |
} |
|
94 |
} |
|
88 | 95 |
return 1; |
89 | 96 |
} |
90 | 97 |
|
... | ... | |
95 | 102 |
int colors[5]; |
96 | 103 |
updateLine(colors); |
97 | 104 |
int position = lineLocate(colors); |
98 |
if(position==NOLINE)turnDistance++; |
|
99 |
else if(turnDistance>10) return 0;//turnDistance = 0; |
|
100 |
return 1; |
|
105 |
if(position>2 || position<-2)turnDistance++; |
|
106 |
if(turnDistance>1) |
|
107 |
{ |
|
108 |
if(position<3 && position>-3) |
|
109 |
{ |
|
110 |
turnDistance = 0; |
|
111 |
return 0; |
|
112 |
} |
|
113 |
} |
|
114 |
return 1; |
|
101 | 115 |
} |
102 | 116 |
|
103 | 117 |
|
Also available in: Unified diff