Exemplo 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;
}
Exemplo n.º 2
0
double ConfigurationManager::retrieveAsDouble(std::string namespaceName, std::string identifier, double defaultValue)
{
	double result = defaultValue;
	
	EntriesMap::const_iterator iter = entries->find(std::make_pair(namespaceName, identifier));
	if(iter != entries->end())
	{
		result = valueAsDouble(iter->second,defaultValue);
	}
	
	return result;
}
Exemplo n.º 3
0
/**
 * @brief SeriesPlotData::append Appends data to series plot
 * @param obj UAVO with new data
 * @return
 */
bool SeriesPlotData::append(UAVObject* obj)
{
    if (uavObjectName == obj->getName()) {

        //Get the field of interest
        UAVObjectField* field =  obj->getField(uavFieldName);

        if (field) {

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

            if (yData->size() > getXWindowSize()) { //If new data overflows the window, remove old data...
                yData->pop_front();
            } else //...otherwise, add a new y point at position xData
                xData->insert(xData->size(), xData->size());

            return true;
        }
    }

    return false;
}
Exemplo n.º 4
0
/**
 * @brief SpectrogramData::append Appends data to spectrogram
 * @param obj UAVO with new data
 * @return
 */
bool SpectrogramData::append(UAVObject* multiObj)
{
    QDateTime NOW = QDateTime::currentDateTime(); //TODO: Upgrade this to show UAVO time and not system time

    // Check to make sure it's the correct UAVO
    if (uavObjectName == multiObj->getName()) {

        // Only run on UAVOs that have multiple instances
        if (multiObj->isSingleInstance())
            return false;

        //Instantiate object manager
        UAVObjectManager *objManager;

        ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
        Q_ASSERT(pm != NULL);
        objManager = pm->getObject<UAVObjectManager>();
        Q_ASSERT(objManager != NULL);


        // Get list of object instances
        QVector<UAVObject*> list = objManager->getObjectInstancesVector(multiObj->getName());

        // Remove a row's worth of data.
        unsigned int spectrogramWidth = list.size();

        // Check that there is a full window worth of data. While GCS is starting up, the size of
        // multiple instance UAVOs is 1, so it's possible for spurious data to come in before
        // the flight controller board has had time to initialize the UAVO size.
        if (spectrogramWidth != windowWidth){
            qDebug() << "Incomplete data set in" << multiObj->getName() << "." << uavFieldName <<  "spectrogram: " << spectrogramWidth << " samples provided, but expected " << windowWidth;
            return false;
        }

        //Initialize vector where we will read out an entire row of multiple instance UAVO
        QVector<double> values;

        timeDataHistory->append(NOW.toTime_t() + NOW.time().msec() / 1000.0);
        UAVObjectField* multiField =  multiObj->getField(uavFieldName);
        Q_ASSERT(multiField);
        if (multiField ) {

            // Get the field of interest
            foreach (UAVObject *obj, list) {
                UAVObjectField* field =  obj->getField(uavFieldName);

                double currentValue = valueAsDouble(obj, field, haveSubField, uavSubFieldName) * pow(10, scalePower);

                double vecVal = currentValue;
                //Normally some math would go here, modifying vecVal before appending it to values
                // .
                // .
                // .


                // Second to last step, see if autoscale is turned on and if the value exceeds the maximum for the scope.
                if ( zMaximum == 0 &&  vecVal > rasterData->interval(Qt::ZAxis).maxValue()){
                    // Change scope maximum and color depth
                    rasterData->setInterval(Qt::ZAxis, QwtInterval(0, vecVal) );
                    autoscaleValueUpdated = vecVal;
                }
                // Last step, assign value to vector
                values += vecVal;
            }

            while (timeDataHistory->back() - timeDataHistory->front() > timeHorizon){
                timeDataHistory->pop_front();
                zDataHistory->remove(0, fminl(spectrogramWidth, zDataHistory->size()));
            }

            // Doublecheck that there are the right number of samples. This can occur if the "field" assert fails
            if(values.size() == (int) windowWidth){
                *zDataHistory << values;
            }

            return true;
        }
    }