Revision 1981
Added new barcode reading to linefollowing project - first barcode is still wrong, however.
trunk/code/projects/linefollowing/lineFollow.h | ||
---|---|---|
6 | 6 |
#define LWHITE 0 |
7 | 7 |
#define LGREY 1 |
8 | 8 |
#define LBLACK 2 |
9 |
#define BAD_READING 3 |
|
9 | 10 |
#define CENTER 3 |
10 | 11 |
#define LINELOST -1 |
11 | 12 |
|
... | ... | |
15 | 16 |
#define NOLINE -50 |
16 | 17 |
#define FULL_LINE -51 |
17 | 18 |
|
19 |
|
|
18 | 20 |
//! Number of consecutive barcode color readings for a significant reading. |
19 | 21 |
#define MAX_DURATION 20 |
20 | 22 |
//! Number of consecutive white barcode readings before a barcode reset. |
21 | 23 |
#define TIMEOUT_DURATION 1000 |
22 | 24 |
//! Anything lower than this value is white |
23 |
#define GREY_THRESHOLD 250
|
|
25 |
#define GREY_THRESHOLD 500
|
|
24 | 26 |
//! Anything higher than this value is black |
25 |
#define BLACK_THRESHOLD 650
|
|
27 |
#define BLACK_THRESHOLD 750
|
|
26 | 28 |
|
27 | 29 |
#define NUM_READINGS 20 |
28 | 30 |
|
trunk/code/projects/linefollowing/lineFollow.c | ||
---|---|---|
29 | 29 |
int duration[2] = {0}; |
30 | 30 |
int lastColor[2] = {0}; |
31 | 31 |
char isReset[2] = {0}; |
32 |
int lastReadings[2][ NUM_READINGS ] = {{3}};
|
|
32 |
int lastReadings[2][ NUM_READINGS ] = {{0}};
|
|
33 | 33 |
int lastReadingsPtr[2] = {0}; |
34 | 34 |
int numLast[2][4] = { {0, 0, 0, NUM_READINGS}, {0, 0, 0, NUM_READINGS} }; |
35 | 35 |
int bitColor[2] = {0}; |
... | ... | |
46 | 46 |
|
47 | 47 |
void lineFollow_init() |
48 | 48 |
{ |
49 |
int i, j; |
|
50 |
|
|
49 | 51 |
analog_init(0); |
50 | 52 |
encoders_init(); |
51 | 53 |
lost = 0; |
52 | 54 |
intersectionFilter=0; |
53 | 55 |
disableBarCode=0; |
56 |
|
|
57 |
for(i=0; i<2; i++) |
|
58 |
{ |
|
59 |
for(j=0; j<NUM_READINGS; j++) |
|
60 |
{ |
|
61 |
lastReadings[i][j] = BAD_READING; |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
//numLast = { {0, 0, 0, NUM_READINGS}, {0, 0, 0, NUM_READINGS} }; |
|
54 | 66 |
} |
55 | 67 |
|
56 | 68 |
|
... | ... | |
297 | 309 |
lastReadingsPtr[i] = (lastReadingsPtr[i]+1) % NUM_READINGS; |
298 | 310 |
numLast[i][curColor]++; |
299 | 311 |
|
300 |
/*usb_puts("Totals: "); |
|
312 |
/*usb_puts("LP["); |
|
313 |
usb_puti(i); |
|
314 |
usb_puts("]: "); |
|
315 |
usb_puti(lastReadingsPtr[i]); |
|
316 |
usb_puts(", oldest: "); |
|
317 |
usb_puti(oldest); |
|
318 |
usb_puts(", Totals: "); |
|
301 | 319 |
|
302 |
for(int j=0; j<=2; j++)
|
|
320 |
for(int j=0; j<=3; j++)
|
|
303 | 321 |
{ |
304 | 322 |
usb_puts("["); |
305 | 323 |
usb_puti(j); |
... | ... | |
307 | 325 |
usb_puti(numLast[i][j]); |
308 | 326 |
usb_puts(" "); |
309 | 327 |
} |
310 |
usb_puts("\n");*/ |
|
328 |
usb_puts("\t ");*/ |
|
329 |
//usb_puts("\n"); |
|
311 | 330 |
} |
312 | 331 |
|
313 | 332 |
void updateBarCode() |
... | ... | |
338 | 357 |
curColor = LGREY; |
339 | 358 |
} |
340 | 359 |
|
341 |
// usb_puts("Read: ");
|
|
342 |
//usb_puti(curReading);
|
|
343 |
//usb_puts("\t");
|
|
360 |
/*usb_puts("Read: ");
|
|
361 |
usb_puti(curReading); |
|
362 |
usb_puts("\t ");*/
|
|
344 | 363 |
|
345 | 364 |
addToBuckets(curColor, i); |
346 | 365 |
|
... | ... | |
366 | 385 |
} |
367 | 386 |
else |
368 | 387 |
{ |
369 |
curColor = NOBARCODE;
|
|
388 |
curColor = BAD_READING;
|
|
370 | 389 |
} |
371 | 390 |
|
372 |
// @work |
|
373 |
switch(curColor) |
|
391 |
/*switch(curColor) |
|
374 | 392 |
{ |
375 |
//case LBLACK: usb_puts("LBLACK. "); break;
|
|
376 |
//case LGREY: usb_puts("LGREY. "); break;
|
|
377 |
//case LWHITE: usb_puts("LWHITE. "); break;
|
|
393 |
case LBLACK: usb_puts("LBLACK. "); break; |
|
394 |
case LGREY: usb_puts("LGREY. "); break; |
|
395 |
case LWHITE: usb_puts("LWHITE. "); break; |
|
378 | 396 |
} |
379 |
//usb_puti(curReading);
|
|
380 |
//usb_puts("\n");
|
|
397 |
usb_puti(curReading); |
|
398 |
usb_puts("\n");*/
|
|
381 | 399 |
|
382 |
return; |
|
383 |
|
|
384 |
if(curColor != NOBARCODE) |
|
400 |
if(curColor != BAD_READING) |
|
385 | 401 |
{ |
386 | 402 |
// Now we assume our reading is significant - a bit, or a white space |
387 | 403 |
|
... | ... | |
391 | 407 |
// Only read a value if we have read 0 first (isReset == 1) |
392 | 408 |
if(isReset[i] && (curColor == LBLACK || curColor == LGREY) ) |
393 | 409 |
{ |
394 |
|
|
395 |
/*if(barCodePosition[i] == 0) |
|
396 |
{ |
|
397 |
// testing encoder use |
|
398 |
encoder_rst_dx(LEFT); |
|
399 |
encoder_rst_dx(RIGHT); |
|
400 |
usb_puts("Encoders reset.\n"); |
|
401 |
}*/ |
|
402 |
|
|
403 | 410 |
isReset[i] = 0; |
404 |
/*if(i==0) |
|
405 |
{ |
|
406 |
usb_puts("Read barcode bit: "); |
|
407 |
usb_puti(barCodePosition[i]); |
|
408 |
usb_puts(" = "); |
|
409 |
usb_puti(curColor); |
|
410 |
usb_puts(", curReading = "); |
|
411 |
usb_puti(curReading); |
|
412 |
usb_puts(".\n"); |
|
413 |
}*/ |
|
414 |
|
|
415 |
/*if(curColor == LBLACK) |
|
416 |
{ |
|
417 |
orb_set_color(RED); |
|
418 |
} |
|
419 |
else |
|
420 |
{ |
|
421 |
orb_set_color(BLUE); |
|
422 |
}*/ |
|
423 |
|
|
424 | 411 |
duration[i] = 0; |
425 | 412 |
} |
426 | 413 |
else if(curColor == LWHITE) |
427 | 414 |
{ |
428 |
if(!isReset[i]) |
|
415 |
if(!isReset[i] && (bitColor[i] != LWHITE))
|
|
429 | 416 |
{ |
430 | 417 |
barCode[i][barCodePosition[i]++] = |
431 | 418 |
(bitColor[i] == LBLACK) ? 1 : 0; |
Also available in: Unified diff