2013-04-05 22:46:56 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file plotdata.h
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup ScopePlugin Scope Gadget Plugin
|
|
|
|
* @{
|
|
|
|
* @brief The scope Gadget, graphically plots the states of UAVObjects
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLOTDATA_H
|
|
|
|
#define PLOTDATA_H
|
|
|
|
|
|
|
|
#include "uavobject.h"
|
|
|
|
|
|
|
|
#include "qwt/src/qwt.h"
|
|
|
|
#include "qwt/src/qwt_plot.h"
|
|
|
|
#include "qwt/src/qwt_plot_curve.h"
|
|
|
|
#include "qwt/src/qwt_scale_draw.h"
|
|
|
|
#include "qwt/src/qwt_scale_widget.h"
|
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QTime>
|
|
|
|
#include <QVector>
|
2014-10-28 13:33:21 +01:00
|
|
|
#include <uavdataobject.h>
|
2013-04-05 22:46:56 +02:00
|
|
|
|
|
|
|
/*!
|
2013-05-19 16:37:30 +02:00
|
|
|
\brief Defines the different type of plots.
|
|
|
|
*/
|
2014-10-22 00:52:39 +02:00
|
|
|
enum PlotType {SequentialPlot, ChronoPlot};
|
2013-04-05 22:46:56 +02:00
|
|
|
|
|
|
|
/*!
|
2013-05-19 16:37:30 +02:00
|
|
|
\brief Base class that keeps the data for each curve in the plot.
|
|
|
|
*/
|
|
|
|
class PlotData : public QObject {
|
2013-04-05 22:46:56 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2014-10-28 13:33:21 +01:00
|
|
|
PlotData(UAVObject *object, UAVObjectField *field, int element,
|
2014-10-22 00:52:39 +02:00
|
|
|
QwtPlotCurve *plotCurve, int scaleOrderFactor, int meanSamples,
|
|
|
|
QString mathFunction, double plotDataSize);
|
2013-04-05 22:46:56 +02:00
|
|
|
~PlotData();
|
|
|
|
|
2014-10-28 13:33:21 +01:00
|
|
|
UAVObject *object() const { return m_object; }
|
|
|
|
UAVObjectField *field() const { return m_field; }
|
|
|
|
int element() const { return m_element; }
|
2014-10-22 00:52:39 +02:00
|
|
|
QString elementName() const { return m_elementName; }
|
|
|
|
|
|
|
|
bool isVisible() const { return m_plotCurve->isVisible(); }
|
|
|
|
|
|
|
|
double yMin() const { return m_yMin;}
|
|
|
|
double yMax() const { return m_yMax;}
|
2013-04-05 22:46:56 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
virtual bool append(UAVObject *obj) = 0;
|
2014-10-22 00:52:39 +02:00
|
|
|
virtual PlotType plotType() const = 0;
|
2013-04-05 22:46:56 +02:00
|
|
|
virtual void removeStaleData() = 0;
|
|
|
|
|
|
|
|
void updatePlotCurveData();
|
|
|
|
|
2014-10-28 12:19:54 +01:00
|
|
|
bool hasData() { return !m_xDataEntries.isEmpty(); }
|
|
|
|
double lastData() { return m_yDataEntries.last(); }
|
|
|
|
|
2013-04-05 22:46:56 +02:00
|
|
|
protected:
|
2013-05-19 16:37:30 +02:00
|
|
|
double valueAsDouble(UAVObject *obj, UAVObjectField *field);
|
2013-04-05 22:46:56 +02:00
|
|
|
|
2014-10-22 00:52:39 +02:00
|
|
|
int m_scalePower; // This is the power to which each value must be raised
|
|
|
|
int m_meanSamples;
|
|
|
|
double m_meanSum;
|
|
|
|
QString m_mathFunction;
|
|
|
|
double m_correctionSum;
|
|
|
|
int m_correctionCount;
|
|
|
|
double m_plotDataSize;
|
|
|
|
|
2014-10-28 12:19:54 +01:00
|
|
|
QVector<double> m_xDataEntries;
|
|
|
|
QVector<double> m_yDataEntries;
|
|
|
|
QVector<double> m_yDataHistory;
|
|
|
|
|
2014-10-28 13:33:21 +01:00
|
|
|
UAVObject *m_object;
|
|
|
|
UAVObjectField *m_field;
|
|
|
|
int m_element;
|
2014-10-22 00:52:39 +02:00
|
|
|
QString m_elementName;
|
2014-10-28 13:33:21 +01:00
|
|
|
|
2014-10-28 13:44:58 +01:00
|
|
|
virtual void calcMathFunction(double currentValue);
|
|
|
|
|
2014-10-28 13:33:21 +01:00
|
|
|
private:
|
2014-10-22 00:52:39 +02:00
|
|
|
double m_yMin;
|
|
|
|
double m_yMax;
|
|
|
|
QwtPlotCurve *m_plotCurve;
|
2013-04-05 22:46:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
2013-05-19 16:37:30 +02:00
|
|
|
\brief The sequential plot have a fixed size buffer of data. All the curves in one plot
|
|
|
|
have the same size buffer.
|
|
|
|
*/
|
|
|
|
class SequentialPlotData : public PlotData {
|
2013-04-05 22:46:56 +02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-10-28 13:33:21 +01:00
|
|
|
SequentialPlotData(UAVObject *object, UAVObjectField *field, int element,
|
2014-10-22 00:52:39 +02:00
|
|
|
QwtPlotCurve *plotCurve, int scaleFactor, int meanSamples,
|
|
|
|
QString mathFunction, double plotDataSize)
|
2014-10-28 13:33:21 +01:00
|
|
|
: PlotData(object, field, element, plotCurve, scaleFactor, meanSamples, mathFunction, plotDataSize) {}
|
2013-04-05 22:46:56 +02:00
|
|
|
~SequentialPlotData() {}
|
|
|
|
|
|
|
|
/*!
|
2013-05-19 16:37:30 +02:00
|
|
|
\brief Append new data to the plot
|
|
|
|
*/
|
|
|
|
bool append(UAVObject *obj);
|
2013-04-05 22:46:56 +02:00
|
|
|
|
|
|
|
/*!
|
2013-05-19 16:37:30 +02:00
|
|
|
\brief The type of plot
|
|
|
|
*/
|
2014-10-22 00:52:39 +02:00
|
|
|
PlotType plotType() const
|
2013-05-19 16:37:30 +02:00
|
|
|
{
|
2013-04-05 22:46:56 +02:00
|
|
|
return SequentialPlot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-05-19 16:37:30 +02:00
|
|
|
\brief Removes the old data from the buffer
|
|
|
|
*/
|
2014-10-22 00:52:39 +02:00
|
|
|
void removeStaleData() {}
|
2013-04-05 22:46:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
2013-05-19 16:37:30 +02:00
|
|
|
\brief The chrono plot have a variable sized buffer of data, where the data is for a specified time period.
|
|
|
|
*/
|
|
|
|
class ChronoPlotData : public PlotData {
|
2013-04-05 22:46:56 +02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-10-28 13:33:21 +01:00
|
|
|
ChronoPlotData(UAVObject *object, UAVObjectField *field, int element,
|
2014-10-22 00:52:39 +02:00
|
|
|
QwtPlotCurve *plotCurve, int scaleFactor, int meanSamples,
|
|
|
|
QString mathFunction, double plotDataSize)
|
2014-10-28 13:33:21 +01:00
|
|
|
: PlotData(object, field, element, plotCurve, scaleFactor, meanSamples, mathFunction, plotDataSize)
|
2013-05-19 16:37:30 +02:00
|
|
|
{
|
2013-04-05 22:46:56 +02:00
|
|
|
}
|
2013-05-19 16:37:30 +02:00
|
|
|
~ChronoPlotData() {}
|
2013-04-05 22:46:56 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
bool append(UAVObject *obj);
|
2013-04-05 22:46:56 +02:00
|
|
|
|
2014-10-22 00:52:39 +02:00
|
|
|
PlotType plotType() const
|
2013-05-19 16:37:30 +02:00
|
|
|
{
|
2013-04-05 22:46:56 +02:00
|
|
|
return ChronoPlot;
|
|
|
|
}
|
|
|
|
|
2014-10-22 00:52:39 +02:00
|
|
|
void removeStaleData();
|
2013-04-05 22:46:56 +02:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void removeStaleDataTimeout();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PLOTDATA_H
|