Datasheet
Chapter 3: EEPROM Tricks and Program Tips ยท Page 103
should measure the QTI readings for the black surface and use them as a basis for setting
a threshold value to decide whether the QTIs are "seeing" black or white. As you may
have noticed from Activity #2, white QTI measurements are very small in comparison.
Your program can safely set the threshold at 1/4 of the average of the two QTI sensors'
measurements of black. It takes three steps: (1) call the
Read_Line_Sensors subroutine
to update the values of
qtiLeft and qtiRight. (2) take the average of the two
readings. (3) divide this average by 4. Here is an example:
GOSUB Read_Line_Sensors
qtiThreshold = (qtiLeft + qtiRight) / 2
qtiThreshold = qtiThreshold / 4
You can set higher or lower thresholds. For example, if you divide qtiThreshold by 3
instead of 4, the threshold will be higher. If you divide qtiThreshold by 5 or 6, the
threshold will be lower. A lower threshold value makes the SumoBot less likely to mistake a
crease in the SumoBot Robot Competition Ring for a white tawara line. It also helps
somewhat in brightly lit rooms. In contrast, a higher threshold value may be better for rings
where there is less difference in IR reflectivity between black and white.
You can also save a line of code. These two lines of code:
qtiThreshold = (qtiLeft + qtiRight) / 2
qtiThreshold = qtiThreshold / 4
are equivalent to this one line of code:
qtiThreshold = (qtiLeft + qtiRight) / 8
To discern whether the QTI is looking at black or white, use
IF...THEN statements:
IF qtiLeft < qtiThreshold THEN
DEBUG "White"
ELSE
DEBUG "Black"
ENDIF
The next example program uses these code blocks to tell you whether each QTI is
looking at black or white. Figure 3-13 shows an example of how this program can be
used to test the calibration routine and make sure it's working right.