Chapter 5: Tactile Navigation with Whiskers
· Page 185
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
How EscapingCorners.bs2 Works
Since this program is a modified version of RoamingWithWhiskers.bs2, only new
features related to detecting and escaping corners are discussed here.
Three extra variables are created for detecting a corner. The nibble variable
counter
can
store a value between 0 and 15. Since our target value for detecting a corner is 4, the size
of the variable is reasonable. Remember that a bit variable can store a single bit, either a
1 or a 0. The next two variables (
old7
and
old5
) are both bit variables. These are also
the right size for the job since they are used to store old values of
IN7
and
IN5
, which are
also bit variables.
counter VAR Nib
old7 VAR Bit
old5 VAR Bit
These variables have to be initialized (given initial values). For the sake of making the
program easier to read,
counter
is set to 1, and when it gets to 4 due to the fact that the
Boe-Bot is stuck in a corner, it is reset to 1. The
old7
and
old5
variables have to be set
so that it looks like one of the two whiskers was pressed some time before the program
started. This has to be done because the routine for detecting alternate corners always
compares an alternating pattern, either (
IN5
= 1
and
IN7 = 0
) or (
IN5 = 0
and
IN7 =
1
). Likewise,
old5
and
old7
have to be different from each other.