Revision 1974
Back to most recent version of barcode reading.
trunk/code/projects/linefollowing/lineFollow.h | ||
---|---|---|
3 | 3 |
#ifndef _LINEFOLLOW_H_ |
4 | 4 |
#define _LINEFOLLOW_H_ |
5 | 5 |
|
6 |
#define ORB_LINEFOLLOW |
|
7 |
|
|
8 | 6 |
#define LWHITE 0 |
9 | 7 |
#define LGREY 1 |
10 | 8 |
#define LBLACK 2 |
... | ... | |
22 | 20 |
//! Number of consecutive white barcode readings before a barcode reset. |
23 | 21 |
#define TIMEOUT_DURATION 1000 |
24 | 22 |
//! Anything lower than this value is white |
25 |
#define GREY_THRESHOLD 500
|
|
23 |
#define GREY_THRESHOLD 250
|
|
26 | 24 |
//! Anything higher than this value is black |
27 |
#define BLACK_THRESHOLD 750
|
|
25 |
#define BLACK_THRESHOLD 650
|
|
28 | 26 |
|
29 | 27 |
#define NUM_READINGS 20 |
30 | 28 |
|
trunk/code/projects/linefollowing/lineFollow.c | ||
---|---|---|
28 | 28 |
|
29 | 29 |
int duration[2] = {0}; |
30 | 30 |
int lastColor[2] = {0}; |
31 |
char isReset[2] = {1};
|
|
32 |
int lastReadings[2][ NUM_READINGS ] = {{0}};
|
|
31 |
char isReset[2] = {0};
|
|
32 |
int lastReadings[2][ NUM_READINGS ] = {{3}};
|
|
33 | 33 |
int lastReadingsPtr[2] = {0}; |
34 |
int numLast[2][3] = { {NUM_READINGS, 0, 0}, {NUM_READINGS, 0, 0} };
|
|
34 |
int numLast[2][4] = { {0, 0, 0, NUM_READINGS}, {0, 0, 0, NUM_READINGS} };
|
|
35 | 35 |
int bitColor[2] = {0}; |
36 | 36 |
|
37 | 37 |
int turnDistance=0; |
... | ... | |
72 | 72 |
{ |
73 | 73 |
if(lost++ > 20) |
74 | 74 |
{ |
75 |
#ifdef ORB_LINEFOLLOW |
|
76 | 75 |
orb2_set_color(GREEN); |
77 |
#endif |
|
78 | 76 |
motors_off(); |
79 | 77 |
return LINELOST; |
80 | 78 |
} |
... | ... | |
83 | 81 |
{ |
84 | 82 |
if(intersectionFilter++ > 4) |
85 | 83 |
{ |
86 |
#ifdef ORB_LINEFOLLOW |
|
87 | 84 |
orb2_set_color(RED); |
88 |
#endif |
|
89 | 85 |
barCodePosition[0]=0; |
90 | 86 |
barCodePosition[1]=0; |
91 | 87 |
disableBarCode=50; |
... | ... | |
95 | 91 |
else |
96 | 92 |
{ |
97 | 93 |
position*=30; |
98 |
#ifdef ORB_LINEFOLLOW |
|
99 | 94 |
orb2_set_color(ORB_OFF); |
100 |
#endif |
|
101 | 95 |
motorLeft(min(speed+position, 255)); |
102 | 96 |
motorRight(min(speed-position, 255)); |
103 | 97 |
lost=0; |
... | ... | |
213 | 207 |
// Using this for debugging, take it out soon! |
214 | 208 |
motor_l_set(FORWARD,0); |
215 | 209 |
motor_r_set(FORWARD,0); |
216 |
#ifdef ORB_LINEFOLLOW |
|
217 | 210 |
//orb_set_color(WHITE); |
218 |
#endif |
|
219 | 211 |
delay_ms(2000); |
220 | 212 |
} |
221 | 213 |
|
... | ... | |
318 | 310 |
usb_puts("\n");*/ |
319 | 311 |
} |
320 | 312 |
|
321 |
|
|
322 | 313 |
void updateBarCode() |
323 | 314 |
{ |
324 | 315 |
// USING THESE GLOBAL VARIABLES |
... | ... | |
336 | 327 |
|
337 | 328 |
if(curReading > BLACK_THRESHOLD) |
338 | 329 |
{ |
339 |
//usb_puts("LBLACK "); |
|
340 | 330 |
curColor = LBLACK; |
341 | 331 |
} |
342 | 332 |
else if(curReading < GREY_THRESHOLD) |
343 | 333 |
{ |
344 |
//usb_puts("LWHITE"); |
|
345 | 334 |
curColor = LWHITE; |
346 | 335 |
} |
347 | 336 |
else |
348 | 337 |
{ |
349 |
//usb_puts("LGREY"); |
|
350 | 338 |
curColor = LGREY; |
351 | 339 |
} |
352 | 340 |
|
341 |
// usb_puts("Read: "); |
|
342 |
//usb_puti(curReading); |
|
343 |
//usb_puts("\t"); |
|
344 |
|
|
353 | 345 |
addToBuckets(curColor, i); |
354 | 346 |
|
355 | 347 |
// Just an error check |
... | ... | |
359 | 351 |
} |
360 | 352 |
|
361 | 353 |
// We now edit curColor to use the majority of the last buckets. |
362 |
for(int j = 0; j <= 2; j++)
|
|
354 |
if(numLast[i][1] > NUM_READINGS / 2)
|
|
363 | 355 |
{ |
364 |
if(numLast[i][1] > NUM_READINGS / 2) |
|
365 |
{ |
|
366 |
curColor = LGREY; |
|
367 |
} |
|
368 |
else if(numLast[i][2] > NUM_READINGS / 2) |
|
369 |
{ |
|
370 |
curColor = LBLACK; |
|
371 |
} |
|
372 |
else if(numLast[i][0] > NUM_READINGS / 2) |
|
373 |
{ |
|
374 |
curColor = LWHITE; |
|
375 |
duration[i]++; |
|
376 |
} |
|
377 |
else |
|
378 |
{ |
|
379 |
curColor = NOBARCODE; |
|
380 |
} |
|
356 |
curColor = LGREY; |
|
381 | 357 |
} |
358 |
else if(numLast[i][2] > NUM_READINGS / 2) |
|
359 |
{ |
|
360 |
curColor = LBLACK; |
|
361 |
} |
|
362 |
else if(numLast[i][0] > NUM_READINGS / 2) |
|
363 |
{ |
|
364 |
curColor = LWHITE; |
|
365 |
duration[i]++; |
|
366 |
} |
|
367 |
else |
|
368 |
{ |
|
369 |
curColor = NOBARCODE; |
|
370 |
} |
|
382 | 371 |
|
372 |
// @work |
|
373 |
switch(curColor) |
|
374 |
{ |
|
375 |
//case LBLACK: usb_puts("LBLACK. "); break; |
|
376 |
//case LGREY: usb_puts("LGREY. "); break; |
|
377 |
//case LWHITE: usb_puts("LWHITE. "); break; |
|
378 |
} |
|
379 |
//usb_puti(curReading); |
|
380 |
//usb_puts("\n"); |
|
381 |
|
|
382 |
return; |
|
383 |
|
|
383 | 384 |
if(curColor != NOBARCODE) |
384 | 385 |
{ |
385 | 386 |
// Now we assume our reading is significant - a bit, or a white space |
... | ... | |
413 | 414 |
|
414 | 415 |
/*if(curColor == LBLACK) |
415 | 416 |
{ |
416 |
#ifdef ORB_LINEFOLLOW |
|
417 | 417 |
orb_set_color(RED); |
418 |
#endif |
|
419 | 418 |
} |
420 | 419 |
else |
421 | 420 |
{ |
422 |
#ifdef ORB_LINEFOLLOW |
|
423 | 421 |
orb_set_color(BLUE); |
424 |
#endif |
|
425 | 422 |
}*/ |
426 | 423 |
|
427 | 424 |
duration[i] = 0; |
... | ... | |
433 | 430 |
barCode[i][barCodePosition[i]++] = |
434 | 431 |
(bitColor[i] == LBLACK) ? 1 : 0; |
435 | 432 |
usb_puts("Reset. Read bit: "); |
436 |
usb_puti(bitColor[i]);
|
|
433 |
usb_puts(((bitColor[i] == LBLACK) ? "BLACK" : "GREY"));
|
|
437 | 434 |
usb_puts("\n"); |
438 | 435 |
|
439 | 436 |
bitColor[i] = LWHITE; |
440 | 437 |
} |
441 | 438 |
isReset[i] = 1; |
442 |
#ifdef ORB_LINEFOLLOW |
|
443 | 439 |
orb_set(0, 0, 0); |
444 |
#endif |
|
445 | 440 |
} |
446 | 441 |
} |
447 | 442 |
|
Also available in: Unified diff