(===========================================================) ( CMPUT 412 ) ( MILESTONE 2 ) (===========================================================) ( File: bar.txt ) ( Team: Gang Green ) ( Members: David Laing, Craig Martin, Cam Frith ) ( Date: October 15, 2001 ) ( ) ( This module contains code necessary for ) ( barcode detection. ) ( ) ( Variables used: ) ( RBS: Right Barcode Sensor - the photodiode pair ) ( mounted to detect the right barcode sync line. RBS ) ( receives a digital value between 00 and FF depending on ) ( the amount of light it detects. Barcode detection ) ( requires no continuous data; input is either black or ) ( white. For this reason, we have set a black threshold as ) ( any value under 70, and a white threshold as any value ) ( over D0. ) ( ) ( LBS: Left Barcode Sensor - the photodiode pair ) ( mounted to detect the information bit of barcode. ) ( ) ( FLAG: A flag that is set when RBS detects light and ) ( cleared only when RBS detects black. This keeps the robot ) ( from reading the same sync line more than once. ) ( ) ( BCODE: The value of the information bits of the ) ( barcode. ) ( ) ( INC: A counter variable that keeps track of the ) ( number of sync lines read, so that the correct value can ) ( be added to bcode. Each information bit of the barcode is ) ( assigned a different value: 4, 2, and 1. That value is ) (added to bcode if the information bit is detected. ) (===========================================================) FORGET BAR : BAR ( -- ) RBS @ 70 < IF 0 FLAG ! THEN (clear flag if RBS detects black) RBS @ D0 > IF (If RBS detects white) FLAG @ 0= IF (If flag is cleared) INC @ 0= IF (If counter = 0) 0 BCODE ! THEN (Reset the barcode variable) INC 1+! (Increment the counter) LBS @ 70 > IF (If LBS detects white) INC @ 1 = IF 4 BCODE +! THEN (If counter = 1 add 4 to bcode) INC @ 2 = IF 2 BCODE +! THEN (If counter = 2 add 2 to bcode) INC @ 3 = IF 1 BCODE +! THEN (If counter = 3 add 1 to bcode) THEN (Set flag variable to ensure sync line is read only once) 1 FLAG ! THEN THEN ( Once inc = 3, barcode has been read.) ( Buzzer must now sound the value of barcode.) INC @ 2 > IF FFFF L-WHEEL ! FFFF R-WHEEL ! (Stop wheels) BCODE @ DUP 0= IF ELSE (If bcode != 0) 0 DO (bcode is on stack as first parameter for DO loop) 02 PORTC C! (Enable buzzer) 800 0 DO LOOP (Pause) 00 PORTC C! (Disable buzzer) A00 0 DO LOOP (Pause) LOOP (Repeat n times, where n = bcode) THEN 0 INC ! (Reset the counter) THEN ;