User Manual

reading that is less than or equal to the minimum value read by calibrate() and 1000 corresponds
to a reading that is greater than or equal to the maximum value. Calibration values are stored
separately for each sensor, so that differences in the sensors are accounted for automatically.
unsigned int readLine(unsigned int *sensorValues, unsigned char readMode =
QTR_EMITTERS_ON, unsigned char whiteLine = 0)
Operates the same as read calibrated, but with a feature designed for line following: this function
returns an estimated position of the line. The estimate is made using a weighted average of the
sensor indices multiplied by 1000, so that a return value of 0 indicates that the line is directly below
sensor 0 (or was last seen by sensor 0 before being lost), a return value of 1000 indicates that
the line is directly below sensor 1, 2000 indicates that it’s below sensor 2, etc. Intermediate values
indicate that the line is between two sensors. The formula is:
0*value0 + 1000*value1 + 2000*value2 + ...
--------------------------------------------
value0 + value1 + value2 + ...
As long as your sensors aren’t spaced too far apart relative to the line, this returned value is
designed to be monotonic, which makes it great for use in closed-loop PID control. Additionally, this
method remembers where it last saw the line, so if you ever lose the line to the left or the right, it’s
line position will continue to indicate the direction you need to go to reacquire the line. For example,
if sensor 4 is your rightmost sensor and you end up completely off the line to the left, this function
will continue to return 4000.
By default, this function assumes a dark line (high values) surrounded by white (low values). If your
line is light on black, set the optional second argument whiteLine to true. In this case, each sensor
value will be replaced by the maximum possible value minus its actual value before the averaging.
unsigned int* calibratedMinimumOn
The calibrated minimum values measured for each sensor, with emitters on. The pointers are
unallocated and set to 0 until calibrate() is called, and then allocated to exactly the size required.
Depending on the readMode argument to calibrate(), only the On or Off values may be allocated, as
required. This and the following variables are made public so that you can use them for your own
calculations and do things like saving the values to EEPROM, performing sanity checking, etc.
unsigned int* calibratedMaximumOn
The calibrated maximum values measured for each sensor, with emitters on.
unsigned int* calibratedMinimumOff
The calibrated minimum values measured for each sensor, with emitters off.
unsigned int* calibratedMaximumOff
The calibrated maximum values measured for each sensor, with emitters off.
Destructor: ~QTRSensors()
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation
3. QTRSensors Methods & Usage Notes Page 9 of 15