28125 Parallax Inc, 28125 Datasheet - Page 154

TEXT ROBOTICS

28125

Manufacturer Part Number
28125
Description
TEXT ROBOTICS
Manufacturer
Parallax Inc
Datasheet

Specifications of 28125

Title
Robotics with the Boe-Bot
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
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
the
to do.
RETURN
' Ramp up right rotate.
FOR pulseCount = 0 TO 30
NEXT
' Ramp down right rotate
FOR pulseCount = 30 TO 0
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.
PULSOUT 13, 750 + pulseCount
PULSOUT 12, 750 + pulseCount
PAUSE 20
PULSOUT 13, 750 + pulseCount
PULSOUT 12, 750 + pulseCount
PAUSE 20
command make up the code block that does the job you want the subroutine
RETURN
command. The commands between the label and

Related parts for 28125