Project

General

Profile

Revision 1945

Changed to use Alex's barcode code.

View differences:

trunk/code/projects/linefollowing/lineFollow.h
15 15
#define NOLINE			-50
16 16
#define FULL_LINE 		-51
17 17

  
18
// Number of consecutive barcode color readings to establish a significant
19
// reading.
18
//! Number of consecutive barcode color readings for a significant reading.
20 19
#define MAX_DURATION    20
20
//! Number of consecutive white barcode readings before a barcode reset.
21
#define TIMEOUT_DURATION    1000
22
//! Anything lower than this value is white
23
#define GREY_THRESHOLD 100
24
//! Anything higher than this value is black
25
#define BLACK_THRESHOLD 350
21 26

  
22 27
/**
23 28
 * @brief Initializes line following.
trunk/code/projects/linefollowing/main.c
45 45
    while(1)
46 46
    {
47 47

  
48
        int barcode = lineFollow(200);
48
        int barcode = lineFollow(170);
49 49

  
50
        if(barcode != NOBARCODE)
50
        if(barcode != NOBARCODE && barcode != LINELOST)
51 51
        {
52 52
            usb_puti(barcode);
53 53
            usb_puts("\n");
trunk/code/projects/linefollowing/lineFollow.c
281 281

  
282 282

  
283 283
// new version by Alex
284
/*void updateBarCode()
284
void updateBarCode()
285 285
{
286
    // Average the readings of the last 2 sensors
287
    int curReading = (read_line(6) + read_line(7)) / 2;
288
    int curColor = (curReading > 500) ? LBLACK : LWHITE;
289

  
290 286
    // USING THESE GLOBAL VARIABLES
291 287
    // global int duration = 0;
292 288
    // global int lastColor = 0;
293 289
    // global int barCodePosition = 0;
294 290
    // global char isReset = 0;
295 291

  
292
    // Average the readings of the last 2 sensors
293
    if(read_line(6) - read_line(7) > 150 || read_line(6) - read_line(7) < -150)
294
    {
295
        return;
296
    }
297

  
298
    int curReading = (read_line(6) + read_line(7)) / 2;
299
    int curColor;
300

  
301
    if(curReading > BLACK_THRESHOLD)
302
        curColor = LBLACK;
303
    else if(curReading < GREY_THRESHOLD)
304
        curColor = LWHITE;
305
    else
306
        curColor = LGREY;
307

  
296 308
    // Just an error check
297 309
    if(barCodePosition > CODESIZE)
298 310
    {
299 311
        barCodePosition = 0;
300 312
    }
301 313

  
314
    // We are only interested in consecutive color values
302 315
    if(curColor == lastColor)
303 316
    {
304 317
        duration++;
......
317 330
        if(isReset && (curColor == LBLACK || curColor == LGREY) )
318 331
        {
319 332
            isReset = 0;
333
            usb_puts("Read barcode bit: ");
334
            usb_puti(barCodePosition);
335
            usb_puts(" = ");
336
            usb_puti(curColor);
337
            usb_puts(", curReading = ");
338
            usb_puti(curReading);
339
            usb_puts(".\n");
320 340

  
321 341
            barCode[barCodePosition++] = (curColor == LBLACK) ? 1 : 0;
322 342
        }
......
325 345
            isReset = 1;
326 346
        }
327 347
    }
328
}*/
348
    if(duration > TIMEOUT_DURATION && barCodePosition != 0)
349
    {
350
        usb_puts("TIMED OUT. BARCODE READER RESET.\n");
351
        barCodePosition = 0;
352
        duration = 0;
353
    }
354
}
329 355

  
330

  
331
void updateBarCode()
356
// Dan's version
357
/*void updateBarCode()
332 358
{
333 359
	//! Note: currently only uses one of the barcode sensors.
334 360

  
......
366 392
	}
367 393
	else countHi/=2;
368 394
	if(countHi==0)countLo=0; 
369
}
395
}*/
370 396

  
371 397

  
372 398
int min(int x, int y){return x>y ? y : x;}
trunk/code/projects/linefollowing/Makefile
11 11
USE_WIRELESS = 1
12 12

  
13 13
# com1 = serial port. Use lpt1 to connect to parallel port.
14
AVRDUDE_PORT = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'COM4:'; else echo '/dev/ttyUSB0'; fi)
14
AVRDUDE_PORT = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'COM4:'; else echo '/dev/ttyUSB1'; fi)
15 15

  
16 16
else
17 17
COLONYROOT := ../$(COLONYROOT)

Also available in: Unified diff