Chapter 4: Boe-Bot Navigation
· Page 145
√
Enter, save, and run MovementWithVariablesAndOneSubroutine.bs2.
' Robotics with the Boe-Bot - MovementWithVariablesAndOneSubroutine.bs2
' Make a navigation routine that accepts parameters.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
counter VAR Word
pulseLeft VAR Word
pulseRight VAR Word
pulseCount VAR Byte
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
' Forward
pulseLeft = 850: pulseRight = 650: pulseCount = 64: GOSUB Navigate
' Left turn
pulseLeft = 650: pulseRight = 650: pulseCount = 24: GOSUB Navigate
' Right turn
pulseLeft = 850: pulseRight = 850: pulseCount = 24: GOSUB Navigate
' Backward
pulseLeft = 650: pulseRight = 850: pulseCount = 64: GOSUB Navigate
END
Navigate:
FOR counter = 1 TO pulseCount
PULSOUT 13, pulseLeft
PULSOUT 12, pulseRight
PAUSE 20
NEXT
PAUSE 200
RETURN
Did your Boe-Bot perform the familiar forward-left-right-backward sequence? This
program may be difficult to read at first, because the instructions are arranged in a new
way. Instead of having each variable statement and each
GOSUB
command on a different
line, they are grouped together on the same line and separated by colons. Here, the