1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-21 13:28:58 +01:00

OP-42 GCS/Scope: Added support for array-like UAVObject fields

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1465 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
banigreyling 2010-08-30 14:17:15 +00:00 committed by banigreyling
parent 65dc5e9b04
commit e15a12329c
6 changed files with 113 additions and 37 deletions

View File

@ -31,9 +31,21 @@
#include <QDebug>
PlotData::PlotData(QString p_uavObject, QString p_uavField)
{
{
uavObject = p_uavObject;
uavField = p_uavField;
if(p_uavField.contains("-"))
{
QStringList fieldSubfield = p_uavField.split("-", QString::SkipEmptyParts);
uavField = fieldSubfield.at(0);
uavSubField = fieldSubfield.at(1);
haveSubField = true;
}
else
{
uavField = p_uavField;
haveSubField = false;
}
xData = new QVector<double>();
yData = new QVector<double>();
@ -46,6 +58,21 @@ PlotData::PlotData(QString p_uavObject, QString p_uavField)
m_xWindowSize = 0;
}
double PlotData::valueAsDouble(UAVObject* obj, UAVObjectField* field)
{
QVariant value;
if(haveSubField){
int indexOfSubField = field->getElementNames().indexOf(QRegExp(uavSubField, Qt::CaseSensitive, QRegExp::FixedString));
value = field->getValue(indexOfSubField);
}else
value = field->getValue();
// qDebug() << "Data (" << value.typeName() << ") " << value.toString();
return value.toDouble();
}
PlotData::~PlotData()
{
delete xData;
@ -56,12 +83,14 @@ PlotData::~PlotData()
bool SequencialPlotData::append(UAVObject* obj)
{
if (uavObject == obj->getName()) {
//Get the field of interest
UAVObjectField* field = obj->getField(uavField);
if (field) {
//Shift data forward and put the new value at the front
yData->append(field->getDouble() * pow(10, scalePower));
yData->append( valueAsDouble(obj, field) * pow(10, scalePower));
if (yData->size() > m_xWindowSize) {
yData->pop_front();
} else
@ -81,14 +110,18 @@ bool ChronoPlotData::append(UAVObject* obj)
if (uavObject == obj->getName()) {
//Get the field of interest
UAVObjectField* field = obj->getField(uavField);
//qDebug() << "uavObject: " << uavObject << ", uavField: " << uavField;
if (field) {
//Put the new value at the front
QDateTime NOW = QDateTime::currentDateTime();
double newestValue = NOW.toTime_t() + NOW.time().msec() / 1000.0;
xData->append(newestValue);
yData->append(field->getDouble() * pow(10, scalePower));
double valueX = NOW.toTime_t() + NOW.time().msec() / 1000.0;
double valueY = valueAsDouble(obj, field) * pow(10, scalePower);
xData->append(valueX);
yData->append(valueY);
//qDebug() << "Data " << uavObject << "." << field->getName() << " X,Y:" << valueX << "," << valueY;
//Remove stale data
removeStaleData();

View File

@ -31,6 +31,8 @@
#include "uavobjects/uavobject.h"
#include "uavobjects/baroaltitude.h"
#include "uavobjects/positionactual.h"
#include "uavobjects/attituderaw.h"
#include "uavobjects/manualcontrolcommand.h"
#include "qwt/src/qwt.h"
@ -67,6 +69,8 @@ public:
QString uavObject;
QString uavField;
QString uavSubField;
bool haveSubField;
int scalePower; //This is the power to which each value must be raised
double yMinimum;
double yMaximum;
@ -81,6 +85,9 @@ public:
void updatePlotCurveData();
protected:
double valueAsDouble(UAVObject* obj, UAVObjectField* field);
signals:
void dataChanged();
};

View File

@ -82,4 +82,4 @@ private:
};
#endif // SCOPEGADGETCONFIGURATION_H
#endif // SCOPEGADGETCONFIGURATION_H

View File

@ -172,7 +172,18 @@ void ScopeGadgetOptionsPage::on_cmbUAVObjects_currentIndexChanged(QString val)
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
options_page->cmbUAVField->addItem(field->getName());
if(field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM )
continue;
if(field->getElementNames().count() > 1)
{
foreach(QString elemName , field->getElementNames())
{
options_page->cmbUAVField->addItem(field->getName() + "-" + elemName);
}
}
else
options_page->cmbUAVField->addItem(field->getName());
}
}
@ -191,7 +202,7 @@ void ScopeGadgetOptionsPage::apply()
m_config->setDataSize(options_page->spnDataSize->value());
m_config->setRefreashInterval(options_page->spnRefreshInterval->value());
QList<PlotCurveConfiguration*> m_PlotCurveConfigs;
QList<PlotCurveConfiguration*> plotCurveConfigs;
for(int iIndex = 0; iIndex < options_page->lstCurves->count();iIndex++) {
QListWidgetItem* listItem = options_page->lstCurves->item(iIndex);
@ -209,10 +220,10 @@ void ScopeGadgetOptionsPage::apply()
else
newPlotCurveConfigs->color = (QRgb)rgb;
m_PlotCurveConfigs.append(newPlotCurveConfigs);
plotCurveConfigs.append(newPlotCurveConfigs);
}
m_config->replacePlotCurveConfig(m_PlotCurveConfigs);
m_config->replacePlotCurveConfig(plotCurveConfigs);
}
/*!
@ -231,7 +242,7 @@ void ScopeGadgetOptionsPage::on_btnAddCurve_clicked()
QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb();
//TODO: Find an existing plot curve config based on the uavobject and uav field. If it
//Find an existing plot curve config based on the uavobject and uav field. If it
//exists, update it, else add a new one.
if(options_page->lstCurves->currentItem()->text() == uavObject + "." + uavField)
{
@ -247,8 +258,6 @@ void ScopeGadgetOptionsPage::on_btnAddCurve_clicked()
void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavField, int scale, QVariant varColor)
{
bool parseOK = false;
//Add a new curve config to the list
QString listItemDisplayText = uavObject + "." + uavField;
options_page->lstCurves->addItem(listItemDisplayText);

View File

@ -160,21 +160,25 @@ void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavField, int sc
if (plotData->yMinimum != plotData->yMaximum)
setAxisScale(QwtPlot::yLeft, plotData->yMinimum, plotData->yMaximum);
//Create the curve
QString curveName;
if(scaleOrderFactor == 0)
curveName = (plotData->uavObject) + "." + (plotData->uavField);
else
curveName = (plotData->uavObject) + "." + (plotData->uavField) + "(E" + QString::number(scaleOrderFactor) + ")";
//Create the curve
QString curveName = (plotData->uavObject) + "." + (plotData->uavField);
if(plotData->haveSubField)
curveName = curveName.append("." + plotData->uavSubField);
QwtPlotCurve* plotCurve = new QwtPlotCurve(curveName);
QString curveNameScaled;
if(scaleOrderFactor == 0)
curveNameScaled = curveName;
else
curveNameScaled = curveName + "(E" + QString::number(scaleOrderFactor) + ")";
QwtPlotCurve* plotCurve = new QwtPlotCurve(curveNameScaled);
plotCurve->setPen(pen);
plotCurve->setData(*plotData->xData, *plotData->yData);
plotCurve->attach(this);
plotData->curve = plotCurve;
//Keep the curve details for later
m_curvesData.insert(curveName, plotData);
m_curvesData.insert(curveNameScaled, plotData);
//Get the object to monitor
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
@ -190,19 +194,19 @@ void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavField, int sc
replot();
}
void ScopeGadgetWidget::removeCurvePlot(QString uavObject, QString uavField)
{
QString curveName = uavObject + "." + uavField;
PlotData* plotData = m_curvesData.take(curveName);
m_curvesData.remove(curveName);
plotData->curve->detach();
delete plotData->curve;
delete plotData;
replot();
}
//void ScopeGadgetWidget::removeCurvePlot(QString uavObject, QString uavField)
//{
// QString curveName = uavObject + "." + uavField;
//
// PlotData* plotData = m_curvesData.take(curveName);
// m_curvesData.remove(curveName);
// plotData->curve->detach();
//
// delete plotData->curve;
// delete plotData;
//
// replot();
//}
void ScopeGadgetWidget::uavObjectReceived(UAVObject* obj)
{
@ -319,14 +323,17 @@ TestDataGen::TestDataGen()
baroAltitude = BaroAltitude::GetInstance(objManager);
gps = PositionActual::GetInstance(objManager);
attRaw = AttitudeRaw::GetInstance(objManager);
manCtrlCmd = ManualControlCommand::GetInstance(objManager);
//Setup timer
periodMs = 4;
periodMs = 20;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(genTestData()));
timer->start(periodMs);
debugCounter = 0;
testTime = 0;
}
void TestDataGen::genTestData()
@ -349,6 +356,24 @@ void TestDataGen::genTestData()
gpsData.Satellites = 10;
gps->setData(gpsData);
// Update Attitude Raw data
AttitudeRaw::DataFields attData;
// attData.accels[0] = 4 * sin(2 * testTime) + 1 * cos(6 * testTime) + 4;
// attData.accels[1] = 3 * sin(2.3 * testTime) + 1.5 * cos(3.3 * testTime) + 2;
// attData.accels[2] = 4 * sin(5.3 * testTime) + 1.5 * cos(1.3 * testTime) + 1;
attData.accels[0] = 1;
attData.accels[1] = 4;
attData.accels[2] = 9;
attRaw->setData(attData);
ManualControlCommand::DataFields manCtlData;
manCtlData.Channel[0] = 400 * cos(2 * testTime) + 100 * sin(6 * testTime) + 400;
manCtlData.Channel[1] = 350 * cos(2.3 * testTime) + 150 * sin(3.3 * testTime) + 200;
manCtlData.Channel[2] = 450 * cos(5.3 * testTime) + 150 * sin(1.3 * testTime) + 150;
manCtrlCmd->setData(manCtlData);
testTime += (periodMs / 1000.0);
// debugCounter++;

View File

@ -80,6 +80,8 @@ public:
private:
BaroAltitude* baroAltitude;
PositionActual* gps;
AttitudeRaw* attRaw;
ManualControlCommand* manCtrlCmd;
QTimer *timer;
double testTime;
@ -112,7 +114,7 @@ public:
void addCurvePlot(QString uavObject, QString uavField, int scaleOrderFactor = 0, QPen pen = QPen(Qt::black));
void removeCurvePlot(QString uavObject, QString uavField);
//void removeCurvePlot(QString uavObject, QString uavField);
void clearCurvePlots();