Code ' -----[ Title ]------------------------------------------------------- ' ' File...... linetrack.BAS ' Purpose... Robot to follow Black Line BasicBoard -> IRD Line Detector ' Author.... Chuck Hellebuyck ' Started... August 10, 2002 ' Updated... ' -----[ Program Description ]----------------------------------------- ' ' This Program uses the BasicBoard to control a Servo robot platform. The ' robot has a Lynxmotion infrared 3 element line detector module mounted ' under its platform. This program will drive the robot forward while it ' scans for the black line under the detector. If the black line hits ' one of the outer elements, the robot will correct back to center as ' it moves forward. The object is to have the robot follow the line ' from one end to the other. ' ' P0 Left Detector Element Output ' P1 Center Detector Element Output ' P2 Right Detector Element Output ' P8 Left Wheel Servo ' P9 Right Wheel Servo ' -----[ Revision History ]-------------------------------------------- ' ' ' -----[ Variables & Constants ]--------------------------------------- ' LSENS var in0 'Left detector element CSENS var in1 'Center detector element RSENS var in2 'Right detector element serv1 con p8 ' Left wheel servo connection to P8 serv2 con p9 ' Right wheel servo connection to P9 ' -----[ Variables ]--------------------------------------------------- ' move var byte 'robot movement variable x var byte 'general purpose variable ' -----[ Initialization ]---------------------------------------------- ' ' -----[ Main Code ]--------------------------------------------------- ' main: if csens = 1 and lsens = 1 and rsens = 1 then lost 'Can't find line if lsens = 0 and rsens = 0 then rest 'Both outer sensors see black if lsens = 0 then left 'Black line sensed left if rsens = 0 then right 'Black line sensed right if csens = 0 then center 'Black line in center of robot goto main 'Loop back and check sensors '*** Line at center drive robot routine *** center: move = 5 'Set max movement to 5 units for x = 1 to move 'Loop for 1 to 5 units servo serv1, 1200, 1 'Drive left wheel forward servo serv2, -1200, 1 'Drive right wheel forward if lsens = 0 or rsens = 0 then main 'If black line left or right return next 'Continue loop goto main 'Return to main loop '*** Line sensed at left, drive robot routine *** left: move = 5 'Set max movement to 5 units for x = 1 to move 'Loop for 1 to 5 units servo serv2, -1200, 1 'Drive right wheel forward if lsens = 1 then main 'If black line not sensed then main next 'Continue loop goto main 'Return to main loop '*** Line sensed at right, drive robot routine *** right: move = 5 'Set max movement to 5 units for x = 1 to move 'Loop for 1 to 5 units servo serv1, 1200, 1 'Drive left wheel forward if rsens = 1 then main 'If black line not sensed then main next 'Continue loop goto main 'Return to main loop '*** Cannot find black line routine *** lost: servo serv1, 1200, 1 'Drive left wheel forward one unit servo serv2, -1200, 1 'Drive right wheel forward one unit if lsens = 0 or rsens = 0 or csens = 0 then main 'Check for line goto lost 'Keep searching line not found '*** Stop robot routine *** rest: pause 10 'Delay for 10 milliseconds goto main 'Jump to Main loop end