Datasheet

Chapter 4: Navigation Tips ยท Page 193
qtiLF = ~qtiSigLeft ' Snapshot of QTI signal states
qtiRF = ~qtiSigRight
LOW qtiPwrLeft ' Turn off QTIS
LOW qtiPwrRight
RETURN
Moving the State Routines to Subroutines
Here is the Main Routine from the upcoming example program SumoWrestler.bs2, a
revision of TestSumoWrestler.bs2 in which all of the state routines have been moved to
subroutines. It's quite clean and easy to read, isn't it?
' -----[ Main Routine ]-------------------------------------------------------
DO
IF qtiLF = 1 THEN ' Left qti sees line?
GOSUB Avoid_Tawara_Left ' State = avoid left tawara
ELSEIF qtiRF = 1 THEN ' Right qti sees line?
GOSUB Avoid_Tawara_Right ' State = avoid right tawara
ELSEIF irLF = 1 AND irRF = 1 THEN ' Both? Lunge forward
GOSUB Go_Forward ' State = Go forward
ELSEIF irLF = 1 THEN ' Just left?
GOSUB Track_Front_Left_Object ' State = Track front left obj.
ELSEIF irRF = 1 THEN ' Just right?
GOSUB Track_Front_Right_Object ' State = Track front right obj.
ELSEIF irLS = 1 THEN ' Left side?
GOSUB Track_Side_Left_Object ' State = track side left obj.
ELSEIF irRS = 1 THEN ' Right side?
GOSUB Track_Side_Left_Object ' State = track side right obj.
ELSE ' Nothing sensed?
GOSUB Search_Pattern ' State = Search pattern
ENDIF
LOOP
The code block for each navigation state now resides in a subroutine. Here is an example
of
Avoid_Tawara_Left. For the most part, the actual code in each subroutine is
unchanged from the way it was in the main routine. The only difference is usually the
label and
RETURN command.
' -----[ Subroutine - Avoid_Tawara_Left ]------------------------------
Avoid_Tawara_Left:
FOR counter = 1 TO 15 ' Back up