'******************************************************************** ' OMSI BOT 02-16-2000 ' This code is for a Mini Sumo Robot. It uses a cds sensor to ' to detect a white line, then it spins around. If an object ' is detected with the iodx (IR Object Detector) the motor on ' the opposite side rotate faster to turn toward the object. ' Remember to find the deadzone or neutral of the servos. ' this example code the dead zone is set to 150. ' ' How I/O pins are used: ' ' pin 0 = Piezo - output - Makes Sounds ' pin 1 = LED1 - output - LED1 on or off ' pin 2 = LED2 - output - LED2 on or off ' pin 3 = Servo Right - output - 150 dead zone ' pin 4 = Servo Left - output - 150 dead zone ' pin 5 = IODR - input - IR Object Detector Right ' pin 6 = IODL - input - IR Object Detector Left ' pin 7 = CDS - input - Reads value of light ' ' Servo Right SR pin 3 : Forward = -20 Deadzone = 150 Reverse = +20 ' Servo Left SL pin 3 : Forward = -20 Deadzone = 150 Reverse = +20 ' '******************************************************************** Variables: Symbol thres = b0 ' Threshold for light level Symbol srvr = b3 ' Servo Right Symbol srvl = b4 ' Servo Left Symbol cds = b7 ' Hold current light level Symbol led1 = pin1 ' LED 1 Symbol led2 = pin2 ' LED 2 Symbol iodr = pin5 ' Infrared Object Detector Right Symbol iodl = pin6 ' Infrared Object Detector Left Symbol dvr = 150 ' Deadzone for Right Servo Symbol dvl = 150 ' Deadzone for Left Servo '******************************************************************** Initialize: dirs = %00011111 ' Sets i/o pin directions ' Play a short tune sound 0,(60,15,75,15,90,15,60,30,60,15,75,15,90,15,60,30) pause 4000 ' Wait about 4 seconds pot 7,128,cds ' Get Dark Threshold thres = cds / 2 Main: pot 7,128,cds ' Read cds for White Line if cds < thres then online ' Is it White? Goto online. led1 = iodr ' LED1 on if object detected led2 = iodl ' LED2 on if object detected ' If right and left detectors see object see something ' then rush forward. If object detected on right then turn ' right. If object detected on left then turn left. ' If neither right or left detectors see object then go ' forward slowly. if iodr = 1 and iodl = 1 then forw if iodr = 1 then right if iodl = 1 then left ' Move forward slowly srvr = dvr - 5 srvl = dvl - 5 drive: pulsout 3, srvr ' Drive Right Servo pulsout 4, srvl ' Drive Left Servo goto Main forw: ' Drive forward Fast srvr = dvr - 20 srvl = dvl - 20 goto drive right: ' Turn right srvr = dvr - 20 srvl = dvl goto drive left: srvr = dvr ' Turn left srvl = dvl - 30 goto drive online: ' On a White Line for b1 = 0 to 8 ' Back Up a Bit pulsout 3, 80 pulsout 4, 80 pause 20 next for b1 = 0 to 23 ' Spin Toward Center pulsout 3, 120 pulsout 4, 80 pause 20 next goto Main