Hi, I’ve been looking through the QRT sensor files and found something I don’t understand. It’s in the file “PololuQTRSensors.cpp”. This is the function:
void PololuQTRSensors::read(unsigned int *sensor_values, unsigned char readMode)
{
unsigned int off_values[8];
unsigned char i;
if(readMode == QTR_EMITTERS_ON || readMode == QTR_EMITTERS_ON_AND_OFF)
emittersOn();
if (_type == QTR_RC)
{
((PololuQTRSensorsRC*)this)->readPrivate(sensor_values);
emittersOff();
if(readMode == QTR_EMITTERS_ON_AND_OFF)
((PololuQTRSensorsRC*)this)->readPrivate(off_values);
}
else
{
((PololuQTRSensorsAnalog*)this)->readPrivate(sensor_values);
emittersOff();
if(readMode == QTR_EMITTERS_ON_AND_OFF)
((PololuQTRSensorsRC*)this)->readPrivate(off_values);
}
if(readMode == QTR_EMITTERS_ON_AND_OFF)
{
for(i=0;i<_numSensors;i++)
{
sensor_values[i] += _maxValue - off_values[i];
}
}
}
For a non-RC sensor, we are turning on the emitters and taking an analog reading then turning off the emitters (if read_mode is on_and_off) and taking an RC reading of the sensors. Why is this??
Also, why do we calculate the sensor value that way? Sensor = Sensor + ( 1023 - off_value ). We are inversing the off_value and adding it to the on_value? Why not just subtract the the off_value from the on_value?
Denis.