Parallax Boe-Bot Student Manual page 192

Hide thumbs Also See for Boe-Bot:
Table of Contents

Advertisement

Page 178 · Robotics with the Boe-Bot
Programming the Boe-Bot to Navigate Based on Whisker Inputs
This next program makes the Boe-Bot go forward until it encounters an obstacle. In this
case, the Boe-Bot knows when it encounters an obstacle by bumping into it with one or
both of its whiskers. As soon as the obstacle is detected by the whiskers, the navigation
routines and subroutines developed in Chapter 4 will make the Boe-Bot back up and turn.
Then, the Boe-Bot resumes forward motion until it bumps into another obstacle.
In order to do that, the Boe-Bot needs to be programmed to make decisions. PBASIC has
a command called an
IF...THEN
statements is:
IF (condition) THEN...{ELSEIF (condition)}...{ELSE}...ENDIF
The "..." means you can place a code block (one or more commands) between the
keywords. The next example program makes decisions based on the whisker inputs, and
then calls subroutines to make the Boe-Bot take action. The subroutines are similar to the
ones you developed in Chapter 4. Here is how
IF (IN5
= 0) AND (IN7 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (IN7
GOSUB Back_Up
GOSUB Turn_Left
ELSE
GOSUB Forward_Pulse
ENDIF
Example Program: RoamingWithWhiskers.bs2
This program demonstrates one way of evaluating the whisker inputs and deciding which
navigation subroutine to call using
Reconnect power to your board and servos.
Enter, save, and run RoamingWithWhiskers.bs2.
statement that makes decisions. The syntax for
IF...THEN
' Both whiskers detect obstacle,
' back up & U-turn (left twice)
= 0) THEN
' Left whisker contacts
' Back up & turn right
= 0) THEN
' Right whisker contacts
' Back up & turn left
' Both whiskers 1, no contacts
' Apply a forward pulse &
' check again
.
IF...THEN
IF...THEN
is used.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Boe-Bot and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF