1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Added Math Functions to the scope. Currently only support standard deviation.

This commit is contained in:
Laura Sebesta 2012-05-22 05:21:11 +03:00
parent ce139a12cc
commit aeca5c6741
10 changed files with 195 additions and 108 deletions

View File

@ -53,8 +53,9 @@ PlotData::PlotData(QString p_uavObject, QString p_uavField)
curve = 0; curve = 0;
scalePower = 0; scalePower = 0;
interpolationSamples = 1; meanSamples = 1;
interpolationSum = 0.0f; meanSum = 0.0f;
// mathFunction=0;
correctionSum = 0.0f; correctionSum = 0.0f;
correctionCount = 0; correctionCount = 0;
yMinimum = 0; yMinimum = 0;
@ -96,28 +97,50 @@ bool SequentialPlotData::append(UAVObject* obj)
if (field) { if (field) {
//Shift data forward and put the new value at the front
// calculate interpolated (smoothed) value
double currentValue = valueAsDouble(obj, field) * pow(10, scalePower); double currentValue = valueAsDouble(obj, field) * pow(10, scalePower);
//Compute boxcar average
if (meanSamples > 1){
//Put the new value at the front
yDataHistory->append( currentValue ); yDataHistory->append( currentValue );
interpolationSum += currentValue;
if(yDataHistory->size() > interpolationSamples) { // calculate average value
interpolationSum -= yDataHistory->first(); meanSum += currentValue;
if(yDataHistory->size() > meanSamples) {
meanSum -= yDataHistory->first();
yDataHistory->pop_front(); yDataHistory->pop_front();
} }
// make sure to correct the sum every interpolationSamples steps to prevent it
// from running away due to flouting point rounding errors // make sure to correct the sum every meanSamples steps to prevent it
correctionSum += currentValue; // from running away due to floating point rounding errors
if (++correctionCount >= interpolationSamples) { correctionSum+=currentValue;
interpolationSum = correctionSum; if (++correctionCount >= meanSamples) {
meanSum = correctionSum;
correctionSum = 0.0f; correctionSum = 0.0f;
correctionCount = 0; correctionCount = 0;
} }
yData->append(interpolationSum/yDataHistory->size());
if (yData->size() > m_xWindowSize) { double boxcarAvg=meanSum/yDataHistory->size();
if ( mathFunction == "Standard deviation" ){
//Calculate square of sample standard deviation, with Bessel's correction
double stdSum=0;
for (int i=0; i < yDataHistory->size(); i++){
stdSum+= pow(yDataHistory->at(i)- boxcarAvg,2)/(meanSamples-1);
}
yData->append(sqrt(stdSum));
}
else {
yData->append(boxcarAvg);
}
}
else{
yData->append( currentValue );
}
if (yData->size() > m_xWindowSize) { //If new data overflows the window, remove old data...
yData->pop_front(); yData->pop_front();
} else } else //...otherwise, add a new y point at position xData
xData->insert(xData->size(), xData->size()); xData->insert(xData->size(), xData->size());
//notify the gui of changes in the data //notify the gui of changes in the data
@ -137,30 +160,49 @@ bool ChronoPlotData::append(UAVObject* obj)
//qDebug() << "uavObject: " << uavObject << ", uavField: " << uavField; //qDebug() << "uavObject: " << uavObject << ", uavField: " << uavField;
if (field) { if (field) {
//Put the new value at the front QDateTime NOW = QDateTime::currentDateTime(); //THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME
QDateTime NOW = QDateTime::currentDateTime();
// calculate interpolated (smoothed) value
double currentValue = valueAsDouble(obj, field) * pow(10, scalePower); double currentValue = valueAsDouble(obj, field) * pow(10, scalePower);
//Compute boxcar average
if (meanSamples > 1){
//Put the new value at the front
yDataHistory->append( currentValue ); yDataHistory->append( currentValue );
interpolationSum += currentValue;
if(yDataHistory->size() > interpolationSamples) { // calculate average value
interpolationSum -= yDataHistory->first(); meanSum += currentValue;
if(yDataHistory->size() > meanSamples) {
meanSum -= yDataHistory->first();
yDataHistory->pop_front(); yDataHistory->pop_front();
} }
// make sure to correct the sum every interpolationSamples steps to prevent it // make sure to correct the sum every meanSamples steps to prevent it
// from running away due to flouting point rounding errors // from running away due to floating point rounding errors
correctionSum += currentValue; correctionSum+=currentValue;
if (++correctionCount >= interpolationSamples) { if (++correctionCount >= meanSamples) {
interpolationSum = correctionSum; meanSum = correctionSum;
correctionSum = 0.0f; correctionSum = 0.0f;
correctionCount = 0; correctionCount = 0;
} }
double boxcarAvg=meanSum/yDataHistory->size();
//qDebug()<<mathFunction;
if ( mathFunction == "Standard deviation" ){
//Calculate square of sample standard deviation, with Bessel's correction
double stdSum=0;
for (int i=0; i < yDataHistory->size(); i++){
stdSum+= pow(yDataHistory->at(i)- boxcarAvg,2)/(meanSamples-1);
}
yData->append(sqrt(stdSum));
}
else {
yData->append(boxcarAvg);
}
}
else{
yData->append( currentValue );
}
double valueX = NOW.toTime_t() + NOW.time().msec() / 1000.0; double valueX = NOW.toTime_t() + NOW.time().msec() / 1000.0;
double valueY = interpolationSum/yDataHistory->size();
xData->append(valueX); xData->append(valueX);
yData->append(valueY);
//qDebug() << "Data " << uavObject << "." << field->getName() << " X,Y:" << valueX << "," << valueY; //qDebug() << "Data " << uavObject << "." << field->getName() << " X,Y:" << valueX << "," << valueY;

View File

@ -67,8 +67,9 @@ public:
QString uavSubField; QString uavSubField;
bool haveSubField; bool haveSubField;
int scalePower; //This is the power to which each value must be raised int scalePower; //This is the power to which each value must be raised
int interpolationSamples; int meanSamples;
double interpolationSum; double meanSum;
QString mathFunction;
double correctionSum; double correctionSum;
int correctionCount; int correctionCount;
double yMinimum; double yMinimum;

View File

@ -61,14 +61,16 @@ void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration* config)
QString uavObject = plotCurveConfig->uavObject; QString uavObject = plotCurveConfig->uavObject;
QString uavField = plotCurveConfig->uavField; QString uavField = plotCurveConfig->uavField;
int scale = plotCurveConfig->yScalePower; int scale = plotCurveConfig->yScalePower;
int interpolation = plotCurveConfig->yInterpolationSamples; int mean = plotCurveConfig->yMeanSamples;
QString mathFunction = plotCurveConfig->mathFunction;
QRgb color = plotCurveConfig->color; QRgb color = plotCurveConfig->color;
widget->addCurvePlot( widget->addCurvePlot(
uavObject, uavObject,
uavField, uavField,
scale, scale,
interpolation, mean,
mathFunction,
QPen( QBrush(QColor(color),Qt::SolidPattern), QPen( QBrush(QColor(color),Qt::SolidPattern),
// (qreal)2, // (qreal)2,
(qreal)1, (qreal)1,

View File

@ -31,7 +31,8 @@ ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, QSettings* q
IUAVGadgetConfiguration(classId, parent), IUAVGadgetConfiguration(classId, parent),
m_plotType((int)ChronoPlot), m_plotType((int)ChronoPlot),
m_dataSize(60), m_dataSize(60),
m_refreshInterval(1000) m_refreshInterval(1000),
m_mathFunctionType(0)
{ {
uint currentStreamVersion = 0; uint currentStreamVersion = 0;
int plotCurveCount = 0; int plotCurveCount = 0;
@ -65,8 +66,11 @@ ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, QSettings* q
color = qSettings->value("color").value<QRgb>(); color = qSettings->value("color").value<QRgb>();
plotCurveConf->color = color; plotCurveConf->color = color;
plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt(); plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt();
plotCurveConf->yInterpolationSamples = qSettings->value("yInterpolationSamples").toInt(); plotCurveConf->mathFunction = qSettings->value("mathFunction").toString();
if (!plotCurveConf->yInterpolationSamples) plotCurveConf->yInterpolationSamples = 1; // fallback for backward compatibility with earlier versions plotCurveConf->yMeanSamples = qSettings->value("yMeanSamples").toInt();
if (!plotCurveConf->yMeanSamples) plotCurveConf->yMeanSamples = 1; // fallback for backward compatibility with earlier versions //IS THIS STILL NECESSARY?
plotCurveConf->yMinimum = qSettings->value("yMinimum").toDouble(); plotCurveConf->yMinimum = qSettings->value("yMinimum").toDouble();
plotCurveConf->yMaximum = qSettings->value("yMaximum").toDouble(); plotCurveConf->yMaximum = qSettings->value("yMaximum").toDouble();
@ -105,8 +109,9 @@ IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
int plotDatasLoadIndex = 0; int plotDatasLoadIndex = 0;
ScopeGadgetConfiguration *m = new ScopeGadgetConfiguration(this->classId()); ScopeGadgetConfiguration *m = new ScopeGadgetConfiguration(this->classId());
m->setPlotType(m_plotType); m->setPlotType( m_plotType);
m->setDataSize( m_dataSize); m->setDataSize( m_dataSize);
m->setMathFunctionType( m_mathFunctionType);
m->setRefreashInterval( m_refreshInterval); m->setRefreashInterval( m_refreshInterval);
plotCurveCount = m_PlotCurveConfigs.size(); plotCurveCount = m_PlotCurveConfigs.size();
@ -120,7 +125,9 @@ IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
newPlotCurveConf->uavField = currentPlotCurveConf->uavField; newPlotCurveConf->uavField = currentPlotCurveConf->uavField;
newPlotCurveConf->color = currentPlotCurveConf->color; newPlotCurveConf->color = currentPlotCurveConf->color;
newPlotCurveConf->yScalePower = currentPlotCurveConf->yScalePower; newPlotCurveConf->yScalePower = currentPlotCurveConf->yScalePower;
newPlotCurveConf->yInterpolationSamples = currentPlotCurveConf->yInterpolationSamples; newPlotCurveConf->yMeanSamples = currentPlotCurveConf->yMeanSamples;
newPlotCurveConf->mathFunction = currentPlotCurveConf->mathFunction;
newPlotCurveConf->yMinimum = currentPlotCurveConf->yMinimum; newPlotCurveConf->yMinimum = currentPlotCurveConf->yMinimum;
newPlotCurveConf->yMaximum = currentPlotCurveConf->yMaximum; newPlotCurveConf->yMaximum = currentPlotCurveConf->yMaximum;
@ -136,43 +143,46 @@ IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
return m; return m;
} }
/**
* Saves a configuration.
*
*/
void ScopeGadgetConfiguration::saveConfig(QSettings* qSettings) const {
int plotCurveCount = m_PlotCurveConfigs.size(); ////THIS SEEMS TO BE UNUSED
int plotDatasLoadIndex = 0; ///**
// * Saves a configuration.
// *
// */
//void ScopeGadgetConfiguration::saveConfig(QSettings* qSettings) const {
qSettings->setValue("configurationStreamVersion", m_configurationStreamVersion); // int plotCurveCount = m_PlotCurveConfigs.size();
qSettings->setValue("plotType", m_plotType); // int plotDatasLoadIndex = 0;
qSettings->setValue("dataSize", m_dataSize);
qSettings->setValue("refreshInterval", m_refreshInterval);
qSettings->setValue("plotCurveCount", plotCurveCount);
for(plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) // qSettings->setValue("configurationStreamVersion", m_configurationStreamVersion);
{ // qSettings->setValue("plotType", m_plotType);
qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex)); // qSettings->setValue("dataSize", m_dataSize);
// qSettings->setValue("refreshInterval", m_refreshInterval);
// qSettings->setValue("plotCurveCount", plotCurveCount);
PlotCurveConfiguration* plotCurveConf = m_PlotCurveConfigs.at(plotDatasLoadIndex); // for(plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++)
qSettings->setValue("uavObject", plotCurveConf->uavObject); // {
qSettings->setValue("uavField", plotCurveConf->uavField); // qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex));
qSettings->setValue("color", plotCurveConf->color);
qSettings->setValue("yScalePower", plotCurveConf->yScalePower);
qSettings->setValue("yInterpolationSamples", plotCurveConf->yInterpolationSamples);
qSettings->setValue("yMinimum", plotCurveConf->yMinimum);
qSettings->setValue("yMaximum", plotCurveConf->yMaximum);
qSettings->endGroup(); // PlotCurveConfiguration* plotCurveConf = m_PlotCurveConfigs.at(plotDatasLoadIndex);
} // qSettings->setValue("uavObject", plotCurveConf->uavObject);
// qSettings->setValue("uavField", plotCurveConf->uavField);
// qSettings->setValue("color", plotCurveConf->color);
// qSettings->setValue("mathFunction", plotCurveConf->mathFunction);
// qSettings->setValue("yScalePower", plotCurveConf->yScalePower);
// qSettings->setValue("yMeanSamples", plotCurveConf->yMeanSamples);
// qSettings->setValue("yMinimum", plotCurveConf->yMinimum);
// qSettings->setValue("yMaximum", plotCurveConf->yMaximum);
qSettings->setValue("LoggingEnabled", m_LoggingEnabled); // qSettings->endGroup();
qSettings->setValue("LoggingNewFileOnConnect", m_LoggingNewFileOnConnect); // }
qSettings->setValue("LoggingPath", m_LoggingPath);
// qSettings->setValue("LoggingEnabled", m_LoggingEnabled);
// qSettings->setValue("LoggingNewFileOnConnect", m_LoggingNewFileOnConnect);
// qSettings->setValue("LoggingPath", m_LoggingPath);
} //}
void ScopeGadgetConfiguration::replacePlotCurveConfig(QList<PlotCurveConfiguration*> newPlotCurveConfigs) void ScopeGadgetConfiguration::replacePlotCurveConfig(QList<PlotCurveConfiguration*> newPlotCurveConfigs)
{ {

View File

@ -41,7 +41,8 @@ struct PlotCurveConfiguration
QString uavField; QString uavField;
int yScalePower; //This is the power to which each value must be raised int yScalePower; //This is the power to which each value must be raised
QRgb color; QRgb color;
int yInterpolationSamples; int yMeanSamples;
QString mathFunction;
double yMinimum; double yMinimum;
double yMaximum; double yMaximum;
}; };
@ -56,6 +57,7 @@ public:
//configuration setter functions //configuration setter functions
void setPlotType(int value){m_plotType = value;} void setPlotType(int value){m_plotType = value;}
void setMathFunctionType(int value){m_mathFunctionType = value;}
void setDataSize(int value){m_dataSize = value;} void setDataSize(int value){m_dataSize = value;}
void setRefreashInterval(int value){m_refreshInterval = value;} void setRefreashInterval(int value){m_refreshInterval = value;}
void addPlotCurveConfig(PlotCurveConfiguration* value){m_PlotCurveConfigs.append(value);} void addPlotCurveConfig(PlotCurveConfiguration* value){m_PlotCurveConfigs.append(value);}
@ -64,11 +66,12 @@ public:
//configurations getter functions //configurations getter functions
int plotType(){return m_plotType;} int plotType(){return m_plotType;}
int mathFunctionType(){return m_mathFunctionType;}
int dataSize(){return m_dataSize;} int dataSize(){return m_dataSize;}
int refreshInterval(){return m_refreshInterval;} int refreshInterval(){return m_refreshInterval;}
QList<PlotCurveConfiguration*> plotCurveConfigs(){return m_PlotCurveConfigs;} QList<PlotCurveConfiguration*> plotCurveConfigs(){return m_PlotCurveConfigs;}
void saveConfig(QSettings* settings) const; // void saveConfig(QSettings* settings) const; //THIS SEEMS TO BE UNUSED
IUAVGadgetConfiguration *clone(); IUAVGadgetConfiguration *clone();
bool getLoggingEnabled(){return m_LoggingEnabled;}; bool getLoggingEnabled(){return m_LoggingEnabled;};
@ -84,6 +87,7 @@ private:
int m_plotType; //The type of the plot int m_plotType; //The type of the plot
int m_dataSize; //The size of the data buffer to render in the curve plot int m_dataSize; //The size of the data buffer to render in the curve plot
int m_refreshInterval; //The interval to replot the curve widget. The data buffer is refresh as the data comes in. int m_refreshInterval; //The interval to replot the curve widget. The data buffer is refresh as the data comes in.
int m_mathFunctionType; //The type of math function to be used in the scope analysis
QList<PlotCurveConfiguration*> m_PlotCurveConfigs; QList<PlotCurveConfiguration*> m_PlotCurveConfigs;
void clearPlotData(); void clearPlotData();

View File

@ -69,6 +69,9 @@ QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent)
//Connect signals to slots cmbUAVObjects.currentIndexChanged //Connect signals to slots cmbUAVObjects.currentIndexChanged
connect(options_page->cmbUAVObjects, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_cmbUAVObjects_currentIndexChanged(QString))); connect(options_page->cmbUAVObjects, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_cmbUAVObjects_currentIndexChanged(QString)));
options_page->mathFunctionComboBox->addItem("None");
options_page->mathFunctionComboBox->addItem("Standard deviation");
if(options_page->cmbUAVObjects->currentIndex() >= 0) if(options_page->cmbUAVObjects->currentIndex() >= 0)
on_cmbUAVObjects_currentIndexChanged(options_page->cmbUAVObjects->currentText()); on_cmbUAVObjects_currentIndexChanged(options_page->cmbUAVObjects->currentText());
@ -92,6 +95,7 @@ QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent)
//Set widget values from settings //Set widget values from settings
options_page->cmbPlotType->setCurrentIndex(m_config->plotType()); options_page->cmbPlotType->setCurrentIndex(m_config->plotType());
options_page->mathFunctionComboBox->setCurrentIndex(m_config->mathFunctionType());
options_page->spnDataSize->setValue(m_config->dataSize()); options_page->spnDataSize->setValue(m_config->dataSize());
options_page->spnRefreshInterval->setValue(m_config->refreshInterval()); options_page->spnRefreshInterval->setValue(m_config->refreshInterval());
@ -101,10 +105,11 @@ QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent)
QString uavObject = plotData->uavObject; QString uavObject = plotData->uavObject;
QString uavField = plotData->uavField; QString uavField = plotData->uavField;
int scale = plotData->yScalePower; int scale = plotData->yScalePower;
int interpolation = plotData->yInterpolationSamples; int mean = plotData->yMeanSamples;
QString mathFunction = plotData->mathFunction;
QVariant varColor = plotData->color; QVariant varColor = plotData->color;
addPlotCurveConfig(uavObject,uavField,scale,interpolation,varColor); addPlotCurveConfig(uavObject,uavField,scale,mean,mathFunction,varColor);
} }
if(m_config->plotCurveConfigs().count() > 0) if(m_config->plotCurveConfigs().count() > 0)
@ -152,6 +157,7 @@ void ScopeGadgetOptionsPage::setYAxisWidgetFromPlotCurve()
if(listItem == 0) if(listItem == 0)
return; return;
//WHAT IS UserRole DOING?
int currentIndex = options_page->cmbUAVObjects->findText( listItem->data(Qt::UserRole + 0).toString()); int currentIndex = options_page->cmbUAVObjects->findText( listItem->data(Qt::UserRole + 0).toString());
options_page->cmbUAVObjects->setCurrentIndex(currentIndex); options_page->cmbUAVObjects->setCurrentIndex(currentIndex);
@ -166,9 +172,13 @@ void ScopeGadgetOptionsPage::setYAxisWidgetFromPlotCurve()
setButtonColor(QColor((QRgb)rgb)); setButtonColor(QColor((QRgb)rgb));
int interpolation = listItem->data(Qt::UserRole + 4).toInt(&parseOK); int mean = listItem->data(Qt::UserRole + 4).toInt(&parseOK);
if(!parseOK) interpolation = 1; if(!parseOK) mean = 1;
options_page->spnInterpolationSamples->setValue(interpolation); options_page->spnMeanSamples->setValue(mean);
currentIndex = options_page->mathFunctionComboBox->findData( listItem->data(Qt::UserRole + 5).toString());
options_page->mathFunctionComboBox->setCurrentIndex(currentIndex);
} }
void ScopeGadgetOptionsPage::setButtonColor(const QColor &color) void ScopeGadgetOptionsPage::setButtonColor(const QColor &color)
@ -221,6 +231,7 @@ void ScopeGadgetOptionsPage::apply()
//Apply configuration changes //Apply configuration changes
m_config->setPlotType(options_page->cmbPlotType->currentIndex()); m_config->setPlotType(options_page->cmbPlotType->currentIndex());
m_config->setMathFunctionType(options_page->mathFunctionComboBox->currentIndex());
m_config->setDataSize(options_page->spnDataSize->value()); m_config->setDataSize(options_page->spnDataSize->value());
m_config->setRefreashInterval(options_page->spnRefreshInterval->value()); m_config->setRefreashInterval(options_page->spnRefreshInterval->value());
@ -242,9 +253,12 @@ void ScopeGadgetOptionsPage::apply()
else else
newPlotCurveConfigs->color = (QRgb)rgb; newPlotCurveConfigs->color = (QRgb)rgb;
newPlotCurveConfigs->yInterpolationSamples = listItem->data(Qt::UserRole + 4).toInt(&parseOK); newPlotCurveConfigs->yMeanSamples = listItem->data(Qt::UserRole + 4).toInt(&parseOK);
if(!parseOK) if(!parseOK)
newPlotCurveConfigs->yInterpolationSamples = 1; newPlotCurveConfigs->yMeanSamples = 1;
newPlotCurveConfigs->mathFunction = listItem->data(Qt::UserRole + 5).toString();
plotCurveConfigs.append(newPlotCurveConfigs); plotCurveConfigs.append(newPlotCurveConfigs);
} }
@ -271,7 +285,9 @@ void ScopeGadgetOptionsPage::on_btnAddCurve_clicked()
if(!parseOK) if(!parseOK)
scale = 0; scale = 0;
int interpolation = options_page->spnInterpolationSamples->value(); int mean = options_page->spnMeanSamples->value();
QString mathFunction = options_page->mathFunctionComboBox->currentText();
QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb(); QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb();
@ -281,27 +297,27 @@ void ScopeGadgetOptionsPage::on_btnAddCurve_clicked()
options_page->lstCurves->currentItem()->text() == uavObject + "." + uavField) options_page->lstCurves->currentItem()->text() == uavObject + "." + uavField)
{ {
QListWidgetItem *listWidgetItem = options_page->lstCurves->currentItem(); QListWidgetItem *listWidgetItem = options_page->lstCurves->currentItem();
setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,interpolation,varColor); setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,mean,mathFunction,varColor);
}else }else
{ {
addPlotCurveConfig(uavObject,uavField,scale,interpolation,varColor); addPlotCurveConfig(uavObject,uavField,scale,mean,mathFunction,varColor);
options_page->lstCurves->setCurrentRow(options_page->lstCurves->count() - 1); options_page->lstCurves->setCurrentRow(options_page->lstCurves->count() - 1);
} }
} }
void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavField, int scale, int interpolation, QVariant varColor) void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor)
{ {
//Add a new curve config to the list //Add a new curve config to the list
QString listItemDisplayText = uavObject + "." + uavField; QString listItemDisplayText = uavObject + "." + uavField;
options_page->lstCurves->addItem(listItemDisplayText); options_page->lstCurves->addItem(listItemDisplayText);
QListWidgetItem *listWidgetItem = options_page->lstCurves->item(options_page->lstCurves->count() - 1); QListWidgetItem *listWidgetItem = options_page->lstCurves->item(options_page->lstCurves->count() - 1);
setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,interpolation,varColor); setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,mean,mathFunction,varColor);
} }
void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetItem,QString uavObject, QString uavField, int scale, int interpolation, QVariant varColor) void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetItem,QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor)
{ {
bool parseOK = false; bool parseOK = false;
@ -317,7 +333,8 @@ void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetI
listWidgetItem->setData(Qt::UserRole + 1,QVariant(uavField)); listWidgetItem->setData(Qt::UserRole + 1,QVariant(uavField));
listWidgetItem->setData(Qt::UserRole + 2,QVariant(scale)); listWidgetItem->setData(Qt::UserRole + 2,QVariant(scale));
listWidgetItem->setData(Qt::UserRole + 3,varColor); listWidgetItem->setData(Qt::UserRole + 3,varColor);
listWidgetItem->setData(Qt::UserRole + 4,QVariant(interpolation)); listWidgetItem->setData(Qt::UserRole + 4,QVariant(mean));
listWidgetItem->setData(Qt::UserRole + 5,QVariant(mathFunction));
} }
/*! /*!

View File

@ -66,8 +66,8 @@ private:
Ui::ScopeGadgetOptionsPage *options_page; Ui::ScopeGadgetOptionsPage *options_page;
ScopeGadgetConfiguration *m_config; ScopeGadgetConfiguration *m_config;
void addPlotCurveConfig(QString uavObject, QString uavField, int scale, int interpolation, QVariant varColor); void addPlotCurveConfig(QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor);
void setCurvePlotProperties(QListWidgetItem *listWidgetItem, QString uavObject, QString uavField, int scale, int interpolation, QVariant varColor); void setCurvePlotProperties(QListWidgetItem *listWidgetItem, QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor);
void setYAxisWidgetFromPlotCurve(); void setYAxisWidgetFromPlotCurve();
void setButtonColor(const QColor &color); void setButtonColor(const QColor &color);
void validateRefreshInterval(); void validateRefreshInterval();

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>544</width> <width>548</width>
<height>342</height> <height>457</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -185,43 +185,43 @@
<item row="6" column="1"> <item row="6" column="1">
<widget class="QComboBox" name="cmbUAVField"/> <widget class="QComboBox" name="cmbUAVField"/>
</item> </item>
<item row="7" column="0"> <item row="8" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Color:</string> <string>Color:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="8" column="1">
<widget class="QPushButton" name="btnColor"> <widget class="QPushButton" name="btnColor">
<property name="text"> <property name="text">
<string>Choose</string> <string>Choose</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="0"> <item row="9" column="0">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
<property name="text"> <property name="text">
<string>Y-axis scale factor:</string> <string>Y-axis scale factor:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="1"> <item row="9" column="1">
<widget class="QComboBox" name="cmbScale"> <widget class="QComboBox" name="cmbScale">
<property name="editable"> <property name="editable">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="0"> <item row="10" column="0">
<widget class="QLabel" name="label_10"> <widget class="QLabel" name="label_10">
<property name="text"> <property name="text">
<string>Display smoothed interpolation:</string> <string>Display moving average:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="1"> <item row="10" column="1">
<widget class="QSpinBox" name="spnInterpolationSamples"> <widget class="QSpinBox" name="spnMeanSamples">
<property name="suffix"> <property name="suffix">
<string> samples</string> <string> samples</string>
</property> </property>
@ -239,6 +239,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0">
<widget class="QLabel" name="mathFunctionLabel">
<property name="text">
<string>Math function:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="mathFunctionComboBox"/>
</item>
</layout> </layout>
</item> </item>
<item> <item>

View File

@ -352,7 +352,7 @@ void ScopeGadgetWidget::setupChronoPlot()
// scaleWidget->setMinBorderDist(0, fmw); // scaleWidget->setMinBorderDist(0, fmw);
} }
void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor, int interpolationSamples, QPen pen) void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor, int meanSamples, QString mathFunction, QPen pen)
{ {
PlotData* plotData; PlotData* plotData;
@ -365,7 +365,8 @@ void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField
plotData->m_xWindowSize = m_xWindowSize; plotData->m_xWindowSize = m_xWindowSize;
plotData->scalePower = scaleOrderFactor; plotData->scalePower = scaleOrderFactor;
plotData->interpolationSamples = interpolationSamples; plotData->meanSamples = meanSamples;
plotData->mathFunction = mathFunction;
//If the y-bounds are supplied, set them //If the y-bounds are supplied, set them
if (plotData->yMinimum != plotData->yMaximum) if (plotData->yMinimum != plotData->yMaximum)

View File

@ -81,7 +81,7 @@ public:
int refreshInterval(){return m_refreshInterval;} int refreshInterval(){return m_refreshInterval;}
void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, int interpolationSamples = 1, QPen pen = QPen(Qt::black)); void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, int meanSamples = 1, QString mathFunction= "None", QPen pen = QPen(Qt::black));
//void removeCurvePlot(QString uavObject, QString uavField); //void removeCurvePlot(QString uavObject, QString uavField);
void clearCurvePlots(); void clearCurvePlots();
int csvLoggingStart(); int csvLoggingStart();