Ejemplo n.º 1
0
/**
 * @brief TimeSeriesPlotData::append Appends data to time series data
 * @param obj UAVO with new data
 * @return
 */
bool TimeSeriesPlotData::append(UAVObject* obj)
{
    if (uavObjectName == obj->getName()) {
        //Get the field of interest
        UAVObjectField* field =  obj->getField(uavFieldName);

        if (field) {
            QDateTime NOW = QDateTime::currentDateTime(); //THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME
            double currentValue = valueAsDouble(obj, field, haveSubField, uavSubFieldName) * pow(10, scalePower);

            //Perform scope math, if necessary
            if (mathFunction  == "Boxcar average" || mathFunction  == "Standard deviation"){
                //Put the new value at the back
                yDataHistory->append( currentValue );

                // calculate average value
                meanSum += currentValue;
                if(yDataHistory->size() > meanSamples) {
                    meanSum -= yDataHistory->first();
                    yDataHistory->pop_front();
                }
                // make sure to correct the sum every meanSamples steps to prevent it
                // from running away due to floating point rounding errors
                correctionSum+=currentValue;
                if (++correctionCount >= meanSamples) {
                    meanSum = correctionSum;
                    correctionSum = 0.0f;
                    correctionCount = 0;
                }

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

            double valueX = NOW.toTime_t() + NOW.time().msec() / 1000.0;
            xData->append(valueX);

            //Remove stale data
            removeStaleData();

            return true;
        }
    }

    return false;
}
Ejemplo n.º 2
0
/**
 * @brief SpectrogramScopeConfig::plotNewData Update plot with new data
 * @param scopeGadgetWidget
 */
void SpectrogramData::plotNewData(PlotData *plot3dData, ScopeConfig *scopeConfig, ScopeGadgetWidget *scopeGadgetWidget)
{
    Q_UNUSED(plot3dData);

    removeStaleData();

    // Check for new data
    if (readAndResetUpdatedFlag() == true){
        // Plot new data
        rasterData->setValueMatrix(*zDataHistory, windowWidth);

        // Check autoscale. (For some reason, QwtSpectrogram doesn't support autoscale)
        if (zMaximum == 0){
            double newVal = readAndResetAutoscaleValue();
            if (newVal != 0){
                rightAxis->setColorMap( QwtInterval(0, newVal), new ColorMap(((SpectrogramScopeConfig*) scopeConfig)->getColorMap()));
                scopeGadgetWidget->setAxisScale( QwtPlot::yRight, 0, newVal);
            }
        }
    }
}
Ejemplo n.º 3
0
/**
 * @brief TimeSeriesPlotData::removeStaleDataTimeout On timer timeout, removes data that can no longer be seen on axes.
 */
void TimeSeriesPlotData::removeStaleDataTimeout()
{
    removeStaleData();
}