Revision 1864
Added comments (doxygen style) to linefollow and linedrive.
lineFollow.c | ||
---|---|---|
1 |
/** |
|
2 |
* @file lineFollow.c |
|
3 |
* |
|
4 |
* Takes care of following a line. Running this program is done by calling the |
|
5 |
* init() function and then the lineFollow(speed) command. However, direct use |
|
6 |
* of this class is discouraged as its behavior is used by lineDrive.c, which |
|
7 |
* extends this class to provide behavior functionality. |
|
8 |
* |
|
9 |
* @author Dan Jacobs |
|
10 |
* @date 11-1-2010 |
|
11 |
*/ |
|
12 |
|
|
1 | 13 |
#include "lineFollow.h" |
2 | 14 |
|
3 | 15 |
#define CODESIZE 5 |
... | ... | |
13 | 25 |
int disableBarCode=0; |
14 | 26 |
|
15 | 27 |
|
28 |
/** |
|
29 |
* Initializes line following. Must be called before other line-following |
|
30 |
* behavior will work. |
|
31 |
*/ |
|
16 | 32 |
void lineFollow_init() |
17 | 33 |
{ |
18 | 34 |
analog_init(0); |
... | ... | |
22 | 38 |
} |
23 | 39 |
|
24 | 40 |
|
25 |
|
|
41 |
/** |
|
42 |
* Follows a line at the given speed. |
|
43 |
* @param speed The speed with which to follow the line. |
|
44 |
*/ |
|
26 | 45 |
int lineFollow(int speed) |
27 | 46 |
{ |
28 | 47 |
int colors[5]; |
... | ... | |
72 | 91 |
} |
73 | 92 |
|
74 | 93 |
|
94 |
/** |
|
95 |
* Implements the left merge, assuming a line exists to the left. Works by |
|
96 |
* turning off the line at an increasing angle and waiting to hit another line |
|
97 |
* on the left. |
|
98 |
*/ |
|
75 | 99 |
int mergeLeft() |
76 | 100 |
{ |
77 | 101 |
motor_l_set(FORWARD, 200); |
... | ... | |
96 | 120 |
} |
97 | 121 |
|
98 | 122 |
|
123 |
/** |
|
124 |
* Implements the right merge, assuming a line exists to the right. Works by |
|
125 |
* turning off the line at an increasing angle and waiting to hit another line |
|
126 |
* on the right. |
|
127 |
*/ |
|
99 | 128 |
int mergeRight() |
100 | 129 |
{ |
101 | 130 |
motor_r_set(FORWARD, 200); |
... | ... | |
121 | 150 |
|
122 | 151 |
|
123 | 152 |
|
153 |
/** |
|
154 |
* Turns left at a cross of two lines. Assumes that we are at lines in a cross |
|
155 |
* pattern, and turns until it sets straight on the new line. |
|
156 |
* @return 1 if the turn was executed successfully, 0 otherwise. |
|
157 |
*/ |
|
124 | 158 |
int turnLeft() |
125 | 159 |
{ |
126 | 160 |
motor_l_set(BACKWARD, 200); |
... | ... | |
142 | 176 |
|
143 | 177 |
|
144 | 178 |
|
179 |
/** |
|
180 |
* Turns right at a cross of two lines. Assumes that we are at lines in a cross |
|
181 |
* pattern, and turns until it sets straight on the new line. |
|
182 |
* @return 1 if the turn was executed successfully, 0 otherwise. |
|
183 |
*/ |
|
145 | 184 |
int turnRight() |
146 | 185 |
{ |
147 | 186 |
motor_r_set(BACKWARD, 200); |
... | ... | |
245 | 284 |
} |
246 | 285 |
|
247 | 286 |
|
287 |
//! A simple function to return the minimum of two integers. |
|
248 | 288 |
int min(int x, int y){return x>y ? y : x;} |
289 |
//! A simple function to return the maximum of two integers. |
|
249 | 290 |
int max(int x, int y){return x<y ? y : x;} |
250 | 291 |
|
251 | 292 |
void motorLeft(int speed){ |
... | ... | |
255 | 296 |
void motorRight(int speed){ |
256 | 297 |
((speed-=127)>=0)?motor_r_set(FORWARD, 160+speed*95/128):motor_r_set(BACKWARD, 160-speed*95/127); |
257 | 298 |
} |
258 |
|
Also available in: Unified diff