pololu / qtr-sensors-arduino Goto Github PK
View Code? Open in Web Editor NEWArduino library for the Pololu QTR reflectance sensors
Home Page: http://www.pololu.com/catalog/category/123
License: Other
Arduino library for the Pololu QTR reflectance sensors
Home Page: http://www.pololu.com/catalog/category/123
License: Other
Hello,
when i using this code
unsigned char pins[] = {A8,A9,A10,A11,A12,A13,A14,A15};
QTRSensorsAnalog sensors;
void setup() {
QTRSensorsAnalog sensors = QTRSensorsAnalog(pins, 8);
sensors.calibrate();
}
the calibraition of the Sensors wont work because the Sensor lost the value of the pins in the QTRSensor implementation.
Hi,
I was looking through your library, and I can't seem to figure out why you store the maximum value found during calibration into calibratedMinimum, and the minimum value into calibratedMaximum:
for(i=0;i<_numSensors;i++)
{
if(min_sensor_values[i] > (*calibratedMaximum)[i])
(*calibratedMaximum)[i] = min_sensor_values[i];
if(max_sensor_values[i] < (*calibratedMinimum)[i])
(*calibratedMinimum)[i] = max_sensor_values[i];
}
I keep trying to go through a step by step of how this would work, but I always end up with calibratedMinimum being larger than calibratedMaximum. Should it be:
for(i=0;i<_numSensors;i++)
{
if(max_sensor_values[i] > (*calibratedMaximum)[i])
(*calibratedMaximum)[i] = max_sensor_values[i];
if(min_sensor_values[i] < (*calibratedMinimum)[i])
(*calibratedMinimum)[i] = min_sensor_values[i];
}
This is contained in line 230 to 236 of QTRSensors.cpp.
Thanks,
Farzad
While looking over the code, I found this peculiar piece of code:
if (_type == QTR_RC)
{
((QTRSensorsRC*)this)->readPrivate(sensor_values);
emittersOff();
if(readMode == QTR_EMITTERS_ON_AND_OFF)
((QTRSensorsRC*)this)->readPrivate(off_values);
}
else
{
((QTRSensorsAnalog*)this)->readPrivate(sensor_values);
emittersOff();
if(readMode == QTR_EMITTERS_ON_AND_OFF)
((QTRSensorsAnalog*)this)->readPrivate(off_values);
}
It seems that the QTRSensors
object keeps a _type
variable to tell the code
which subclass it is, and then based on that calls either the
QTRSensorsAnalog
or QTRSensorsRC
version of the readPrivate
method.
This kind of thing is what C++ has virtual methods for. By declaring
readPrivate
as a (pure) virtual method in QTRSensors
and then implementing
it in the subclasses, you can just call this->readPrivate()
and the compiler
will (generate code to) find out which subclass is being used at runtime.
Or is there some reason that using virtual methods is not an option here?
Gr.
Matthijs
'QTRSensorsRC' does not name a type; did you mean 'QTRSensors'?
I think there might be a bug in the QTRSensors::readLinePrivate() method. The weighted average is calculated in this method by the following code:
for (uint8_t i = 0; i < _sensorCount; i++)
{
...
// only average in values that are above a noise threshold
if (value > 50)
{
avg += (uint32_t)value * (i * 1000);
sum += value;
}
}
...
_lastPosition = avg / sum;
The i
variable starts at 0 and that 0th element will always contribute a value of 0 to avg
.
Maybe something like this would work better?
for (uint8_t i = 0; i < _sensorCount; i++)
{
...
// only average in values that are above a noise threshold
if (value > 50)
{
avg += (uint32_t)value * ((i+1) * 1000);
sum += value;
}
}
...
_lastPosition = avg / sum - 1000;
It should still result in the same final range I think but the 0th element will always contribute to avg
.
Thoughts?
Hi @kevin-pololu,
I have a suggestion to improve your arduino library.
The new arduino IDE includes a auto update of the libraries but for that it need’s a file called “library.properties” inside the library folder. I think that it would be good to add that file to all your libraries so that users can get always the newer versions automatically. I will attach a file the I made for the QTRSensors library base on an Adafruit library, I’m not sure if it works….
name=QTRSensors
version=2.1.2
author=Pololu
maintainer= Pololu <www.pololu.com>
sentence=Driver for Pololu QTR-XX line Sensors
paragraph=Driver for Pololu QTR-XX line Sensors
category=Sensors
url=hhttps://github.com/pololu/qtr-sensors-arduino
architectures=*
It would be nice if the library provided a constant for 2500, the default RC timeout.
Hello, I use Arduino 1.6.7 after adding the library QTR, this message appears : Invalid library found in Arduino \ libraries \ QT
On that line, the comment says that the returned value will be between 0 and 5000. It turns out that with a size 8 sensor, the reading should vary between 0 and 7000.
At least, that's the result I got with a properly calibrated size 8 sensor.
I am having a issue where the readLineWhite() is not working properly. It keeps giving me values between 5000-6000 on a QTRX-13MD-RC, even though on a black line with readLineBlack() the readings are perfectly fine and gives me 0-12000.
readLineWhite() on a white line is causing issues.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.