Page 258 ·
Robotics with the Boe-Bot
A second feature of a program for turning away from drop-offs is adjustable distance.
You may want your Boe-Bot to only take one pulse forward between checking the
detectors, but as soon as a drop-off is detected, you may want your Boe-Bot to take
several pulses worth of turn before checking the detectors again.
Just because you are taking multiple pulses in an evasive maneuver, it doesn’t mean you
have to return to whiskers-style navigation. Instead, you can add a
pulseCount
variable
that you can use to set to the number of pulses to deliver for a maneuver. The
PULSOUT
command can be placed inside a
FOR…NEXT
loop that executes
FOR 1 TO pulseCount
pulses. For one pulse forward,
pulseCount
can be 1, for ten pulses left,
pulseCount
can be set to 10, and so on.
Example Program – AvoidTableEdge.bs2
√
Open FastIrNavigation.bs2 and save it as AvoidTableEdge.bs2.
√
Modify the program so that it matches the example program. This will involve
adding variables, modifying the
IF…THEN
statements, and nesting the
PULSOUT
commands inside a
FOR…NEXT
loop. Be careful to make sure that all the
pulseLeft
and
pulseRight
variable values inside the
IF…THEN
statement are
properly adjusted. Their values are different from the ones in
FastIrNavigation.bs2 because the rules of the course are different.
√
Reconnect your board and servos.
√
Test the program on your electrical tape delimited course.
√
If you decide to try a tabletop, remember to follow the testing and spotting tips
discussed earlier.
' Robotics with the Boe-Bot - AvoidTableEdge.bs2
' IR detects object edge and navigates to avoid drop-off.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
irDetectLeft VAR Bit ' Variable declarations.
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
loopCount VAR Byte
pulseCount VAR Byte