Chapter 5: Tactile Navigation with Whiskers
· Page 181
The
Turn_Left
,
Turn_Right
, and
Back_Up
subroutines should look fairly familiar, but
the
Forward_Pulse
subroutine has a twist. It just sends one pulse, then returns. This is
really important, because it means the Boe-Bot can check its whiskers between each
forward pulse. That means the Boe-Bot checks for obstacles roughly 40 times per second
as it travels forward.
Forward_Pulse:
PULSOUT 12,650
PULSOUT 13,850
PAUSE 20
RETURN
Since each full speed forward pulse makes the Boe-Bot roll around half a centimeter, it’s
a really good idea to only send one pulse, then go back and check the whiskers again.
Since the
IF…THEN
statement is inside a
DO…LOOP
, each time the program returns from a
Forward_Pulse
, it gets to
LOOP
, which sends the program back up to
DO
. What happens
then? The
IF…THEN
statement checks the whiskers all over again.
Your Turn
The
FOR
...
NEXT
loop
EndValue
arguments in the
Back_Right
and
Back_Left
routines
can be adjusted for more or less turn, and the
Back_Up
routine can have its
EndValue
adjusted to back up less for navigation in tighter spaces.
√
Experiment with the
FOR
...
NEXT
loop
EndValue
arguments in the navigation
routines in RoamingWithWhiskers.bs2.
You can also modify your
IF…THEN
statements to make the LED indicators from the
previous activity broadcast what maneuver the Boe-Bot is in by adding
HIGH
and
LOW
commands to control the LED circuits. Here is an example.
IF (IN5 = 0) AND (IN7 = 0) THEN
HIGH 10
HIGH 1
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5 = 0) THEN
HIGH 10
GOSUB Back_Up