Datasheet

Chapter 5: Debugging and Datalogging ยท Page 217
performs. This kind of tool can be really helpful for isolating both program and circuit
bugs.
One important feature of this diagnostic tool, is that it all appears in conditional compiler
directives. Because of this, you will be able to change one value in your program, and
change it from a diagnostic tool back to competition code.
Incorporation Diagnostic Display Code in the SumoWrestler.bs2 Program
Watching the SumoBot's program play itself out in slow motion on the Debug Terminal
makes it a lot easier to isolate problems with sensors, in the program, and so on. It also
makes it easier to understand how the program reacts to various sensor conditions. This,
in turn makes it easier to refine and improve the program, and also to add more sensors.
The example program for this activity started as SumoWrestler.bs2. After renaming the
program, all the code that involves displaying the sensors, state, and maneuver values
were added, nested in conditional compiler directives. This makes it possible to use one
#DEFINE to change the program from a diagnostic tool to a competition program. The
Symbol the program will use for these conditional compiler directives is DEBUG_MODE.
' -----[ Compiler Definitions ]-----------------------------------------------
#DEFINE DEBUG_MODE = 1 ' 1 -> full debug 0 -> wrestle
The Display_All subroutine required a few modifications to the program. First, some
constants for the state values were added, again in a conditional compiler directive.
' -----[ Constants ]----------------------------------------------------------
.
.
.
#IF DEBUG_MODE = 1 #THEN
' State constants.
ATL CON 0 ' Avoid_Tawara_Left
ATR CON 1 ' Avoid_Tawara_Right
GF CON 2 ' Go-Forward
TFLO CON 3 ' Track_Front_Left_Object
TFRO CON 4 ' Track_Front_Right_Object
TSLO CON 5 ' Track_Side_Left_Object
TSRO CON 6 ' Track_Side_Right_Object
SP CON 7 ' Search_Pattern
#ENDIF
A variable named state is added to store these constants.