Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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);
}

// kertoimien laskenta
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]));
    }
}

//oikean arvon  haku
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;
}

Esimerkkinä QDialog perustainen ohjelma, jolla voi testata kalibrointikäyrän tomintaa.

Code Block
#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include "sensorunlinearitycorrection.h"

namespace Ui {
    class Dialog;
}

class Dialog : public QDialog {
    Q_OBJECT
public:
    Dialog(QWidget *parent = 0);
    ~Dialog();
    SensorUnlinearityCorrection sensorUnlinearityCorrection;
protected:
    void changeEvent(QEvent *e);

private:
    Ui::Dialog *ui;

private slots:
    void on_horizontalSlider_sliderMoved(int position);
};

#endif // DIALOG_H


...