'Complete program to run a BOE BOT equiped with (2) IR sensors, (1) photoresistor, (1) piezospeaker ' 'Purpose...... Ever wanted TO have a robot that acts just like a pet OR an insect? This is the ' source code you need! Feel free to modify the program, open source ;) 'Creator...... Ghostface 'Program...... BOE-BUG 1.0 'Observations. This program is very much like those you can find in the book "Robotics with the Boe-Bot" by ' Andy Lindsay. It is a compilation of all the programs used exept the wisker one. 'E-mail....... neomix_law@hotmail.com ' {$STAMP BS2} ' {$PBASIC 2.5} '--------[Variables]-------- leftir VAR Nib rightir VAR Nib pulse VAR Byte obscurity VAR Word freqSelect VAR Nib irFrequency VAR Word irDetectLeft VAR Bit irDetectRight VAR Bit pulseLeft VAR Word pulseRight VAR Word pulseCount VAR Byte '--------[Initialization]-------- FREQOUT 0, 100, 3000 'Signals the human that FREQOUT 0, 200, 2589 'the robot is operational '--------[Main Routine]-------- '======================================================================================================================== DO GOSUB Core 'Executes the core program wich is the principal program 'that will run all the other sub routines. It is a sub routine LOOP 'it self. '======================================================================================================================== '--------[Core Program (1)]-------- Core: DEBUG CLS, "IR OBJECT ZONE", CR, "Left Right", CR, "----- -----" DO GOSUB Get_distances GOSUB Display_distances ' GOSUB Hide_shadow IF (leftir = 5) AND (rightir = 5) THEN GOSUB forward ELSEIF (leftir = 5) AND (rightir = 4) THEN GOSUB forward ELSEIF (leftir = 4) AND (rightir = 5) THEN GOSUB forward_1 ELSEIF (leftir = 4) AND (rightir = 4) THEN GOSUB forward ELSEIF (leftir = 4) AND (rightir = 3) THEN GOSUB forward ELSEIF (leftir = 3) AND (rightir = 4) THEN GOSUB forward ELSEIF (leftir = 3) AND (rightir = 3) THEN GOSUB forward_1 ELSEIF (leftir = 3) AND (rightir =< 2) THEN GOSUB back_1 GOSUB left_1 ELSEIF (leftir =< 2) AND (rightir= 3) THEN GOSUB back_1 GOSUB right_1 ELSEIF (leftir = 2) AND (rightir = 2) THEN GOSUB back_1 ELSEIF (leftir = 1) AND (rightir = 1) THEN GOSUB back ELSEIF (leftir = 0) AND (rightir = 0) THEN GOSUB left GOSUB back_1 GOSUB left ELSEIF (leftir = 5) AND (rightir = 3) THEN GOSUB left_1 ELSEIF (leftir = 3) AND (rightir = 5) THEN GOSUB right_1 ELSEIF (leftir = 5) AND (rightir =< 2) THEN GOSUB left GOSUB forward_1 GOSUB right ELSEIF (leftir =< 2) AND (rightir = 5) THEN GOSUB right GOSUB forward_1 GOSUB left ENDIF LOOP RETURN '======================================================================================================================== '--------[Sub routines (2)]-------- '----[Get_distances]---- Get_distances: leftir = 0 rightir = 0 FOR freqSelect = 0 TO 4 LOOKUP freqSelect, [37500, 38500, 39500, 40500, 41500], irFrequency FREQOUT 8,1,irFrequency irDetectLeft = IN9 leftir = leftir + irDetectLeft FREQOUT 2,1,irFrequency irDetectRight = IN1 rightir = rightir + irDetectRight PAUSE 100 NEXT RETURN '======================================================================================================================== '----[Hide_shadow]---- 'Hide_shadow: 'FOR pulse = 1 TO 2 ' HIGH 3 ' PAUSE 2 ' RCTIME 3,1,obscurity ' DEBUG HOME, "Level of obscurity = ", DEC5 obscurity 'Displays this pessage in case the robot is ' PAUSE 100 'connected to the PC by cable or wireless 'NEXT 'DEBUG CR, "Stop, final level of obscurity = ", DEC5 obscurity ' IF (obscurity <= 0005) THEN ' DEBUG CR, "Rate: Unapropriate to hide!" ' ELSEIF (obscurity >5) AND (obscurity <= 20) THEN ' DEBUG CR, "Rate: Unapropriate to hide!" ' ELSEIF (obscurity > 20) AND (obscurity <= 50) THEN ' DEBUG CR, "Rate: Medium to hide!" ' ELSEIF (obscurity > 50) AND (obscurity <= 100) THEN ' DEBUG CR, "Rate Good to hide" ' SLEEP 5 'Hibernates for ~5 seconds ' FREQOUT 0, 100, 2000 'Alerts its enviroment ' FREQOUT 0, 100, 2500 'that it is operational again ' ELSEIF (obscurity > 100) THEN ' DEBUG CR, "Rate: exelent to hide, preparing to hibernate!" ' SLEEP 20 'Hibernates for ~20 seconds ' FREQOUT 0, 200, 6666 ' ENDIF 'RETURN '======================================================================================================================== '----[Forward]---- forward: pulseLeft = 850: pulseRight = 650: pulseCount = 25 FOR pulse = 1 TO pulseCount PULSOUT 13, pulseLeft PULSOUT 12, pulseRight PAUSE 20 NEXT RETURN '======================================================================================================================== '----[Forward_1]---- forward_1: FOR pulse = 1 TO 20 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT RETURN '======================================================================================================================== '----[left]---- left: FOR pulse = 1 TO 20 PULSOUT 13, 650 PULSOUT 12, 650 PAUSE 20 NEXT RETURN '======================================================================================================================== '----[left_1]---- left_1: FOR pulse = 1 TO 20 PULSOUT 13, 650 PULSOUT 12, 757 PAUSE 20 NEXT RETURN '======================================================================================================================== '----[right]---- right: FOR pulse = 1 TO 20 PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT RETURN '======================================================================================================================== '----[right_1]---- right_1: FOR pulse = 1 TO 20 PULSOUT 13, 757 PULSOUT 12, 850 PAUSE 20 NEXT RETURN '======================================================================================================================== '----[back]---- back: FOR pulse = 1 TO 20 PULSOUT 13, 650 PULSOUT 12, 850 PAUSE 20 NEXT RETURN '======================================================================================================================== '----[back_1]---- back_1: FOR pulse = 1 TO 10 PULSOUT 13, 650 PULSOUT 12, 850 PAUSE 20 NEXT RETURN '======================================================================================================================== '----[Display_distances]---- Display_distances: DEBUG CRSRXY,2,3, DEC1 leftir, CRSRXY,9,3, DEC1 rightir RETURN '======================================================================================================================== '--------[End of program]-------- 'New updates comming soon, please be pacient and creative! 'For any questions or comments, contact me by e-mail :) '13/6/2005 by Ghostface