Project

General

Profile

Revision 1961

Added new linefollowing code for barcodes.

Debug statements are still included, but this is the latest version of the code.

Bot14 at least reads all barcodes consistently. Thresholds may have to be adjusted for other robots.

View differences:

lineFollow.c
28 28

  
29 29
int duration[2] = {0};
30 30
int lastColor[2] = {0};
31
char isReset[2] = {0};
31
char isReset[2] = {1};
32 32
int lastReadings[2][ NUM_READINGS ] = {{0}};
33 33
int lastReadingsPtr[2] = {0};
34 34
int numLast[2][3] = { {NUM_READINGS, 0, 0}, {NUM_READINGS, 0, 0} };
35
int bitColor[2] = {0};
35 36

  
36 37
int turnDistance=0;
37 38
//! Counts the number of full line readings before we determine an intersection
......
310 311
}
311 312

  
312 313

  
313
// new version by Alex
314 314
void updateBarCode()
315 315
{
316 316
    // USING THESE GLOBAL VARIABLES
......
341 341
            //usb_puts("LGREY");
342 342
            curColor = LGREY;
343 343
        }
344
        //usb_puti(curReading);
345
        //usb_puts("\n");
346 344

  
347 345
        addToBuckets(curColor, i);
348 346

  
......
352 350
            barCodePosition[i] = 0;
353 351
        }
354 352

  
353
        // We now edit curColor to use the majority of the last buckets.
355 354
        for(int j = 0; j <= 2; j++)
356 355
        {
357 356
            if(numLast[i][1] > NUM_READINGS / 2)
......
377 376
        {
378 377
            // Now we assume our reading is significant - a bit, or a white space
379 378

  
379
            if(bitColor[i] == LGREY || bitColor[i] == LWHITE)
380
                bitColor[i] = curColor;
381

  
380 382
            // Only read a value if we have read 0 first (isReset == 1)
381 383
            if(isReset[i] && (curColor == LBLACK || curColor == LGREY) )
382 384
            {
383
                if(barCodePosition[i] == 0)
385

  
386
                /*if(barCodePosition[i] == 0)
384 387
                {
385 388
                    // testing encoder use
386 389
                    encoder_rst_dx(LEFT);
387 390
                    encoder_rst_dx(RIGHT);
388 391
                    usb_puts("Encoders reset.\n");
389
                }
392
                }*/
390 393

  
391 394
                isReset[i] = 0;
392
                if(i==0)
395
                /*if(i==0)
393 396
                {
394 397
                    usb_puts("Read barcode bit: ");
395 398
                    usb_puti(barCodePosition[i]);
......
398 401
                    usb_puts(", curReading = ");
399 402
                    usb_puti(curReading);
400 403
                    usb_puts(".\n");
401
                }
404
                }*/
402 405

  
403
                if(curColor == LBLACK)
406
                /*if(curColor == LBLACK)
404 407
                {
405 408
                    orb_set_color(RED);
406 409
                }
407 410
                else
408 411
                {
409 412
                    orb_set_color(BLUE);
410
                }
413
                }*/
411 414

  
412
                barCode[i][barCodePosition[i]++] = (curColor == LBLACK) ? 1 : 0;
413 415
                duration[i] = 0;
414 416
            }
415 417
            else if(curColor == LWHITE)
416 418
            {
417 419
                if(!isReset[i])
418 420
                {
419
                    usb_puts("Reset.\n");
421
                    barCode[i][barCodePosition[i]++] = 
422
                        (bitColor[i] == LBLACK) ? 1 : 0;
423
                    usb_puts("Reset. Read bit: ");
424
                    usb_puti(bitColor[i]);
425
                    usb_puts("\n");
426

  
427
                    bitColor[i] = LWHITE;
420 428
                }
421 429
                isReset[i] = 1;
422 430
                orb_set(0, 0, 0);
......
439 447
    }
440 448
}
441 449

  
442
// Dan's version
443
/*void updateBarCode()
444
{
445
	//! Note: currently only uses one of the barcode sensors.
446 450

  
447
	//maps the sensors to the analog input ports
448
	int ports[2] = {8,1};
449
	int current[2];
450
//	current[0] = analog_get10(ports[0]);
451
	//current[1] = analog_get10(ports[1]);
452
    current[1] = read_line(6);
453

  
454
	if(current[1] > 150)
455
	{
456
		if(countHi++ == 0) 
457
		{
458
			avg = 500;
459
			maxAvg = 500;
460
		}
461
		else
462
		{
463
			avg = 3*avg + current[1];
464
			avg/=4;
465
			maxAvg = max(maxAvg, avg);
466
		}
467
	}
468
	else if(countHi > 5)
469
	{
470
		if(countLo++ > 15)
471
		{
472
			countHi = countLo = 0;
473
			if(maxAvg > 825)
474
                orb1_set_color(RED);
475
			else orb1_set_color(BLUE);
476
			barCode[barCodePosition++] = maxAvg > 825 ? 1:0;
477
		}
478
	}
479
	else countHi/=2;
480
	if(countHi==0)countLo=0; 
481
}*/
482

  
483

  
484 451
int min(int x, int y){return x>y ? y : x;}
485 452
int max(int x, int y){return x<y ? y : x;}
486 453

  

Also available in: Unified diff