Parallax, Inc
http://www.parallaxinc.com
http://www.stampsinclass.com
Whisker Kit Instructions (June 2000)
•
Page
3
BASIC Stamp Boe-Bot Navigation Using Whiskers
Whiskers.bs2 is a simple roaming program example that uses Whiskers instead of infrared for object detection.
This program listing makes the Boe-Bot travel straight ahead while monitoring the whiskers to see if they have
bumped into an obstacle. As soon as an obstacle is detected, the Boe-Bot backs up, turns, and continues forward
until another obstacle is encountered.
When a whisker is pressed, due to an obstacle, the normally open switch closes. When this happens, the output
signal goes from high to low. I/O pins P10 and P5 are set to input and used to monitor the states of these switches.
The two whiskers may be in one of four states:
(1) Both high – no objects detected
(2) Left low, right high – object detected on the left, turn right.
(3) Right low, left high – object detected on the right, turn left.
(4) Both low – indicates a head-on collision with a wide object such as a wall.
' Whiskers.bs2 - Simple program for detecting objects
' with a BASIC Stamp II in a Boe-Bot
' Constant and Variable Definitions
'-----------------------------------------------------------------------------------
servo_left
con
15
' left servo on P15
servo_right
con
14
' right servo on P15
whisker_left
var
in10
' left whisker on P10
whisker_right
var
in5
' right whisker on P5
counter
var
word
' loop counter variable
' Main Program
'-----------------------------------------------------------------------------------
check_whiskers:
' check each whisker
if whisker_left = 0 and whisker_right = 0 then back
if whisker_left = 0 then right
if whisker_right = 0 then left
drive_servos:
' drive forward
pulsout servo_left,850
pulsout servo_right,650
pause 10
goto check_whiskers
back:
' backwards if both switches close
for counter = 0 to 100
pulsout servo_left,650
pulsout servo_right,850
next
return
goto drive_servos
left:
' turn left if right switch closes
gosub back
for counter = 0 to 50
pulsout servo_left,650
pulsout servo_right,650
next
goto drive_servos