'OctoLine1.bs2 - RG0306.10 V02 'Lets OctoBot Survivor perform simple line following behavior using LynxMotion 'Tracker Version 2.0 circuit. Based on LynxMotion demo program ltrack1.bas ' 'Connect Tracker PCBA to X2 Header on bottom of OctoBot ' ' FUNCTION WIRE COLOR X2 HEADER ' ---------------- ---------- --------- ' Ground black pin 1 ' IN5 right sense orange pin 2 ' IN7 center sense blue pin 3 ' IN9 left sense yellow pin 4 ' none - pin 5 ' +5V power red pin 6 line_was var byte i var byte '*** OctoBot command set halt con 0 'stops the robot's motors forward con 1 'start the robot moving forward backward con 2 'start the robot moving backward left con 3 'start the robot rotating left right con 4 'start the robot rotating right lled_on con 5 'left LED on lled_off con 6 'left LED off rled_on con 7 'right LED on rled_off con 8 'right LED off sound con 9 'Plays a tone get_temp con 10 'returns temperature around the batteries in Celsius get_bat con 11 'returns 100x battery voltage; i.e. 725 = 7.25 Volts go_charge con 12 'finds charger, charges, returns a 255 when complete '*** program begins here high 14 'signal "not ready" to OctoBot PIC pause 500 'let OctoBot power up serout 14,84,[55] 'send "55" to indicate go into slave mode high 14 'signal "not ready" to OctoBot PIC pause 1000 'wait a second for i=1 to 10 'flash OctoBot LEDs serout 14,84,[255,lled_on] 'left LED on pause 50 serout 14,84,[255,lled_off] 'left LED off pause 50 serout 14,84,[255,rled_on] 'right LED on pause 50 serout 14,84,[255,rled_off] 'right LED off pause 50 next MainLoop: 'if line seen, adjust direction if in7 = 0 then StayFwd 'if center_sensor = 0 if in5 = 0 then MoreRight 'if right_sensor = 0 if in9 = 0 then MoreLeft 'if left_sensor = 0 'if line not seen, repeat last action if line_was = 1 then MoreLeft if line_was = 2 then MoreRight if line_was = 3 then StayFwd goto MainLoop '*** SUBROUTINES MoreLeft: 'adjust to left line_was = 1 serout 14,84,[255,left] pause 10 serout 14,84,[255,lled_off] 'left LED off pause 10 serout 14,84,[255,rled_on] 'right LED on goto MainLoop MoreRight: 'adjust to right line_was = 2 serout 14,84,[255,right] pause 10 serout 14,84,[255,lled_on] 'left LED on pause 10 serout 14,84,[255,rled_off] 'right LED off goto MainLoop StayFwd: 'keep going forward line_was = 3 serout 14,84,[255,forward] pause 10 serout 14,84,[255,lled_on] 'left LED on pause 10 serout 14,84,[255,rled_on] 'right LED on goto MainLoop 'END