dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
tempcompcurve.cpp
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  */
25 
26 #include "tempcompcurve.h"
27 
29  : QwtPlot(parent)
30  , dataCurve(NULL)
31  , fitCurve(NULL)
32 {
33  setMouseTracking(true);
34 
35  setMinimumSize(64, 64);
36  setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
37 
38  setCanvasBackground(QColor(64, 64, 64));
39 
40  // Add grid lines
41  QwtPlotGrid *grid = new QwtPlotGrid;
42  grid->setMajorPen(QPen(Qt::gray, 0, Qt::DashLine));
43  grid->setMinorPen(QPen(Qt::lightGray, 0, Qt::DotLine));
44  grid->setPen(QPen(Qt::darkGray, 1, Qt::DotLine));
45  grid->attach(this);
46 }
47 
54 {
55  // TODO: Keep the curves and free them in the destructors
56  const int STEPS = 100;
57 
58  points.clear();
59  fit.clear();
60 
61  clearCurves();
62 
63  double min = temp[0];
64  double max = temp[0];
65  for (int i = 0; i < temp.size(); i++) {
66  points.append(QPointF(temp[i], gyro[i]));
67  min = qMin(min, temp[i]);
68  max = qMax(max, temp[i]);
69  }
70 
71  double step = (max - min) / STEPS;
72  for (int i = 0; i < STEPS; i++) {
73  double t = min + step * i;
74  double f = coeff[0] + coeff[1] * t + coeff[2] * pow(t, 2) + coeff[3] * pow(t, 3);
75  fit.append(QPointF(t, f));
76  }
77 
78  // Plot the raw data points
79  QPen pen = QPen(Qt::DotLine);
80  pen.setColor(QColor(244, 244, 244));
81 
82  dataCurve = new QwtPlotCurve("Gyro");
83  dataCurve->setPen(pen);
84  dataCurve->setSamples(this->points);
85  dataCurve->attach(this);
86 
87  // Plot the fit
88  pen.setStyle(Qt::SolidLine);
89  pen.setColor(QColor(0, 255, 0));
90 
91  fitCurve = new QwtPlotCurve("Fit");
92  fitCurve->setPen(pen);
93  fitCurve->setSamples(fit);
94  fitCurve->attach(this);
95 
96  replot();
97 }
98 
102 void TempCompCurve::clearCurves()
103 {
104  // Remove previous curves
105  if (dataCurve) {
106  dataCurve->detach();
107  delete dataCurve;
108  dataCurve = NULL;
109  }
110  if (fitCurve) {
111  fitCurve->detach();
112  delete fitCurve;
113  fitCurve = NULL;
114  }
115 }
const char t[]
Definition: coreconstants.h:40
for i
Definition: OPPlots.m:140
void plotData(QList< double > temp, QList< double > gyro, QList< double > coefficients)
Show calibration data for one of the channels.
TempCompCurve(QWidget *parent=nullptr)