Revision 1954
changed black_value
trunk/code/projects/linefollowing/lineFollow.h | ||
---|---|---|
1 |
<<<<<<< .mine |
|
2 |
#include <dragonfly_lib.h> |
|
3 |
|
|
4 |
#ifndef _LINEFOLLOW_H_ |
|
5 |
#define _LINEFOLLOW_H_ |
|
6 |
|
|
7 |
#define LWHITE 0 |
|
8 |
#define LGREY 1 |
|
9 |
#define LBLACK 2 |
|
10 |
#define CENTER 3 |
|
11 |
#define LINELOST -1 |
|
12 |
|
|
13 |
#define NOBARCODE -2 |
|
14 |
#define INTERSECTION -25 |
|
15 |
|
|
16 |
#define NOLINE -50 |
|
17 |
#define FULL_LINE -51 |
|
18 |
|
|
19 |
//! Number of consecutive barcode color readings for a significant reading. |
|
20 |
#define MAX_DURATION 20 |
|
21 |
//! Number of consecutive white barcode readings before a barcode reset. |
|
22 |
#define TIMEOUT_DURATION 1000 |
|
23 |
//! Anything lower than this value is white |
|
24 |
#define GREY_THRESHOLD 100 |
|
25 |
//! Anything higher than this value is black |
|
26 |
#define BLACK_THRESHOLD 400 |
|
27 |
|
|
28 |
#define LEFT_SENSOR 1 |
|
29 |
#define RIGHT_SENSOR 0 |
|
30 |
|
|
31 |
/** |
|
32 |
* @brief Initializes line following. |
|
33 |
* |
|
34 |
* Must be called before line following will work. |
|
35 |
* Turns the analog loop off. |
|
36 |
*/ |
|
37 |
void lineFollow_init(void); |
|
38 |
|
|
39 |
/** lineFollow |
|
40 |
* Must call lineFollow_init first |
|
41 |
* Must be called inside a loop |
|
42 |
*/ |
|
43 |
int lineFollow(int speed); |
|
44 |
|
|
45 |
/** turnLeft turnRight mergeLeft mergeRight |
|
46 |
* Must be called inside a loop |
|
47 |
* returns 0 when complete |
|
48 |
*/ |
|
49 |
int turnLeft(void); |
|
50 |
int turnRight(void); |
|
51 |
int mergeLeft(void); |
|
52 |
int mergeRight(void); |
|
53 |
|
|
54 |
/** |
|
55 |
* @brief Updates the values stored in the array to white or black based on |
|
56 |
* current sensor readings. |
|
57 |
* |
|
58 |
* @param values The array of five integers to be updated. |
|
59 |
*/ |
|
60 |
void updateLine(int* values); |
|
61 |
|
|
62 |
/** |
|
63 |
* @brief Returns an index of the middle of the line based on line readings. |
|
64 |
* |
|
65 |
* Two special return values are possible: |
|
66 |
* NOLINE if none of the sensors holds a black value, and |
|
67 |
* FULL_LINE if all of the sensors see black. |
|
68 |
* |
|
69 |
* Otherwise, returns a value from -4 (farthest left) to 4 (farthest right), with |
|
70 |
* 0 the line being centered in the middle. |
|
71 |
* |
|
72 |
* @param colors The array of 5 readings from the line sensor. Must be either |
|
73 |
* LWHITE or LBLACK. |
|
74 |
* @return Either a special value or an index from -4 to 4. |
|
75 |
* |
|
76 |
*/ |
|
77 |
int lineLocate(int* colors); |
|
78 |
|
|
79 |
/** updatebarCode |
|
80 |
* Reads in and processes |
|
81 |
* bar code data |
|
82 |
*/ |
|
83 |
void updateBarCode(void); |
|
84 |
|
|
85 |
/** |
|
86 |
* @brief Gets the completed value read by the barcode reader, or NOBARCODE. |
|
87 |
* |
|
88 |
* Returns a bar code if available (if at the end of a barcode) and resets the |
|
89 |
* barcodePosition to 0. Otherwise, return NOBARCODE. * |
|
90 |
* @return The value of the barcode if a complete barcode, else NOBARCODE. |
|
91 |
*/ |
|
92 |
int getBarCode(void); |
|
93 |
|
|
94 |
|
|
95 |
//! A simple function to return the minimum of two integers. |
|
96 |
int min(int x, int y); |
|
97 |
//! A simple function to return the maximum of two integers. |
|
98 |
int max(int x, int y); |
|
99 |
|
|
100 |
/** @todo Alex: I hate these functions, but I'm keeping them so code will still work. But we should delete them sometime. */ |
|
101 |
|
|
102 |
/** motorLeft |
|
103 |
* Commands the left motor |
|
104 |
* Cannot be used to stop |
|
105 |
* 0-126 are backward |
|
106 |
* 127-255 are forward |
|
107 |
*/ |
|
108 |
void motorLeft(int speed); |
|
109 |
|
|
110 |
/** motorRight |
|
111 |
* Commands the right motor |
|
112 |
* Cannot be used to stop |
|
113 |
* 0-126 are backward |
|
114 |
* 127-255 are forward |
|
115 |
*/ |
|
116 |
void motorRight(int speed); |
|
117 |
|
|
118 |
/** lost |
|
119 |
* Internal counter to detect if the line was lost |
|
120 |
*/ |
|
121 |
int lost; |
|
122 |
|
|
123 |
int onLine(void); |
|
124 |
|
|
125 |
#endif |
|
126 |
======= |
|
127 |
#include <dragonfly_lib.h> |
|
128 |
|
|
129 |
#ifndef _LINEFOLLOW_H_ |
|
130 |
#define _LINEFOLLOW_H_ |
|
131 |
|
|
132 |
#define LWHITE 0 |
|
133 |
#define LGREY 1 |
|
134 |
#define LBLACK 2 |
|
135 |
#define CENTER 3 |
|
136 |
#define LINELOST -1 |
|
137 |
|
|
138 |
#define NOBARCODE -2 |
|
139 |
#define INTERSECTION -25 |
|
140 |
|
|
141 |
#define NOLINE -50 |
|
142 |
#define FULL_LINE -51 |
|
143 |
|
|
144 |
//! Number of consecutive barcode color readings for a significant reading. |
|
145 |
#define MAX_DURATION 20 |
|
146 |
//! Number of consecutive white barcode readings before a barcode reset. |
|
147 |
#define TIMEOUT_DURATION 1000 |
|
148 |
//! Anything lower than this value is white |
|
149 |
#define GREY_THRESHOLD 100 |
|
150 |
//! Anything higher than this value is black |
|
151 |
#define BLACK_THRESHOLD 400 |
|
152 |
|
|
153 |
#define LEFT_SENSOR 1 |
|
154 |
#define RIGHT_SENSOR 0 |
|
155 |
|
|
156 |
/** |
|
157 |
* @brief Initializes line following. |
|
158 |
* |
|
159 |
* Must be called before line following will work. |
|
160 |
* Turns the analog loop off. |
|
161 |
*/ |
|
162 |
void lineFollow_init(void); |
|
163 |
|
|
164 |
/** lineFollow |
|
165 |
* Must call lineFollow_init first |
|
166 |
* Must be called inside a loop |
|
167 |
*/ |
|
168 |
int lineFollow(int speed); |
|
169 |
|
|
170 |
/** turnLeft turnRight mergeLeft mergeRight |
|
171 |
* Must be called inside a loop |
|
172 |
* returns 0 when complete |
|
173 |
*/ |
|
174 |
int turnLeft(void); |
|
175 |
int turnRight(void); |
|
176 |
int mergeLeft(void); |
|
177 |
int mergeRight(void); |
|
178 |
|
|
179 |
/** |
|
180 |
* @brief Updates the values stored in the array to white or black based on |
|
181 |
* current sensor readings. |
|
182 |
* |
|
183 |
* @param values The array of five integers to be updated. |
|
184 |
*/ |
|
185 |
void updateLine(int* values); |
|
186 |
|
|
187 |
/** |
|
188 |
* @brief Returns an index of the middle of the line based on line readings. |
|
189 |
* |
|
190 |
* Two special return values are possible: |
|
191 |
* NOLINE if none of the sensors holds a black value, and |
|
192 |
* FULL_LINE if all of the sensors see black. |
|
193 |
* |
|
194 |
* Otherwise, returns a value from -4 (farthest left) to 4 (farthest right), with |
|
195 |
* 0 the line being centered in the middle. |
|
196 |
* |
|
197 |
* @param colors The array of 5 readings from the line sensor. Must be either |
|
198 |
* LWHITE or LBLACK. |
|
199 |
* @return Either a special value or an index from -4 to 4. |
|
200 |
* |
|
201 |
*/ |
|
202 |
int lineLocate(int* colors); |
|
203 |
|
|
204 |
/** updatebarCode |
|
205 |
* Reads in and processes |
|
206 |
* bar code data |
|
207 |
*/ |
|
208 |
void updateBarCode(void); |
|
209 |
|
|
210 |
/** |
|
211 |
* @brief Gets the completed value read by the barcode reader, or NOBARCODE. |
|
212 |
* |
|
213 |
* Returns a bar code if available (if at the end of a barcode) and resets the |
|
214 |
* barcodePosition to 0. Otherwise, return NOBARCODE. * |
|
215 |
* @return The value of the barcode if a complete barcode, else NOBARCODE. |
|
216 |
*/ |
|
217 |
int getBarCode(void); |
|
218 |
|
|
219 |
|
|
220 |
//! A simple function to return the minimum of two integers. |
|
221 |
int min(int x, int y); |
|
222 |
//! A simple function to return the maximum of two integers. |
|
223 |
int max(int x, int y); |
|
224 |
|
|
225 |
/** @todo Alex: I hate these functions, but I'm keeping them so code will still work. But we should delete them sometime. */ |
|
226 |
|
|
227 |
/** motorLeft |
|
228 |
* Commands the left motor |
|
229 |
* Cannot be used to stop |
|
230 |
* 0-126 are backward |
|
231 |
* 127-255 are forward |
|
232 |
*/ |
|
233 |
void motorLeft(int speed); |
|
234 |
|
|
235 |
/** motorRight |
|
236 |
* Commands the right motor |
|
237 |
* Cannot be used to stop |
|
238 |
* 0-126 are backward |
|
239 |
* 127-255 are forward |
|
240 |
*/ |
|
241 |
void motorRight(int speed); |
|
242 |
|
|
243 |
/** lost |
|
244 |
* Internal counter to detect if the line was lost |
|
245 |
*/ |
|
246 |
int lost; |
|
247 |
|
|
248 |
int onLine(void); |
|
249 |
|
|
250 |
#endif |
|
251 |
>>>>>>> .r1952 |
Also available in: Unified diff