‘ Boe-Bot PBASIC Roaming code
DO
IF (lwhisker = 0) AND (rwhisker = 0) THEN
‘ can’t go forward
‘‘‘DEBUG “STUCK!”,13
GOSUB backup
GOSUB left
ELSEIF lwhisker = 0 THEN ‘ can’t go left
‘‘‘DEBUG “LWHISKER”,13
GOSUB right
ELSEIF rwhisker = 0 THEN ‘ can’t go right
‘‘‘DEBUG “RWHISKER”,13
GOSUB left
ELSE ‘ go forward
‘‘‘DEBUG “FORWARD”,13
GOSUB forward
ENDIF
LOOP
‘ RoboProp-Bot Spin Roaming code
repeat
if left_bumper AND right_bumper
‘‘‘ can’t go forward
‘‘‘robot.debug(string(“STUCK!”,13))
backup(2000)
left(1000)
elseif left_bumper ‘ can’t go left
‘‘‘robot.debug(string(“LBUMPER”,13))
right(50)
elseif right_bumper ‘ can’tgo right
‘‘‘robot.debug(string(“RBUMPER”,13))
left(50)
else ‘ go forward
‘‘‘robot.debug(string(“FORWARD”,13))
forward(50)
LISTING 1. PBASIC on Boe vs. Spin on RoboProp.
‘ helper function for checking the state
‘ of the left bumper
pub left_bumper
return robot.ain(lbumper) > BUMPER
‘ helper function for driving forward
pub forward(n) ‘ most common movement, falls
into move
‘‘‘robot.debug(string(13,”FWD”,13))
move(n,speed,speed)
Simple helper functions make it easier to read the code
for beginners and advanced users alike.
Note that the debug serial output is commented out
in all of the examples shown.
LISTING 2. Sample Spin helper functions.
‘ Roaming mode
repeat
‘ go faster if chased
if rear_bumper
‘‘‘robot.debug(string(“GO FAST”,13))
speed := 300
else
speed := 50
Here is what the main body of code looks like after
adding support for the rear virtual bumper.
if left_bumper AND right_bumper
‘‘‘ can’t go forward
‘‘‘robot.debug(string(“STUCK!”,13))
backup(2000)
left(1000)
elseif left_bumper ‘ can’t go left
‘‘‘robot.debug(string(“LBUMPER”,13))
right(50)
elseif right_bumper ‘ can’tgo right
‘‘‘robot.debug(string(“RBUMPER”,13))
left(50)
else ‘ go forward
‘‘‘robot.debug(string(“FORWARD”,13))
forward(50)
Robbie sprints away when any object approaches too
closely from behind.
That was easy! Just imagine how much fun your cat
would have chasing a robot that keeps running away
from him.
LISTING 3. Roaming mode with rear sensor watching for pesky cats.
sensors, and I also decided to add another sensor to boot:
a rear facing short range IR sensor. The three new IR
sensors act like virtual bumpers, allowing Robbie to react
to his environment, and back out of corners.
I added the new sensors as follows:
• Left front virtual bumper on AN3.
To demonstrate Robbie’s new capabilities, I wrote a
more sophisticated version of my Boe-Bot roaming code in
SERVO 09.2011 53