Datasheet

Chapter 5: Debugging and Datalogging · Page 209
Before testing each of these questions, it's important to make a disposable copy of the
SumoWrestler.bs2.
Save SumoWrestler.bs2 as CompCodeLedTest.bs2
Testing for a Cleared Bit
The first question was "...did the irRf bit get accidentally cleared somewhere in the
program?" Some LED indicator code can certainly answer this question:
IF irRS = 1 THEN HIGH LedSpeaker ELSE LOW LedSpeaker
Where you put this line of code can make a big difference in your test. For example, if
it's placed just after the sensor subroutines the program won't have a chance to do all the
other things it does, which might include a coding mistake that clears the
irRF bit. A
better way to test this question would be to place the LED indicator code just before the
sensor subroutines get called. That way, the program will go all the way through its other
loops giving you better chances of exposing the bug.
Modify the
Servos_And_Sensors subroutine in CompCodeLedTest.bs2 as
shown here.
' -----[ Subroutine - Servos_And_Sensors ]------------------------------------
Servos_And_Sensors:
GOSUB Pulse_Servos ' Call Pulse_Servos subroutine
' Call sensor subroutine(s).
IF irRS = 1 THEN HIGH LedSpeaker ELSE LOW LedSpeaker ' <--- Add
sensors = 0 ' Clear previous sensor values
GOSUB Read_Object_Detectors ' Call Read_Object_Detectors
GOSUB Read_Line_Sensors ' Look for lines
RETURN
Run the modified program with the SumoBot's 3-position power switch set to 1.
Make sure no objects are in view of the SumoBot's other three object detectors.
Verify that it correctly indicates when the right side object detector sees and does
not see an object. (Remember to press the SumoBot's Reset button and wait 5
seconds.