Revision 1910
Updating some documentation for lineFollow
trunk/code/projects/linefollowing/lineFollow.h | ||
---|---|---|
1 | 1 |
#include <dragonfly_lib.h> |
2 | 2 |
|
3 |
#ifndef _LINEFOLLOW_H_
|
|
4 |
#define _LINEFOLLOW_H_
|
|
3 |
#ifndef _LINEFOLLOW_H_ |
|
4 |
#define _LINEFOLLOW_H_ |
|
5 | 5 |
|
6 | 6 |
#define LWHITE 0 |
7 | 7 |
#define LGREY 1 |
8 | 8 |
#define LBLACK 2 |
9 | 9 |
#define CENTER 3 |
10 |
#define NOLINE -42 |
|
10 |
#define NOLINE -42 //! Magic number?
|
|
11 | 11 |
#define LINELOST -1 |
12 | 12 |
|
13 | 13 |
#define NOBARCODE -2 |
14 |
#define INTERSECTION -25 |
|
15 |
#define FULL_LINE -26 |
|
14 |
#define INTERSECTION -25 //! Magic number?
|
|
15 |
#define FULL_LINE -26 //! Magic number?
|
|
16 | 16 |
|
17 | 17 |
|
18 | 18 |
|
... | ... | |
37 | 37 |
int mergeLeft(void); |
38 | 38 |
int mergeRight(void); |
39 | 39 |
|
40 |
/* updateLine |
|
41 |
Reads in the analog values |
|
42 |
Fills the given array with WHITE |
|
43 |
or BLACK representing the line |
|
44 |
*/ |
|
40 |
/** |
|
41 |
* @brief Updates the values stored in the array to white or black based on |
|
42 |
* current sensor readings. |
|
43 |
* |
|
44 |
* @param values The array of five integers to be updated. |
|
45 |
**/ |
|
45 | 46 |
void updateLine(int* values); |
46 | 47 |
|
47 |
/* lineLocate |
|
48 |
Finds the location of the line |
|
49 |
Outputs positive for right side |
|
50 |
Negative for left, or NOLINE if a line is not found |
|
51 |
*/ |
|
48 |
/** |
|
49 |
* @brief Returns an index of the middle of the line based on line readings. |
|
50 |
* |
|
51 |
* Two special return values are possible: |
|
52 |
* NOLINE if none of the sensors holds a black value, and |
|
53 |
* FULL_LINE if all of the sensors see black. |
|
54 |
* |
|
55 |
* Otherwise, returns a value from -4 (farthest left) to 4 (farthest right), with |
|
56 |
* 0 the line being centered in the middle. |
|
57 |
* |
|
58 |
* @param colors The array of 5 readings from the line sensor. Must be either |
|
59 |
* LWHITE or LBLACK. |
|
60 |
* @return Either a special value or an index from -4 to 4. |
|
61 |
* |
|
62 |
**/ |
|
52 | 63 |
int lineLocate(int* colors); |
53 | 64 |
|
54 | 65 |
/* updatebarCode |
... | ... | |
57 | 68 |
*/ |
58 | 69 |
void updateBarCode(void); |
59 | 70 |
|
60 |
/* getBarCode |
|
61 |
returns a bar code, if |
|
62 |
available, otherwise NOBARCODE |
|
63 |
*/ |
|
71 |
/** |
|
72 |
* @brief Gets the completed value read by the barcode reader, or NOBARCODE. |
|
73 |
* |
|
74 |
* Returns a bar code if available (if at the end of a barcode) and resets the |
|
75 |
* barcodePosition to 0. Otherwise, return NOBARCODE. * |
|
76 |
* @return The value of the barcode if a complete barcode, else NOBARCODE. |
|
77 |
**/ |
|
64 | 78 |
int getBarCode(void); |
65 | 79 |
|
66 |
/* min max |
|
67 |
returns the minimum/maximum of two values |
|
68 |
*/ |
|
80 |
|
|
81 |
//! A simple function to return the minimum of two integers. |
|
69 | 82 |
int min(int x, int y); |
83 |
//! A simple function to return the maximum of two integers. |
|
70 | 84 |
int max(int x, int y); |
71 | 85 |
|
72 | 86 |
/* motorLeft |
trunk/code/projects/linefollowing/lineFollow.c | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* @file lineFollow.c |
3 |
* @defgroup lineFollwing Line Following |
|
3 | 4 |
* |
4 | 5 |
* Takes care of following a line. Running this program is done by calling the |
5 | 6 |
* init() function and then the lineFollow(speed) command. However, direct use |
... | ... | |
12 | 13 |
|
13 | 14 |
#include "lineFollow.h" |
14 | 15 |
|
16 |
//! The number of bits expected in a barcode |
|
15 | 17 |
#define CODESIZE 5 |
16 | 18 |
|
17 | 19 |
int countHi = 0; |
... | ... | |
21 | 23 |
int barCodePosition=0; |
22 | 24 |
|
23 | 25 |
int turnDistance=0; |
26 |
//! Counts the number of full line readings before we determine an intersection |
|
24 | 27 |
int intersectionFilter=0; |
25 | 28 |
int disableBarCode=0; |
26 | 29 |
|
... | ... | |
54 | 57 |
//not on line |
55 | 58 |
if(position == NOLINE) |
56 | 59 |
{ |
57 |
if(lost++>20)
|
|
60 |
if(lost++ > 20)
|
|
58 | 61 |
{ |
59 | 62 |
orb2_set_color(GREEN); |
60 | 63 |
motors_off(); |
... | ... | |
63 | 66 |
} |
64 | 67 |
else if(position == FULL_LINE) |
65 | 68 |
{ |
66 |
if(intersectionFilter++>4)
|
|
69 |
if(intersectionFilter++ > 4)
|
|
67 | 70 |
{ |
68 | 71 |
orb2_set_color(RED); |
69 | 72 |
barCodePosition=0; |
... | ... | |
202 | 205 |
|
203 | 206 |
|
204 | 207 |
|
205 |
|
|
206 | 208 |
int getBarCode() |
207 | 209 |
{ |
208 | 210 |
if(barCodePosition!=CODESIZE) return NOBARCODE ; |
209 | 211 |
int temp = 0; |
210 |
int i; |
|
211 |
for(i=0; i<CODESIZE; i++) |
|
212 |
for(int i=0; i<CODESIZE; i++) |
|
212 | 213 |
temp += (barCode[i] << i); |
213 | 214 |
barCodePosition = 0; |
214 | 215 |
return temp; |
... | ... | |
240 | 241 |
return NOLINE; |
241 | 242 |
if(count==5) |
242 | 243 |
return FULL_LINE; |
243 |
return (wsum/count)-4; |
|
244 |
return (wsum/count)-4; // Subtract 4 to center the index around the center.
|
|
244 | 245 |
} |
245 | 246 |
|
246 | 247 |
|
247 | 248 |
void updateBarCode() |
248 | 249 |
{ |
250 |
//! Note: currently only uses one of the barcode sensors. |
|
249 | 251 |
|
250 |
//NOTE: currently only uses one of the barcode sensors. |
|
251 |
|
|
252 | 252 |
//maps the sensors to the analog input ports |
253 | 253 |
int ports[2] = {8,1}; |
254 | 254 |
int current[2]; |
... | ... | |
284 | 284 |
} |
285 | 285 |
|
286 | 286 |
|
287 |
//! A simple function to return the minimum of two integers. |
|
288 | 287 |
int min(int x, int y){return x>y ? y : x;} |
289 |
//! A simple function to return the maximum of two integers. |
|
290 | 288 |
int max(int x, int y){return x<y ? y : x;} |
291 | 289 |
|
292 | 290 |
void motorLeft(int speed){ |
Also available in: Unified diff