Datasheet

Page 132ยท Applied Robotics with the SumoBot
โˆš In order from BIT0 to BIT6, test the sensors in this order: infrared object
detectors - right side, right front, left front, left side. QTI line sensors - right
front, left front, pushbutton.
ACTIVITY #8: VARIABLE MANAGEMENT FOR LARGE PROGRAMS
When you have a project with a lot of sensors and programmed machine reactions,
variable space can become pretty tight. For example, the program in the previous activity
uses three words and one byte. There's one byte to take each QTI reading, and another to
store the QTI threshold. All three of these bytes are used at the beginning of the
program, but only one (threshold) is accessed repeatedly as the program runs. Since
threshold isn't even changed repeatedly as the program runs, it's not necessarily the best
use of a RAM variable either.
This activity uses the techniques introduced in Chapter 2, Activity #2 to use and reuse
temporary variables. As you go through the activities in this book, you will use the same
few temporary variables to monitor sensors, control servos, log data, and perform a
variety of maneuvers. In virtually every subroutine you build to perform these functions,
the same few variables will be used in different ways. Even after the activities in this
book, you can continue to add functionality to your SumoBot, without worrying that the
next sensor might take up too much RAM.
Incorporating Temporary Variables into SensorsWithByteDisplay.bs2
It's important to modify the sensor testing program (SensorsWithByteDisplay.bs2) so that
it uses the memory management techniques introduced in ThreeVariablesManyJobs.bs2.
Specifically, it has to use and re-use temporary variables and use EEPROM to store and
access values that don't change frequently. After the program has been modified, features
like more sensors, servo control, navigation, and datalogging can be added in many cases
without ever having to declare any more RAM variables.
โˆš Start by saving SensorsWithByteDisplay.bs2 as SensorsWithTempVariables.bs2.
โˆš Next, the
qtiLeft, qtiRight, and qtiThreshold variable declarations need to
be commented out. In place of these three variables, you can use two word
variables -
temp (short for temporary) and multi (short for multipurpose).
' -----[ Variables ]---------------------------------------------------
' qtiLeft VAR Word ' Stores left QTI time
' qtiRight VAR Word ' Stores right QTI time