Code Block |
---|
#ifndef SENSORUNLINEARITYCORRECTION_H #define SENSORUNLINEARITYCORRECTION_H #include <QObject> #include <QVector> //! Error correction class for sensors class SensorUnlinearityCorrection : public QObject { Q_OBJECT public: explicit SensorUnlinearityCorrection(QObject *parent = 0); double SensorErrorCorrection(double in); void CalcCalibrationConstants(); private: QVector <double> CorrectVal; QVector <double> ValFromSensor; QVector <double> a,b;//angle offset signals: public slots: }; #endif // SENSORUNLINEARITYCORRECTION_H |
Code Block |
---|
#include "sensorunlinearitycorrection.h"
SensorUnlinearityCorrection::SensorUnlinearityCorrection(QObject *parent) :
QObject(parent)
{
//esimerkkina arvot kolmessa kohdassa mitta-aluetta
CorrectVal.append(0.0);
ValFromSensor.append(0.0);
CorrectVal.append(50.0);
ValFromSensor.append(52.0);
CorrectVal.append(100.0);
ValFromSensor.append(98.0);
}
void SensorUnlinearityCorrection::CalcCalibrationConstants()
{
int i;
int length = CorrectVal.size();
a.empty();
b.empty();
for(i=0;i<length;i++)
{
b.append(CorrectVal[i]-ValFromSensor[i]);
}
for(i=0;i<(length-1);i++)
{
a.append((b[i+1]-b[i])/(CorrectVal[i+1]-CorrectVal[i]));
}
}
double SensorUnlinearityCorrection::SensorErrorCorrection(double in)
{
int length = CorrectVal.size();
int i;
double out;
for(i=0;i<(length-1);i++)
{
if(in>=CorrectVal[i]&&in<=CorrectVal[i+1])
{
out=in+(in-CorrectVal[i])*a[i]+b[i];
return out;
}
}
out=in;
return out;
}
|