Chapter 5: Tactile Navigation with Whiskers
· Page 183
Commands for both condition2 and condition1
ELSE
Commands for condition1 but not condition2
ENDIF
ELSE
Commands for not condition1
ENDIF
There is an example of nested
IF…THEN
statements in the routine that detects consecutive
alternate whisker contacts in the next program.
Example Program: EscapingCorners.bs2
This program will cause your Boe-Bot to execute a U-turn at either the fourth or fifth
alternate corner, depending on which whisker was pressed first.
√
Enter, save, and run EscapingCorners.bs2.
√
Test this program by pressing alternate whiskers as the Boe-Bot roams.
Depending on which Whisker you started with, the Boe-Bot should execute its
U-Turn maneuver after either the fourth or fifth consecutive whisker press.
' -----[ Title ]--------------------------------------------------------------
' Robotics with the Boe-Bot - EscapingCorners.bs2
' Boe-Bot navigates out of corners by detecting alternating whisker presses.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
DEBUG "Program Running!"
' -----[ Variables ]----------------------------------------------------------
pulseCount VAR Byte ' FOR...NEXT loop counter.
counter VAR Nib ' Counts alternate contacts.
old7 VAR Bit ' Stores previous IN7.
old5 VAR Bit ' Stores previous IN5.
' -----[ Initialization ]-----------------------------------------------------
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
counter = 1 ' Start alternate corner count.
old7 = 0 ' Make up old values.
old5 = 1
' -----[ Main Routine ]-------------------------------------------------------