From 44c8c9fbe51a2e66d88f09bea21c68cb6b00a74b Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Fri, 18 Nov 2011 18:30:58 +0100 Subject: [PATCH 1/5] GCS/ScopePlugin: Allow SoftwareInterpolation of measurement value --- .../src/plugins/scope/plotdata.cpp | 21 +++++++++++++-- .../openpilotgcs/src/plugins/scope/plotdata.h | 3 +++ .../src/plugins/scope/scopegadget.cpp | 2 ++ .../scope/scopegadgetconfiguration.cpp | 3 +++ .../plugins/scope/scopegadgetconfiguration.h | 1 + .../plugins/scope/scopegadgetoptionspage.cpp | 23 +++++++++++----- .../plugins/scope/scopegadgetoptionspage.h | 4 +-- .../plugins/scope/scopegadgetoptionspage.ui | 26 +++++++++++++++++++ .../src/plugins/scope/scopegadgetwidget.cpp | 3 ++- .../src/plugins/scope/scopegadgetwidget.h | 2 +- 10 files changed, 76 insertions(+), 12 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/scope/plotdata.cpp b/ground/openpilotgcs/src/plugins/scope/plotdata.cpp index f2d4bb5af..fdcb75a83 100644 --- a/ground/openpilotgcs/src/plugins/scope/plotdata.cpp +++ b/ground/openpilotgcs/src/plugins/scope/plotdata.cpp @@ -49,9 +49,12 @@ PlotData::PlotData(QString p_uavObject, QString p_uavField) xData = new QVector(); yData = new QVector(); + yDataHistory = new QVector(); curve = 0; scalePower = 0; + interpolationSamples = 1; + interpolationSum = 0.0f; yMinimum = 0; yMaximum = 0; @@ -78,6 +81,7 @@ PlotData::~PlotData() { delete xData; delete yData; + delete yDataHistory; } @@ -91,7 +95,13 @@ bool SequencialPlotData::append(UAVObject* obj) if (field) { //Shift data forward and put the new value at the front - yData->append( valueAsDouble(obj, field) * pow(10, scalePower)); + yDataHistory->append( valueAsDouble(obj, field) * pow(10, scalePower)); + interpolationSum += valueAsDouble(obj, field) * pow(10, scalePower); + if(yDataHistory->size() > interpolationSamples) { + interpolationSum -= yDataHistory->first(); + yDataHistory->pop_front(); + } + yData->append(interpolationSum/yDataHistory->size()); if (yData->size() > m_xWindowSize) { yData->pop_front(); } else @@ -117,8 +127,15 @@ bool ChronoPlotData::append(UAVObject* obj) //Put the new value at the front QDateTime NOW = QDateTime::currentDateTime(); + yDataHistory->append( valueAsDouble(obj, field) * pow(10, scalePower)); + interpolationSum += valueAsDouble(obj, field) * pow(10, scalePower); + if(yDataHistory->size() > interpolationSamples) { + interpolationSum -= yDataHistory->first(); + yDataHistory->pop_front(); + } + double valueX = NOW.toTime_t() + NOW.time().msec() / 1000.0; - double valueY = valueAsDouble(obj, field) * pow(10, scalePower); + double valueY = interpolationSum/yDataHistory->size(); xData->append(valueX); yData->append(valueY); diff --git a/ground/openpilotgcs/src/plugins/scope/plotdata.h b/ground/openpilotgcs/src/plugins/scope/plotdata.h index 2d61f12c6..0b87c9937 100644 --- a/ground/openpilotgcs/src/plugins/scope/plotdata.h +++ b/ground/openpilotgcs/src/plugins/scope/plotdata.h @@ -72,12 +72,15 @@ public: QString uavSubField; bool haveSubField; int scalePower; //This is the power to which each value must be raised + int interpolationSamples; + double interpolationSum; double yMinimum; double yMaximum; double m_xWindowSize; QwtPlotCurve* curve; QVector* xData; QVector* yData; + QVector* yDataHistory; virtual bool append(UAVObject* obj) = 0; virtual PlotType plotType() = 0; diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp index ccf4a8b82..b4b1f24fa 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadget.cpp @@ -61,12 +61,14 @@ void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration* config) QString uavObject = plotCurveConfig->uavObject; QString uavField = plotCurveConfig->uavField; int scale = plotCurveConfig->yScalePower; + int interpolation = plotCurveConfig->yInterpolationSamples; QRgb color = plotCurveConfig->color; widget->addCurvePlot( uavObject, uavField, scale, + interpolation, QPen( QBrush(QColor(color),Qt::SolidPattern), // (qreal)2, (qreal)1, diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp index 63a48e495..6337be38f 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp @@ -65,6 +65,7 @@ ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, QSettings* q color = qSettings->value("color").value(); plotCurveConf->color = color; plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt(); + plotCurveConf->yInterpolationSamples = qSettings->value("yInterpolationSamples").toInt(); plotCurveConf->yMinimum = qSettings->value("yMinimum").toDouble(); plotCurveConf->yMaximum = qSettings->value("yMaximum").toDouble(); @@ -118,6 +119,7 @@ IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone() newPlotCurveConf->uavField = currentPlotCurveConf->uavField; newPlotCurveConf->color = currentPlotCurveConf->color; newPlotCurveConf->yScalePower = currentPlotCurveConf->yScalePower; + newPlotCurveConf->yInterpolationSamples = currentPlotCurveConf->yInterpolationSamples; newPlotCurveConf->yMinimum = currentPlotCurveConf->yMinimum; newPlotCurveConf->yMaximum = currentPlotCurveConf->yMaximum; @@ -157,6 +159,7 @@ void ScopeGadgetConfiguration::saveConfig(QSettings* qSettings) const { qSettings->setValue("uavField", plotCurveConf->uavField); 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); diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.h b/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.h index 1aadcaf5b..570ebe1f9 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.h +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.h @@ -41,6 +41,7 @@ struct PlotCurveConfiguration QString uavField; int yScalePower; //This is the power to which each value must be raised QRgb color; + int yInterpolationSamples; double yMinimum; double yMaximum; }; diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.cpp index e44ccb08f..d0d364b68 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.cpp @@ -101,9 +101,10 @@ QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent) QString uavObject = plotData->uavObject; QString uavField = plotData->uavField; int scale = plotData->yScalePower; + int interpolation = plotData->yInterpolationSamples; QVariant varColor = plotData->color; - addPlotCurveConfig(uavObject,uavField,scale,varColor); + addPlotCurveConfig(uavObject,uavField,scale,interpolation,varColor); } if(m_config->plotCurveConfigs().count() > 0) @@ -163,6 +164,10 @@ void ScopeGadgetOptionsPage::setYAxisWidgetFromPlotCurve() int rgb = varColor.toInt(&parseOK); setButtonColor(QColor((QRgb)rgb)); + + int interpolation = listItem->data(Qt::UserRole + 4).toInt(&parseOK); + if(!parseOK) interpolation = 1; + options_page->spnInterpolationSamples->setValue(interpolation); } void ScopeGadgetOptionsPage::setButtonColor(const QColor &color) @@ -235,6 +240,10 @@ void ScopeGadgetOptionsPage::apply() newPlotCurveConfigs->color = QColor(Qt::black).rgb(); else newPlotCurveConfigs->color = (QRgb)rgb; + + newPlotCurveConfigs->yInterpolationSamples = listItem->data(Qt::UserRole + 4).toInt(&parseOK); + if(!parseOK) + newPlotCurveConfigs->yInterpolationSamples = 1; plotCurveConfigs.append(newPlotCurveConfigs); } @@ -261,6 +270,7 @@ void ScopeGadgetOptionsPage::on_btnAddCurve_clicked() if(!parseOK) scale = 0; + int interpolation = options_page->spnInterpolationSamples->value(); QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb(); @@ -270,27 +280,27 @@ void ScopeGadgetOptionsPage::on_btnAddCurve_clicked() options_page->lstCurves->currentItem()->text() == uavObject + "." + uavField) { QListWidgetItem *listWidgetItem = options_page->lstCurves->currentItem(); - setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,varColor); + setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,interpolation,varColor); }else { - addPlotCurveConfig(uavObject,uavField,scale,varColor); + addPlotCurveConfig(uavObject,uavField,scale,interpolation,varColor); options_page->lstCurves->setCurrentRow(options_page->lstCurves->count() - 1); } } -void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavField, int scale, QVariant varColor) +void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavField, int scale, int interpolation, QVariant varColor) { //Add a new curve config to the list QString listItemDisplayText = uavObject + "." + uavField; options_page->lstCurves->addItem(listItemDisplayText); QListWidgetItem *listWidgetItem = options_page->lstCurves->item(options_page->lstCurves->count() - 1); - setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,varColor); + setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,interpolation,varColor); } -void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetItem,QString uavObject, QString uavField, int scale, QVariant varColor) +void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetItem,QString uavObject, QString uavField, int scale, int interpolation, QVariant varColor) { bool parseOK = false; @@ -306,6 +316,7 @@ void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetI listWidgetItem->setData(Qt::UserRole + 1,QVariant(uavField)); listWidgetItem->setData(Qt::UserRole + 2,QVariant(scale)); listWidgetItem->setData(Qt::UserRole + 3,varColor); + listWidgetItem->setData(Qt::UserRole + 4,QVariant(interpolation)); } /*! diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.h b/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.h index cbbf9201b..39c0b3ea5 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.h +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.h @@ -66,8 +66,8 @@ private: Ui::ScopeGadgetOptionsPage *options_page; ScopeGadgetConfiguration *m_config; - void addPlotCurveConfig(QString uavObject, QString uavField, int scale, QVariant varColor); - void setCurvePlotProperties(QListWidgetItem *listWidgetItem, QString uavObject, QString uavField, int scale, QVariant varColor); + void addPlotCurveConfig(QString uavObject, QString uavField, int scale, int interpolation, QVariant varColor); + void setCurvePlotProperties(QListWidgetItem *listWidgetItem, QString uavObject, QString uavField, int scale, int interpolation, QVariant varColor); void setYAxisWidgetFromPlotCurve(); void setButtonColor(const QColor &color); diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.ui b/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.ui index 2aaee1942..147f972f1 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.ui +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.ui @@ -159,6 +159,32 @@ + + + + Smooth Interpolation: + + + + + + + samples + + + 1 + + + 1001 + + + 10 + + + 1 + + + diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp index dfbd9d614..2270178cd 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp @@ -356,7 +356,7 @@ void ScopeGadgetWidget::setupChronoPlot() // scaleWidget->setMinBorderDist(0, fmw); } -void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor, QPen pen) +void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor, int interpolationSamples, QPen pen) { PlotData* plotData; @@ -369,6 +369,7 @@ void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField plotData->m_xWindowSize = m_xWindowSize; plotData->scalePower = scaleOrderFactor; + plotData->interpolationSamples = interpolationSamples; //If the y-bounds are supplied, set them if (plotData->yMinimum != plotData->yMaximum) diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h index fd8aaf550..09e79d6b0 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h @@ -110,7 +110,7 @@ public: int refreshInterval(){return m_refreshInterval;} - void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, QPen pen = QPen(Qt::black)); + void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, int interpolationSamples = 1, QPen pen = QPen(Qt::black)); //void removeCurvePlot(QString uavObject, QString uavField); void clearCurvePlots(); int csvLoggingStart(); From dfd18d43b5328827b215277b4592b20d10f32756 Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Sat, 26 Nov 2011 22:06:21 +0100 Subject: [PATCH 2/5] GCS/Scope: CSV export exports non-interpolated data --- ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp index 2270178cd..fe322f06b 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp @@ -710,7 +710,7 @@ int ScopeGadgetWidget::csvLoggingInsertData() } else { - ss << QString().sprintf("%3.6g",plotData2->yData->last()/pow(10,plotData2->scalePower)); + ss << QString().sprintf("%3.6g",plotData2->yDataHistory->last()/pow(10,plotData2->scalePower)); m_csvLoggingDataValid=1; } } From 5af9a2558c8f61a87d9d3db506ccc6a5eb5b61ce Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Sat, 26 Nov 2011 22:06:46 +0100 Subject: [PATCH 3/5] GCS/Scope: Make smooth interpolation (and internal sum) be long term correct despite limited floating point accuracy, but keep constant overhead --- .../src/plugins/scope/plotdata.cpp | 31 ++++++++++++++++--- .../openpilotgcs/src/plugins/scope/plotdata.h | 2 ++ .../plugins/scope/scopegadgetoptionspage.ui | 4 +-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/scope/plotdata.cpp b/ground/openpilotgcs/src/plugins/scope/plotdata.cpp index fdcb75a83..e05bf7a1b 100644 --- a/ground/openpilotgcs/src/plugins/scope/plotdata.cpp +++ b/ground/openpilotgcs/src/plugins/scope/plotdata.cpp @@ -55,6 +55,8 @@ PlotData::PlotData(QString p_uavObject, QString p_uavField) scalePower = 0; interpolationSamples = 1; interpolationSum = 0.0f; + correctionSum = 0.0f; + correctionCount = 0; yMinimum = 0; yMaximum = 0; @@ -95,12 +97,23 @@ bool SequencialPlotData::append(UAVObject* obj) if (field) { //Shift data forward and put the new value at the front - yDataHistory->append( valueAsDouble(obj, field) * pow(10, scalePower)); - interpolationSum += valueAsDouble(obj, field) * pow(10, scalePower); + + // calculate interpolated (smoothed) value + double currentValue = valueAsDouble(obj, field) * pow(10, scalePower); + yDataHistory->append( currentValue ); + interpolationSum += currentValue; if(yDataHistory->size() > interpolationSamples) { interpolationSum -= yDataHistory->first(); yDataHistory->pop_front(); } + // make sure to correct the sum every interpolationSamples steps to prevent it + // from running away due to flouting point rounding errors + correctionSum += currentValue; + if (++correctionCount >= interpolationSamples) { + interpolationSum = correctionSum; + correctionSum = 0.0f; + correctionCount = 0; + } yData->append(interpolationSum/yDataHistory->size()); if (yData->size() > m_xWindowSize) { yData->pop_front(); @@ -127,12 +140,22 @@ bool ChronoPlotData::append(UAVObject* obj) //Put the new value at the front QDateTime NOW = QDateTime::currentDateTime(); - yDataHistory->append( valueAsDouble(obj, field) * pow(10, scalePower)); - interpolationSum += valueAsDouble(obj, field) * pow(10, scalePower); + // calculate interpolated (smoothed) value + double currentValue = valueAsDouble(obj, field) * pow(10, scalePower); + yDataHistory->append( currentValue ); + interpolationSum += currentValue; if(yDataHistory->size() > interpolationSamples) { interpolationSum -= yDataHistory->first(); yDataHistory->pop_front(); } + // make sure to correct the sum every interpolationSamples steps to prevent it + // from running away due to flouting point rounding errors + correctionSum += currentValue; + if (++correctionCount >= interpolationSamples) { + interpolationSum = correctionSum; + correctionSum = 0.0f; + correctionCount = 0; + } double valueX = NOW.toTime_t() + NOW.time().msec() / 1000.0; double valueY = interpolationSum/yDataHistory->size(); diff --git a/ground/openpilotgcs/src/plugins/scope/plotdata.h b/ground/openpilotgcs/src/plugins/scope/plotdata.h index 0b87c9937..a547f2b91 100644 --- a/ground/openpilotgcs/src/plugins/scope/plotdata.h +++ b/ground/openpilotgcs/src/plugins/scope/plotdata.h @@ -74,6 +74,8 @@ public: int scalePower; //This is the power to which each value must be raised int interpolationSamples; double interpolationSum; + double correctionSum; + int correctionCount; double yMinimum; double yMaximum; double m_xWindowSize; diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.ui b/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.ui index 147f972f1..b3d22faa0 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.ui +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetoptionspage.ui @@ -162,7 +162,7 @@ - Smooth Interpolation: + Display smoothed interpolation: @@ -294,7 +294,7 @@ Update - Log data to csv file + Log data to csv file (not interpolated) From 15c1ca4af117e29326ef85196e0fa83b029c53df Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Sat, 26 Nov 2011 22:51:20 +0100 Subject: [PATCH 4/5] GVS/Scope: Bugfix: Export all known data points into CSV not just one per screen redraw --- .../src/plugins/scope/scopegadgetwidget.cpp | 78 +++++++++++-------- .../src/plugins/scope/scopegadgetwidget.h | 2 + 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp index fe322f06b..12f6974b8 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp @@ -447,6 +447,7 @@ void ScopeGadgetWidget::uavObjectReceived(UAVObject* obj) foreach(PlotData* plotData, m_curvesData.values()) { if (plotData->append(obj)) m_csvLoggingDataUpdated=1; } + csvLoggingAddData(); } void ScopeGadgetWidget::replotNewData() @@ -610,6 +611,7 @@ int ScopeGadgetWidget::csvLoggingStart() m_csvLoggingStartTime = NOW; m_csvLoggingHeaderSaved=0; m_csvLoggingDataSaved=0; + m_csvLoggingBuffer.clear(); QDir PathCheck(m_csvLoggingPath); if (!PathCheck.exists()) { @@ -677,13 +679,50 @@ int ScopeGadgetWidget::csvLoggingInsertHeader() return 0; } +int ScopeGadgetWidget::csvLoggingAddData() +{ + if (!m_csvLoggingStarted) return -1; + m_csvLoggingDataValid=0; + QDateTime NOW = QDateTime::currentDateTime(); + QString tempString; + + QTextStream ss( &tempString ); + ss << NOW.toString("yyyy-MM-dd") << ", " << NOW.toString("hh:mm:ss.z") << ", " ; + +#if QT_VERSION >= 0x040700 + ss <<(NOW.toMSecsSinceEpoch() - m_csvLoggingStartTime.toMSecsSinceEpoch())/1000.00; +#else + ss <<(NOW.toTime_t() - m_csvLoggingStartTime.toTime_t()); +#endif + ss << ", " << m_csvLoggingConnected << ", " << m_csvLoggingDataUpdated; + m_csvLoggingDataUpdated=0; + + foreach(PlotData* plotData2, m_curvesData.values()) + { + ss << ", "; + if (plotData2->xData->isEmpty ()) + { + } + else + { + ss << QString().sprintf("%3.6g",plotData2->yDataHistory->last()/pow(10,plotData2->scalePower)); + m_csvLoggingDataValid=1; + } + } + ss << endl; + if (m_csvLoggingDataValid) + { + QTextStream ts( &m_csvLoggingBuffer ); + ts << tempString; + } + + return 0; +} + int ScopeGadgetWidget::csvLoggingInsertData() { if (!m_csvLoggingStarted) return -1; m_csvLoggingDataSaved=1; - m_csvLoggingDataValid=0; - QDateTime NOW = QDateTime::currentDateTime(); - QString tempString; if(m_csvLoggingFile.open(QIODevice::WriteOnly | QIODevice::Append)== FALSE) { @@ -691,38 +730,11 @@ int ScopeGadgetWidget::csvLoggingInsertData() } else { - QTextStream ss( &tempString ); - ss << NOW.toString("yyyy-MM-dd") << ", " << NOW.toString("hh:mm:ss.z") << ", " ; - -#if QT_VERSION >= 0x040700 - ss <<(NOW.toMSecsSinceEpoch() - m_csvLoggingStartTime.toMSecsSinceEpoch())/1000.00; -#else - ss <<(NOW.toTime_t() - m_csvLoggingStartTime.toTime_t()); -#endif - ss << ", " << m_csvLoggingConnected << ", " << m_csvLoggingDataUpdated; - m_csvLoggingDataUpdated=0; - - foreach(PlotData* plotData2, m_curvesData.values()) - { - ss << ", "; - if (plotData2->xData->isEmpty ()) - { - } - else - { - ss << QString().sprintf("%3.6g",plotData2->yDataHistory->last()/pow(10,plotData2->scalePower)); - m_csvLoggingDataValid=1; - } - } - ss << endl; - if (m_csvLoggingDataValid) - { - QTextStream ts( &m_csvLoggingFile ); - ts << tempString; - } + QTextStream ts( &m_csvLoggingFile ); + ts << m_csvLoggingBuffer; m_csvLoggingFile.close(); } - + m_csvLoggingBuffer.clear(); return 0; } diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h index 09e79d6b0..98da3beb6 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h @@ -166,11 +166,13 @@ private: QString m_csvLoggingName; QString m_csvLoggingPath; + QString m_csvLoggingBuffer; QFile m_csvLoggingFile; QMutex mutex; int csvLoggingInsertHeader(); + int csvLoggingAddData(); int csvLoggingInsertData(); void deleteLegend(); From 716bb8ec561f1fa9467e1a89623bd95e90bfdd8d Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Thu, 15 Dec 2011 23:49:01 +0100 Subject: [PATCH 5/5] GCS:Scope: Backward Compatibility: Set Interpolation to minimum (1) when not set in config file --- .../openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp index 6337be38f..3228497f3 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp @@ -66,6 +66,7 @@ ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, QSettings* q plotCurveConf->color = color; plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt(); plotCurveConf->yInterpolationSamples = qSettings->value("yInterpolationSamples").toInt(); + if (!plotCurveConf->yInterpolationSamples) plotCurveConf->yInterpolationSamples = 1; // fallback for backward compatibility with earlier versions plotCurveConf->yMinimum = qSettings->value("yMinimum").toDouble(); plotCurveConf->yMaximum = qSettings->value("yMaximum").toDouble();