Pololu Zumo Shield Arduino Library
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
QTRSensors Class Referenceabstract
Inheritance diagram for QTRSensors:
QTRSensorsAnalog QTRSensorsRC ZumoReflectanceSensorArray

Public Member Functions

void read (unsigned int *sensor_values, unsigned char readMode=QTR_EMITTERS_ON)
 
void emittersOff ()
 Turns the IR LEDs off. More...
 
void emittersOn ()
 Turns the IR LEDs on. More...
 
void calibrate (unsigned char readMode=QTR_EMITTERS_ON)
 Reads the sensors for calibration. More...
 
void resetCalibration ()
 Resets all calibration that has been done. More...
 
void readCalibrated (unsigned int *sensor_values, unsigned char readMode=QTR_EMITTERS_ON)
 Returns sensor readings normalized to values between 0 and 1000. More...
 
int readLine (unsigned int *sensor_values, unsigned char readMode=QTR_EMITTERS_ON, unsigned char white_line=0)
 Returns an estimated position of a line under the sensor array. More...
 

Public Attributes

unsigned int * calibratedMinimumOn
 The calibrated minimum values measured for each sensor, with emitters on. More...
 
unsigned int * calibratedMaximumOn
 The calibrated maximum values measured for each sensor, with emitters on. More...
 
unsigned int * calibratedMinimumOff
 The calibrated minimum values measured for each sensor, with emitters off. More...
 
unsigned int * calibratedMaximumOff
 The calibrated maximum values measured for each sensor, with emitters off. More...
 

Protected Member Functions

void init (unsigned char *pins, unsigned char numSensors, unsigned char emitterPin)
 

Protected Attributes

unsigned char * _pins
 
unsigned char _numSensors
 
unsigned char _emitterPin
 
unsigned int _maxValue
 
int _lastValue
 

Detailed Description

Definition at line 48 of file QTRSensors.h.

Member Function Documentation

◆ calibrate()

void QTRSensors::calibrate ( unsigned char  readMode = QTR_EMITTERS_ON)

Reads the sensors for calibration.

Parameters
readModeRead mode (QTR_EMITTERS_OFF, QTR_EMITTERS_ON, or QTR_EMITTERS_ON_AND_OFF).

The sensor values read by this function are not returned; instead, the maximum and minimum values found over time are stored internally and used for the readCalibrated() method. You can access the calibration (i.e raw max and min sensor readings) through the public member pointers calibratedMinimumOn, calibratedMaximumOn, calibratedMinimumOff, and calibratedMaximumOff. Note that these pointers will point to arrays of length numSensors, as specified in the constructor, and they will only be allocated after calibrate() has been called. If you only calibrate with the emitters on, the calibration arrays that hold the off values will not be allocated.

The ZumoReflectanceSensorArray class inherits this function from the QTRSensors class.

Definition at line 149 of file QTRSensors.cpp.

◆ emittersOff()

void QTRSensors::emittersOff ( )

Turns the IR LEDs off.

This is mainly for use by the read() method, and calling this function before or after reading the sensors will have no effect on the readings, but you might wish to use it for testing purposes. This method will only do something if the emitter pin specified in the constructor is valid (i.e. not QTR_NO_EMITTER_PIN) and the corresponding connection is made.

The ZumoReflectanceSensorArray class inherits this function from the QTRSensors class.

Definition at line 110 of file QTRSensors.cpp.

◆ emittersOn()

void QTRSensors::emittersOn ( )

Turns the IR LEDs on.

This is mainly for use by the read() method, and calling this function before or after reading the sensors will have no effect on the readings, but you might wish to use it for testing purposes. This method will only do something if the emitter pin specified in the constructor is valid (i.e. not QTR_NO_EMITTER_PIN) and the corresponding connection is made.

The ZumoReflectanceSensorArray class inherits this function from the QTRSensors class.

Definition at line 119 of file QTRSensors.cpp.

◆ readCalibrated()

void QTRSensors::readCalibrated ( unsigned int *  sensor_values,
unsigned char  readMode = QTR_EMITTERS_ON 
)

Returns sensor readings normalized to values between 0 and 1000.

Parameters
sensor_valuesArray to populate with sensor readings.
readModeRead mode (QTR_EMITTERS_OFF, QTR_EMITTERS_ON, or QTR_EMITTERS_ON_AND_OFF).

0 corresponds to a 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.

The ZumoReflectanceSensorArray class inherits this function from the QTRSensors class.

Definition at line 235 of file QTRSensors.cpp.

◆ readLine()

int QTRSensors::readLine ( unsigned int *  sensor_values,
unsigned char  readMode = QTR_EMITTERS_ON,
unsigned char  whiteLine = 0 
)

Returns an estimated position of a line under the sensor array.

Parameters
sensor_valuesArray to populate with sensor readings.
readModeRead mode (QTR_EMITTERS_OFF, QTR_EMITTERS_ON, or QTR_EMITTERS_ON_AND_OFF).
whiteLine0 to detect a dark line on a light surface; 1 to detect a light line on a dark surface.
Returns
An estimated line position.

This function operates the same as readCalibrated(), but with a feature designed for line following: it 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:

\[ \newcommand{sv}[1]{\mathtt{sensor_values[#1]}} \text{return value} = \frac{(0 \times \sv{0}) + (1000 \times \sv{1}) + (2000 \times \sv{2}) + \ldots} {\sv{0} + \sv{1} + \sv{2} + \ldots} \]

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, its line position will continue to indicate the direction you need to go to reacquire the line. For example, if sensor 5 is your rightmost sensor and you end up completely off the line to the left, this function will continue to return 5000.

By default, this function assumes a dark line (high values) on a light background (low values). If your line is light on dark, 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.

The ZumoReflectanceSensorArray class inherits this function from the QTRSensors class.

Definition at line 315 of file QTRSensors.cpp.

◆ resetCalibration()

void QTRSensors::resetCalibration ( )

Resets all calibration that has been done.

This function discards the calibration values that have been previously recorded, resetting the min and max values.

The ZumoReflectanceSensorArray class inherits this function from the QTRSensors class.

Definition at line 129 of file QTRSensors.cpp.

Member Data Documentation

◆ calibratedMaximumOff

unsigned int * QTRSensors::calibratedMaximumOff

The calibrated maximum values measured for each sensor, with emitters off.

This pointer is 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 might be allocated, as required. This variable is made public so that you can use the calibration values for your own calculations and do things like saving them to EEPROM, performing sanity checking, etc.

The ZumoReflectanceSensorArray class inherits this variable from the QTRSensors class.

Definition at line 127 of file QTRSensors.h.

◆ calibratedMaximumOn

unsigned int * QTRSensors::calibratedMaximumOn

The calibrated maximum values measured for each sensor, with emitters on.

This pointer is 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 might be allocated, as required. This variable is made public so that you can use the calibration values for your own calculations and do things like saving them to EEPROM, performing sanity checking, etc.

The ZumoReflectanceSensorArray class inherits this variable from the QTRSensors class.

Definition at line 125 of file QTRSensors.h.

◆ calibratedMinimumOff

unsigned int * QTRSensors::calibratedMinimumOff

The calibrated minimum values measured for each sensor, with emitters off.

This pointer is 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 might be allocated, as required. This variable is made public so that you can use the calibration values for your own calculations and do things like saving them to EEPROM, performing sanity checking, etc.

The ZumoReflectanceSensorArray class inherits this variable from the QTRSensors class.

Definition at line 126 of file QTRSensors.h.

◆ calibratedMinimumOn

unsigned int * QTRSensors::calibratedMinimumOn

The calibrated minimum values measured for each sensor, with emitters on.

This pointer is 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 might be allocated, as required. This variable is made public so that you can use the calibration values for your own calculations and do things like saving them to EEPROM, performing sanity checking, etc.

The ZumoReflectanceSensorArray class inherits this variable from the QTRSensors class.

Definition at line 124 of file QTRSensors.h.


The documentation for this class was generated from the following files: