'{$STAMP BS2} ' CMUcam Boe-Bot Demo Program 3 ' Copyright 2002, Seattle Robotics ' Basic Stamp 2 ' CMUcam jumpered for Baud 9600 ' make "red" a fixed color RcvData Var Byte(10) n var byte Confid var byte ' Pause and flash leds 1 sec for CMUcam startup high 1 'turn on cmucam high 3 'flash yel status led pause 200 low 3 pause 200 high 5 'flash grn status led pause 200 low 5 pause 200 high 13 'flash red status led pause 200 low 13 pause 200 ' Send "reset" to sync CMUcam and Stamp serout 10, 84, ["RS",CR] serin 11, 84, [Wait (":")] pause 1000 ' Green LED on serout 10, 84, ["L1 1",CR] serin 11, 84, [Wait (":")] pause 100 ' Turn on auto adjust for 5 seconds serout 10, 84, ["CR 18 44",CR] serin 11, 84, [Wait (":")] pause 100 ' Pause 5 seconds for CMUcam to auto adjust to lighting conditions pause 5000 ' Turn off auto adjust serout 10, 84, ["CR 18 44 19 32",CR] serin 11, 84, [Wait (":")] pause 100 high 5 'flash grn status light to show auto adjust done pause 200 low 5 ' Green LED auto mode serout 10, 84, ["L1 2",CR] serin 11, 84, [Wait (":")] pause 100 ' Give user time to place color target close in front of camera 'pause 5000 ' Send command - Set poll mode - only sends one return packet - ' of data after each command - reduces data flow serout 10, 84, ["PM 1",CR] serin 11, 84, [Wait (":")] pause 100 ' Send command - Set raw data mode - also suppress Ack:/Nak: to - ' further reduce serial data serout 10, 84, ["RM 3",CR] pause 100 ' Track Window command looks at the center of CMUcam image - ' grabs the color information and sends to the Track Color function ' Send command - Track window ''serout 10, 84, ["TW",CR] ' Ignore the S packet and M packet from TW pause 2000 Main: ' Send command - Track color (with no arguments) - ' will track red color serout 10, 84, ["TC 235 240 14 18 14 18",CR] serin 11, 84, [STR RcvData\10] Confid = RcvData(9) ' 45 is aprox H center If RCVData(2) > 65 And Confid > 10 Then Left If RCVData(2) < 25 And Confid > 10 Then Right If RCVData(8) < 150 And Confid > 15 Then Fwd ' Trim the pulsout numbers for your servos Goto Main Left: high 13 for n = 1 to 10 pulsout 14,680 ' 680 right servo pulsout 15,680 ' 680 left servo next low 13 Goto main Right: high 3 for n = 1 to 10 pulsout 14,820 ' right servo pulsout 15,820 ' left servo next low 3 Goto main Fwd: high 5 for n = 1 to 10 pulsout 14,820 ' right servo pulsout 15,680 ' left servo pause 15 next low 5 Goto main