jhill44
Newbie level 1
building a bot that moves autonomously w obstacle avoidance utilizing a basic stamp and an ir control freak module... but i am having trouble stopping the bot. i am initiating the movement of the bot with a universal remote and attempting to stop the bot from moving by pushing a button on the remote. however this task seems to be more difficult then i had thought. for some reason i cant get the basic stamp to exit out of the loop command to stop the bot. there are no problems funning the bot with obs. avoidance subroutines but it just doesn't want to stop. here is the program.....
[/code]
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "program running"
'------------[variables]-----------------------------------------------
irdetectleft VAR BIT
irdetectright VAR BIT
irdetectcenter VAR BIT
BUTTON_CODE VAR BYTE 'Infrated Button Code
DEVICE_CODE VAR BYTE 'Infrared Device Code
'------------[main routine]--------------------------------------------
'***************************
'* MAIN PROGRAM *
'***************************
MAIN:
GOSUB COMMAND_030 'Send the Remote control Command to Infrated Control Freak
GOTO MAIN
COMMAND_030:
SEROUT 14, 16468, [30]
poop:
SERIN 15, 16468,1000,main, [device_code, button_code]
DEBUG "button code =", DEC Button_Code," Device Code =",DEC Device_code," ", CR
DEBUG " ",CR
DEBUG "____________________________",CR
DEBUG HOME
IF Button_code = 21 AND Device_code = 1 THEN obstacle_avoidance
IF BUTTON_code = 101 AND device_code = 1 THEN STOP_bot
GOTO poop
'----------[subroutines]----------------------------------------------
obstacle_avoidance:
DO
FREQOUT 8, 1, 38500
irdetectleft = IN9
FREQOUT 2,1, 38500
irdetectright = IN0
FREQOUT 3,1, 38500
irdetectcenter = IN4
IF (irdetectcenter = 0) THEN
GOSUB back_up
ELSEIF (irdetectleft = 0) THEN
GOSUB turn_right
ELSEIF (irdetectright = 0) THEN
GOSUB turn_left
ELSE
GOSUB forward_pulse
ENDIF
LOOP
forward_pulse:
PAUSE 100
SEROUT 16, 8276, ["!A1E", CR]
SEROUT 16, 8276, ["!b1E", CR]
RETURN
turn_left:
PAUSE 20
SEROUT 16, 8276, ["!A14", CR]
SEROUT 16, 8276, ["!b14", CR]
RETURN
turn_right:
PAUSE 20
SEROUT 16, 8276, ["!A1E", CR]
SEROUT 16, 8276, ["!b1E", CR]
RETURN
back_up:
PAUSE 20
SEROUT 16, 8276, ["!a1E", CR]
SEROUT 16, 8276, ["!B1E", CR]
RETURN
STOP_bot:
PAUSE 20
SEROUT 16, 8276, ["!A00", CR]
SEROUT 16, 8276, ["!B00", CR]
[/code]
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "program running"
'------------[variables]-----------------------------------------------
irdetectleft VAR BIT
irdetectright VAR BIT
irdetectcenter VAR BIT
BUTTON_CODE VAR BYTE 'Infrated Button Code
DEVICE_CODE VAR BYTE 'Infrared Device Code
'------------[main routine]--------------------------------------------
'***************************
'* MAIN PROGRAM *
'***************************
MAIN:
GOSUB COMMAND_030 'Send the Remote control Command to Infrated Control Freak
GOTO MAIN
COMMAND_030:
SEROUT 14, 16468, [30]
poop:
SERIN 15, 16468,1000,main, [device_code, button_code]
DEBUG "button code =", DEC Button_Code," Device Code =",DEC Device_code," ", CR
DEBUG " ",CR
DEBUG "____________________________",CR
DEBUG HOME
IF Button_code = 21 AND Device_code = 1 THEN obstacle_avoidance
IF BUTTON_code = 101 AND device_code = 1 THEN STOP_bot
GOTO poop
'----------[subroutines]----------------------------------------------
obstacle_avoidance:
DO
FREQOUT 8, 1, 38500
irdetectleft = IN9
FREQOUT 2,1, 38500
irdetectright = IN0
FREQOUT 3,1, 38500
irdetectcenter = IN4
IF (irdetectcenter = 0) THEN
GOSUB back_up
ELSEIF (irdetectleft = 0) THEN
GOSUB turn_right
ELSEIF (irdetectright = 0) THEN
GOSUB turn_left
ELSE
GOSUB forward_pulse
ENDIF
LOOP
forward_pulse:
PAUSE 100
SEROUT 16, 8276, ["!A1E", CR]
SEROUT 16, 8276, ["!b1E", CR]
RETURN
turn_left:
PAUSE 20
SEROUT 16, 8276, ["!A14", CR]
SEROUT 16, 8276, ["!b14", CR]
RETURN
turn_right:
PAUSE 20
SEROUT 16, 8276, ["!A1E", CR]
SEROUT 16, 8276, ["!b1E", CR]
RETURN
back_up:
PAUSE 20
SEROUT 16, 8276, ["!a1E", CR]
SEROUT 16, 8276, ["!B1E", CR]
RETURN
STOP_bot:
PAUSE 20
SEROUT 16, 8276, ["!A00", CR]
SEROUT 16, 8276, ["!B00", CR]
Code: