Page 140 ·
Robotics with the Boe-Bot
' Ramp up right rotate.
FOR pulseCount = 0 TO 30
PULSOUT 13, 750 + pulseCount
PULSOUT 12, 750 + pulseCount
PAUSE 20
NEXT
' Ramp down right rotate
FOR pulseCount = 30 TO 0
PULSOUT 13, 750 + pulseCount
PULSOUT 12, 750 + pulseCount
PAUSE 20
NEXT
√
Open ForwardLeftRightBackward.bs2 from Activity #1, and save it as
ForwardLeftRightBackwardRamping.bs2.
√
Modify the new program so your Boe-Bot will ramp into and out of each
maneuver. Hint: you might use the code snippets above, and similar snippets
from StartAndStopWithRamping.bs2.
ACTIVITY #5: SIMPLIFY NAVIGATION WITH SUBROUTINES
In the next chapter, your Boe-Bot will have to perform maneuvers to avoid obstacles.
One of the key ingredients to avoiding obstacles is executing pre-programmed
maneuvers. One way of executing pre-programmed maneuvers is with subroutines. This
activity introduces subroutines, and also two different approaches to creating reusable
maneuvers with subroutines.
Inside the Subroutine
There are two parts of a PBASIC subroutine. One part is the subroutine call. It’s the
command in the program that tells it to jump to the reusable part of code, then come back
when it’s done. The other part is the actual subroutine. It starts with a label that serves
as its name and ends with a
RETURN
command. The commands between the label and
the
RETURN
command make up the code block that does the job you want the subroutine
to do.