From cec2d6f5e4cefd84ee173f5d0996590989d00382 Mon Sep 17 00:00:00 2001 From: lm Date: Wed, 5 Jan 2011 15:37:57 +0100 Subject: [PATCH] A lot of bugfixing of window positions, plots, buttons, initialization values --- src/comm/MAVLinkSimulationLink.cc | 3 + src/uas/UAS.cc | 2 +- src/ui/DebugConsole.cc | 48 ++++++++++ src/ui/DebugConsole.h | 4 + src/ui/DebugConsole.ui | 19 ++-- src/ui/HDDisplay.cc | 27 ++++-- src/ui/HDDisplay.h | 3 + src/ui/HUD.cc | 31 +++--- src/ui/HUD.h | 5 + src/ui/QGCRemoteControlView.cc | 3 +- src/ui/UASControl.ui | 152 ++++++++++++------------------ src/ui/UASInfo.ui | 10 +- src/ui/linechart/LinechartPlot.cc | 92 +++++++++--------- src/ui/linechart/LinechartPlot.h | 1 + src/ui/uas/UASControlWidget.cc | 6 +- src/ui/uas/UASInfoWidget.cc | 30 ++++-- src/ui/uas/UASInfoWidget.h | 51 +--------- src/ui/uas/UASListWidget.cc | 2 + 18 files changed, 262 insertions(+), 227 deletions(-) diff --git a/src/comm/MAVLinkSimulationLink.cc b/src/comm/MAVLinkSimulationLink.cc index 9dcd0bc92..d697dabd3 100644 --- a/src/comm/MAVLinkSimulationLink.cc +++ b/src/comm/MAVLinkSimulationLink.cc @@ -907,6 +907,7 @@ bool MAVLinkSimulationLink::disconnect() { _isConnected = false; emit disconnected(); + emit connected(false); //exit(); } @@ -923,6 +924,8 @@ bool MAVLinkSimulationLink::disconnect() { bool MAVLinkSimulationLink::connect() { _isConnected = true; + emit connected(); + emit connected(true); start(LowPriority); // timer->start(rate); diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 7fc1a66ae..7330cf7bb 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -318,7 +318,7 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) emit valueChanged(uasId, "pitch V (deg/s)", (attitude.pitchspeed/M_PI)*180.0, time); emit valueChanged(uasId, "yaw V (deg/s)", (attitude.yawspeed/M_PI)*180.0, time); - emit attitudeChanged(this, mavlink_msg_attitude_get_roll(&message), mavlink_msg_attitude_get_pitch(&message), mavlink_msg_attitude_get_yaw(&message), time); + emit attitudeChanged(this, attitude.roll, attitude.pitch, attitude.yaw, time); } break; case MAVLINK_MSG_ID_LOCAL_POSITION: diff --git a/src/ui/DebugConsole.cc b/src/ui/DebugConsole.cc index 36629e67d..6da73bfca 100644 --- a/src/ui/DebugConsole.cc +++ b/src/ui/DebugConsole.cc @@ -35,6 +35,7 @@ This file is part of the QGROUNDCONTROL project #include "LinkManager.h" #include "UASManager.h" #include "protocol.h" +#include "QGC.h" #include @@ -102,6 +103,8 @@ DebugConsole::DebugConsole(QWidget *parent) : connect(m_ui->holdCheckBox, SIGNAL(clicked(bool)), this, SLOT(setAutoHold(bool))); // Connect hold button connect(m_ui->holdButton, SIGNAL(toggled(bool)), this, SLOT(hold(bool))); + // Connect connect button + connect(m_ui->connectButton, SIGNAL(clicked()), this, SLOT(handleConnectButton())); this->setVisible(false); } @@ -122,6 +125,7 @@ void DebugConsole::addLink(LinkInterface* link) m_ui->linkComboBox->insertItem(link->getId(), link->getName()); // Set new item as current m_ui->linkComboBox->setCurrentIndex(qMax(0, links.size() - 1)); + linkSelected(m_ui->linkComboBox->currentIndex()); // Register for name changes connect(link, SIGNAL(nameChanged(QString)), this, SLOT(updateLinkName(QString))); @@ -149,6 +153,7 @@ void DebugConsole::linkSelected(int linkId) if (currLink) { disconnect(currLink, SIGNAL(bytesReceived(LinkInterface*,QByteArray)), this, SLOT(receiveBytes(LinkInterface*, QByteArray))); + disconnect(currLink, SIGNAL(connected(bool)), this, SLOT(setConnectionState(bool))); } // Clear data m_ui->receiveText->clear(); @@ -156,6 +161,8 @@ void DebugConsole::linkSelected(int linkId) // Connect new link currLink = links[linkId]; connect(currLink, SIGNAL(bytesReceived(LinkInterface*,QByteArray)), this, SLOT(receiveBytes(LinkInterface*, QByteArray))); + connect(currLink, SIGNAL(connected(bool)), this, SLOT(setConnectionState(bool))); + setConnectionState(currLink->isConnected()); } /** @@ -422,6 +429,47 @@ void DebugConsole::hold(bool hold) this->holdOn = hold; } +/** + * Sets the connection state the widget shows to this state + */ +void DebugConsole::setConnectionState(bool connected) +{ + if(connected) + { + m_ui->connectButton->setText(tr("Disconn.")); + m_ui->receiveText->appendHtml(QString("%2").arg(QGC::colorGreen.name(), tr("Link %1 is connected.").arg(currLink->getName()))); + } + else + { + m_ui->connectButton->setText(tr("Connect")); + m_ui->receiveText->appendHtml(QString("%2").arg(QGC::colorYellow.name(), tr("Link %1 is unconnected.").arg(currLink->getName()))); + } +} + +/** @brief Handle the connect button */ +void DebugConsole::handleConnectButton() +{ + if (currLink) + { + if (currLink->isConnected()) + { + currLink->disconnect(); + m_ui->connectButton->setText(tr("Connect")); + } + else + { + if (currLink->connect()) + { + m_ui->connectButton->setText(tr("Disconn.")); + } + else + { + m_ui->receiveText->appendHtml(QString("%2").arg(QGC::colorRed.name(), tr("Could not connect link %1 ! Please check link hardware.").arg(currLink->getName()))); + } + } + } +} + void DebugConsole::changeEvent(QEvent *e) { QWidget::changeEvent(e); diff --git a/src/ui/DebugConsole.h b/src/ui/DebugConsole.h index b68fa7c11..e3622eefd 100644 --- a/src/ui/DebugConsole.h +++ b/src/ui/DebugConsole.h @@ -75,6 +75,10 @@ public slots: void MAVLINKfilterEnabled(bool filter); /** @brief Freeze input, do not store new incoming data */ void hold(bool hold); + /** @brief Set connection state of the current link */ + void setConnectionState(bool); + /** @brief Handle the connect button */ + void handleConnectButton(); /** @brief Enable auto-freeze mode if traffic intensity is too high to display */ void setAutoHold(bool hold); /** @brief Receive plain text message to output to the user */ diff --git a/src/ui/DebugConsole.ui b/src/ui/DebugConsole.ui index 833c490be..6a32b3ed3 100644 --- a/src/ui/DebugConsole.ui +++ b/src/ui/DebugConsole.ui @@ -6,14 +6,14 @@ 0 0 - 402 - 185 + 463 + 159 Form - + 6 @@ -51,7 +51,7 @@ Ignore MAVLINK protocol messages in display - No MAVLINK + Hide MAVLINK @@ -77,7 +77,7 @@ Enable auto hold to lower the CPU consumption - Hold + Auto Hold @@ -120,7 +120,7 @@ - + 5 @@ -155,6 +155,13 @@ + + + + Disconn. + + + diff --git a/src/ui/HDDisplay.cc b/src/ui/HDDisplay.cc index a73bbccc4..2d73917fb 100644 --- a/src/ui/HDDisplay.cc +++ b/src/ui/HDDisplay.cc @@ -76,6 +76,11 @@ HDDisplay::HDDisplay(QStringList* plotList, QString title, QWidget *parent) : restoreState(); + // Set minimum size + setMinimumSize(80, 80); + // Set preferred size + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + createActions(); // setBackgroundBrush(QBrush(backgroundColor)); @@ -144,6 +149,11 @@ HDDisplay::~HDDisplay() delete m_ui; } +QSize HDDisplay::sizeHint() const +{ + return QSize(400, 400*(vwidth/vheight)); +} + void HDDisplay::enableGLRendering(bool enable) { Q_UNUSED(enable); @@ -281,6 +291,7 @@ void HDDisplay::addGauge(const QString& gauge) } } } + adjustGaugeAspectRatio(); } void HDDisplay::createActions() @@ -313,6 +324,16 @@ void HDDisplay::setColumns() void HDDisplay::setColumns(int cols) { columns = cols; + adjustGaugeAspectRatio(); +} + +void HDDisplay::adjustGaugeAspectRatio() +{ + // Adjust vheight dynamically according to the number of rows + float vColWidth = vwidth / columns; + int vRows = ceil(acceptList->length()/(float)columns); + // Assuming square instruments, vheight is column width*row count + vheight = vColWidth * vRows; } void HDDisplay::setTitle() @@ -349,12 +370,6 @@ void HDDisplay::renderOverlay() // adjust scaling to fit both horizontally and vertically scalingFactor = this->width()/vwidth; - // Adjust vheight dynamically according to the number of rows - float vColWidth = vwidth / columns; - int vRows = ceil(acceptList->length()/(float)columns); - // Assuming square instruments, vheight is column width*row count - vheight = vColWidth * vRows; - double scalingFactorH = this->height()/vheight; if (scalingFactorH < scalingFactor) scalingFactor = scalingFactorH; diff --git a/src/ui/HDDisplay.h b/src/ui/HDDisplay.h index 0ddb8a354..02de21d0f 100644 --- a/src/ui/HDDisplay.h +++ b/src/ui/HDDisplay.h @@ -89,8 +89,11 @@ protected slots: //void render(QPainter* painter, const QRectF& target = QRectF(), const QRect& source = QRect(), Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio); void renderOverlay(); void triggerUpdate(); + /** @brief Adjust the size hint for the current gauge layout */ + void adjustGaugeAspectRatio(); protected: + QSize sizeHint() const; void changeEvent(QEvent* e); void paintEvent(QPaintEvent* event); void showEvent(QShowEvent* event); diff --git a/src/ui/HUD.cc b/src/ui/HUD.cc index 662df6355..f3e234c3e 100644 --- a/src/ui/HUD.cc +++ b/src/ui/HUD.cc @@ -112,13 +112,18 @@ HUD::HUD(int width, int height, QWidget* parent) strongStrokeWidth(1.5f), normalStrokeWidth(1.0f), fineStrokeWidth(0.5f), - waypointName("") + waypointName(""), + roll(0.0f), + pitch(0.0f), + yaw(0.0f) { // Set auto fill to false setAutoFillBackground(false); // Set minimum size setMinimumSize(80, 60); + // Set preferred size + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // Fill with black background QImage fill = QImage(width, height, QImage::Format_Indexed8); @@ -170,8 +175,6 @@ HUD::HUD(int width, int height, QWidget* parent) // Connect with UAS UASManager* manager = UASManager::instance(); connect(manager, SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); - - this->setVisible(false); } HUD::~HUD() @@ -179,6 +182,11 @@ HUD::~HUD() } +QSize HUD::sizeHint() const +{ + return QSize(800, 600); +} + void HUD::showEvent(QShowEvent* event) { // React only to internal (pre-display) @@ -240,16 +248,9 @@ void HUD::setActiveUAS(UASInterface* uas) // Disconnect any previously connected active MAV disconnect(uas, SIGNAL(attitudeChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateAttitude(UASInterface*, double, double, double, quint64))); disconnect(uas, SIGNAL(batteryChanged(UASInterface*, double, double, int)), this, SLOT(updateBattery(UASInterface*, double, double, int))); - disconnect(uas, SIGNAL(heartbeat(UASInterface*)), this, SLOT(receiveHeartbeat(UASInterface*))); - disconnect(uas, SIGNAL(thrustChanged(UASInterface*, double)), this, SLOT(updateThrust(UASInterface*, double))); - disconnect(uas, SIGNAL(localPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateLocalPosition(UASInterface*,double,double,double,quint64))); - disconnect(uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateGlobalPosition(UASInterface*,double,double,double,quint64))); - disconnect(uas, SIGNAL(speedChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateSpeed(UASInterface*,double,double,double,quint64))); disconnect(uas, SIGNAL(statusChanged(UASInterface*,QString,QString)), this, SLOT(updateState(UASInterface*,QString))); disconnect(uas, SIGNAL(modeChanged(int,QString,QString)), this, SLOT(updateMode(int,QString,QString))); - disconnect(uas, SIGNAL(loadChanged(UASInterface*, double)), this, SLOT(updateLoad(UASInterface*, double))); - disconnect(uas, SIGNAL(attitudeThrustSetPointChanged(UASInterface*,double,double,double,double,quint64)), this, SLOT(updateAttitudeThrustSetPoint(UASInterface*,double,double,double,double,quint64))); - disconnect(uas, SIGNAL(valueChanged(UASInterface*,QString,double,quint64)), this, SLOT(updateValue(UASInterface*,QString,double,quint64))); + disconnect(uas, SIGNAL(heartbeat(UASInterface*)), this, SLOT(receiveHeartbeat(UASInterface*))); } // Now connect the new UAS @@ -284,7 +285,7 @@ void HUD::updateAttitudeThrustSetPoint(UASInterface*, double rollDesired, double void HUD::updateAttitude(UASInterface* uas, double roll, double pitch, double yaw, quint64 timestamp) { - //qDebug() << __FILE__ << __LINE__ << "ROLL" << roll; + qDebug() << __FILE__ << __LINE__ << "ROLL" << yaw; updateValue(uas, "roll", roll, timestamp); updateValue(uas, "pitch", pitch, timestamp); updateValue(uas, "yaw", yaw, timestamp); @@ -573,10 +574,6 @@ void HUD::paintHUD() #endif // Read out most important values to limit hash table lookups - static float roll = 0.0f; - static float pitch = 0.0f; - static float yaw = 0.0f; - // Low-pass roll, pitch and yaw roll = roll * 0.2f + 0.8f * values.value("roll", 0.0f); pitch = pitch * 0.2f + 0.8f * values.value("pitch", 0.0f); @@ -725,7 +722,7 @@ void HUD::paintHUD() QString yawAngle; const float yawDeg = ((values.value("yaw", 0.0f)/M_PI)*180.0f)+180.f; - //qDebug() << "YAW: " << yawDeg; + qDebug() << "YAW: " << yawDeg; yawAngle.sprintf("%03d", (int)yawDeg); paintText(yawAngle, defaultColor, 3.5f, -3.7f, compassY+ 0.9f, &painter); diff --git a/src/ui/HUD.h b/src/ui/HUD.h index f5f4695f2..70e5572f2 100644 --- a/src/ui/HUD.h +++ b/src/ui/HUD.h @@ -118,6 +118,8 @@ protected: float refLineWidthToPen(float line); /** @brief Rotate a polygon around a point clockwise */ void rotatePolygonClockWiseRad(QPolygonF& p, float angle, QPointF origin); + /** @brief Preferred Size */ + QSize sizeHint() const; /** @brief Start updating widget */ void showEvent(QShowEvent* event); /** @brief Stop updating widget */ @@ -183,6 +185,9 @@ protected: float fineStrokeWidth; ///< Fine line stroke width, used throughout the HUD QString waypointName; ///< Waypoint name displayed in HUD + float roll; + float pitch; + float yaw; void paintEvent(QPaintEvent *event); }; diff --git a/src/ui/QGCRemoteControlView.cc b/src/ui/QGCRemoteControlView.cc index 106992fae..a00c83ff5 100644 --- a/src/ui/QGCRemoteControlView.cc +++ b/src/ui/QGCRemoteControlView.cc @@ -176,6 +176,7 @@ void QGCRemoteControlView::appendChannelWidget(int channelId) // Add content layout->addWidget(new QLabel(QString("Channel %1").arg(channelId + 1), this)); QLabel* raw = new QLabel(this); + // Append raw label rawLabels.append(raw); layout->addWidget(raw); @@ -196,7 +197,7 @@ void QGCRemoteControlView::redraw() // Update raw values for(int i = 0; i < rawLabels.count(); i++) { - rawLabels.at(i)->setText(QString("%1 us").arg(raw.at(i))); + rawLabels.at(i)->setText(QString("%1 us").arg(raw.at(i), 4)); } // Update percent bars diff --git a/src/ui/UASControl.ui b/src/ui/UASControl.ui index 99f720ddc..1dfe7861b 100644 --- a/src/ui/UASControl.ui +++ b/src/ui/UASControl.ui @@ -6,10 +6,16 @@ 0 0 - 328 - 357 + 210 + 141 + + + 0 + 0 + + 210 @@ -19,19 +25,26 @@ Form - - - 0 - - - 6 - + + + + + Qt::Horizontal + + + + 31 + 159 + + + + - 50 - 20 + 0 + 0 @@ -45,6 +58,19 @@ + + + + Qt::Horizontal + + + + 30 + 159 + + + + @@ -58,40 +84,11 @@ - - - - Qt::Vertical - - - QSizePolicy::MinimumExpanding - - - - 20 - 2 - - - - - - - - Qt::Horizontal - - - - 31 - 159 - - - - - + - 60 + 40 12 @@ -104,11 +101,11 @@ - + - 60 + 40 12 @@ -121,11 +118,11 @@ - + - 60 + 40 12 @@ -138,20 +135,7 @@ - - - - Qt::Horizontal - - - - 30 - 159 - - - - - + @@ -161,7 +145,7 @@ - + @@ -178,52 +162,36 @@ - - + + - 0 - 12 + 40 + 16 - No actions executed so far + Set Origin - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + :/images/actions/go-home.svg:/images/actions/go-home.svg - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 0 - 1 - - - - - - + + - 60 - 16 + 0 + 12 - Set Origin + No actions executed so far - - - :/images/actions/go-home.svg:/images/actions/go-home.svg + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop diff --git a/src/ui/UASInfo.ui b/src/ui/UASInfo.ui index 79c468415..ee130441b 100644 --- a/src/ui/UASInfo.ui +++ b/src/ui/UASInfo.ui @@ -6,8 +6,8 @@ 0 0 - 223 - 138 + 230 + 161 @@ -105,7 +105,7 @@ 100 - 80 + 0 true @@ -363,7 +363,7 @@ - 24 + 0 true @@ -442,7 +442,7 @@ - 24 + 0 diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index 9532b1ce9..2147e5542 100644 --- a/src/ui/linechart/LinechartPlot.cc +++ b/src/ui/linechart/LinechartPlot.cc @@ -1,5 +1,4 @@ /*===================================================================== - PIXHAWK Micro Air Vehicle Flying Robotics Toolkit (c) 2009, 2010 PIXHAWK PROJECT @@ -10,15 +9,15 @@ This file is part of the PIXHAWK project it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + PIXHAWK is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with PIXHAWK. If not, see . - + ======================================================================*/ /** @@ -64,23 +63,23 @@ d_curve(NULL) { this->plotid = plotid; this->plotInterval = interval; - + maxValue = DBL_MIN; minValue = DBL_MAX; - + //lastMaxTimeAdded = QTime(); - + curves = QMap(); data = QMap(); scaleMaps = QMap(); - + yScaleEngine = new QwtLinearScaleEngine(); setAxisScaleEngine(QwtPlot::yLeft, yScaleEngine); - + /* Create color map */ colors = QList(); nextColor = 0; - + ///> Color map for plots, includes 20 colors ///> Map will start from beginning when the first 20 colors are exceeded colors.append(QColor(242,255,128)); @@ -103,11 +102,11 @@ d_curve(NULL) colors.append(QColor(161,252,116)); colors.append(QColor(87,231,246)); colors.append(QColor(230,126,23)); - + plotPosition = 0; - + setAutoReplot(false); - + // Set grid QwtPlotGrid *grid = new QwtPlotGrid; grid->setMinPen(QPen(Qt::darkGray, 0, Qt::DotLine)); @@ -115,39 +114,39 @@ d_curve(NULL) grid->enableXMin(true); // TODO xmin? grid->attach(this); - + // Set left scale //setAxisOptions(QwtPlot::yLeft, QwtAutoScale::Logarithmic); - + // Set bottom scale setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw()); setAxisLabelRotation(QwtPlot::xBottom, -25.0); setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom); - + // Add some space on the left and right side of the scale to prevent flickering - + QwtScaleWidget* bottomScaleWidget = axisWidget(QwtPlot::xBottom); const int fontMetricsX = QFontMetrics(bottomScaleWidget->font()).height(); bottomScaleWidget->setMinBorderDist(fontMetricsX * 2, fontMetricsX / 2); - + plotLayout()->setAlignCanvasToScales(true); - + // Set canvas background setCanvasBackground(QColor(40, 40, 40)); - + // Enable zooming //zoomer = new Zoomer(canvas()); zoomer = new ScrollZoomer(canvas()); zoomer->setRubberBandPen(QPen(Qt::blue, 1.2, Qt::DotLine)); zoomer->setTrackerPen(QPen(Qt::blue)); - + // Start QTimer for plot update updateTimer = new QTimer(this); connect(updateTimer, SIGNAL(timeout()), this, SLOT(paintRealtime())); //updateTimer->start(DEFAULT_REFRESH_RATE); - + // QwtPlot::setAutoReplot(); - + // canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); // canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); } @@ -246,31 +245,39 @@ void LinechartPlot::appendData(QString dataname, quint64 ms, double value) { /* Lock resource to ensure data integrity */ datalock.lock(); - + /* Check if dataset identifier already exists */ if(!data.contains(dataname)) { addCurve(dataname); } - + // Add new value TimeSeriesData* dataset = data.value(dataname); - + + quint64 time; + // Append data if (m_groundTime) { // Use the current (receive) time - dataset->append(MG::TIME::getGroundTimeNow(), value); + //dataset->append(MG::TIME::getGroundTimeNow(), value); + time = QGC::groundTimeUsecs()/1000; + //qDebug() << "QGC:" << QGC::groundTimeUsecs()/1000; } else { // Use timestamp from dataset - dataset->append(ms, value); + time = ms; + //qDebug() << "MS:" << ms; + //qDebug() << "QGC:" << QGC::groundTimeUsecs()/1000; } + dataset->append(time, value); // Scaling values if(ms < minTime) minTime = ms; if(ms > maxTime) maxTime = ms; storageInterval = maxTime - minTime; + lastTime = time; // if (value < minValue) minValue = value; @@ -628,7 +635,9 @@ void LinechartPlot::paintRealtime() if (m_active) { #if (QGC_EVENTLOOP_DEBUG) - qDebug() << "EVENTLOOP:" << __FILE__ << __LINE__; + static quint64 timestamp = 0; + qDebug() << "EVENTLOOP: (" << MG::TIME::getGroundTimeNow() - timestamp << ")" << __FILE__ << __LINE__; + timestamp = MG::TIME::getGroundTimeNow(); #endif // Update plot window value to new max time if the last time was also the max time windowLock.lock(); @@ -637,14 +646,14 @@ void LinechartPlot::paintRealtime() // FIXME Check, but commenting this out should have been // beneficial (does only add complexity) -// if (MG::TIME::getGroundTimeNow() > maxTime && abs(MG::TIME::getGroundTimeNow() - maxTime) < 5000000) -// { -// plotPosition = MG::TIME::getGroundTimeNow(); -// } -// else -// { - plotPosition = maxTime;// + lastMaxTimeAdded.msec(); -// } + // if (MG::TIME::getGroundTimeNow() > maxTime && abs(MG::TIME::getGroundTimeNow() - maxTime) < 5000000) + // { + // plotPosition = MG::TIME::getGroundTimeNow(); + // } + // else + // { + plotPosition = lastTime;// + lastMaxTimeAdded.msec(); + // } setAxisScale(QwtPlot::xBottom, plotPosition - plotInterval, plotPosition, timeScaleStep); // FIXME Last fix for scroll zoomer is here @@ -702,12 +711,7 @@ void LinechartPlot::paintRealtime() canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode); }*/ -// static quint64 timestamp = 0; -// -// -// qDebug() << "PLOT INTERVAL:" << MG::TIME::getGroundTimeNow() - timestamp; -// -// timestamp = MG::TIME::getGroundTimeNow(); + } } @@ -815,7 +819,7 @@ void TimeSeriesData::append(quint64 ms, double value) this->variance = 0; for (unsigned int i = 0; (i < averageWindow) && (((int)count - (int)i) >= 0); ++i) { - this->variance += (this->value[count-i] - mean) * (this->value[count-i] - mean); + this->variance += (this->value[count-i] - mean) * (this->value[count-i] - mean); } this->variance = this->variance / static_cast(qMin(averageWindow,static_cast(count))); diff --git a/src/ui/linechart/LinechartPlot.h b/src/ui/linechart/LinechartPlot.h index a18013521..b693a3349 100644 --- a/src/ui/linechart/LinechartPlot.h +++ b/src/ui/linechart/LinechartPlot.h @@ -284,6 +284,7 @@ protected: // TODO CHECK THIS!!! int scaling; QwtScaleEngine* yScaleEngine; + quint64 lastTime; ///< Last added timestamp quint64 minTime; ///< The smallest timestamp occured so far quint64 maxTime; ///< The biggest timestamp occured so far quint64 maxInterval; diff --git a/src/ui/uas/UASControlWidget.cc b/src/ui/uas/UASControlWidget.cc index a007e7c96..88dd3dd75 100644 --- a/src/ui/uas/UASControlWidget.cc +++ b/src/ui/uas/UASControlWidget.cc @@ -117,15 +117,15 @@ void UASControlWidget::setUAS(UASInterface* uas) { QPushButton* startRecButton = new QPushButton(tr("Record")); connect(startRecButton, SIGNAL(clicked()), mav, SLOT(startDataRecording())); - ui.gridLayout->addWidget(startRecButton, 10, 1); + ui.gridLayout->addWidget(startRecButton, 10, 0, 0, 2); QPushButton* pauseRecButton = new QPushButton(tr("Pause")); connect(pauseRecButton, SIGNAL(clicked()), mav, SLOT(pauseDataRecording())); - ui.gridLayout->addWidget(pauseRecButton, 10, 2); + ui.gridLayout->addWidget(pauseRecButton, 10, 2, 0, 2); QPushButton* stopRecButton = new QPushButton(tr("Stop")); connect(stopRecButton, SIGNAL(clicked()), mav, SLOT(stopDataRecording())); - ui.gridLayout->addWidget(stopRecButton, 10, 3); + ui.gridLayout->addWidget(stopRecButton, 10, 4, 0, 2); } diff --git a/src/ui/uas/UASInfoWidget.cc b/src/ui/uas/UASInfoWidget.cc index 08f176cd4..fa9df58f3 100644 --- a/src/ui/uas/UASInfoWidget.cc +++ b/src/ui/uas/UASInfoWidget.cc @@ -29,6 +29,8 @@ This file is part of the PIXHAWK project * */ +#include + #include #include #include @@ -69,14 +71,14 @@ UASInfoWidget::UASInfoWidget(QWidget *parent, QString name) : QWidget(parent) this->load = 0; receiveLoss = 0; sendLoss = 0; + changed = true; errors = QMap(); updateTimer = new QTimer(this); connect(updateTimer, SIGNAL(timeout()), this, SLOT(refresh())); - updateTimer->start(50); + updateTimer->start(updateInterval); this->setVisible(false); - } UASInfoWidget::~UASInfoWidget() @@ -84,6 +86,22 @@ UASInfoWidget::~UASInfoWidget() } +void UASInfoWidget::showEvent(QShowEvent* event) +{ + // React only to internal (pre-display) + // events + Q_UNUSED(event); + updateTimer->start(updateInterval); +} + +void UASInfoWidget::hideEvent(QHideEvent* event) +{ + // React only to internal (pre-display) + // events + Q_UNUSED(event); + updateTimer->stop(); +} + void UASInfoWidget::addUAS(UASInterface* uas) { if (uas != NULL) @@ -172,13 +190,13 @@ void UASInfoWidget::setTimeRemaining(UASInterface* uas, double seconds) void UASInfoWidget::refresh() { ui.voltageLabel->setText(QString::number(this->voltage, 'f', voltageDecimals)); - ui.batteryBar->setValue(static_cast(this->chargeLevel)); + ui.batteryBar->setValue(qMax(0,qMin(static_cast(this->chargeLevel), 100))); ui.loadLabel->setText(QString::number(this->load, 'f', loadDecimals)); - ui.loadBar->setValue(static_cast(this->load)); + ui.loadBar->setValue(qMax(0, qMin(static_cast(this->load), 100))); - ui.receiveLossBar->setValue(receiveLoss); - ui.receiveLossLabel->setText(QString::number(receiveLoss,'f', 2)); + ui.receiveLossBar->setValue(qMax(0, qMin(static_cast(receiveLoss), 100))); + ui.receiveLossLabel->setText(QString::number(receiveLoss, 'f', 2)); ui.sendLossBar->setValue(sendLoss); ui.sendLossLabel->setText(QString::number(sendLoss, 'f', 2)); diff --git a/src/ui/uas/UASInfoWidget.h b/src/ui/uas/UASInfoWidget.h index 89d52a96b..709a0a78b 100644 --- a/src/ui/uas/UASInfoWidget.h +++ b/src/ui/uas/UASInfoWidget.h @@ -89,56 +89,15 @@ protected: double load; float receiveLoss; float sendLoss; + bool changed; QTimer* updateTimer; QString name; quint64 startTime; QMap errors; -// double lastRemainingTime; -// double lastChargeLevel; -// double startVoltage; -// double fullVoltage; -// double emptyVoltage; -// double currentVoltage; - // Battery Type -// BatteryType batteryType; - // Number of cells -// int cells; - - /* - QMap* instruments; - - class Instrument - { - public: - void setMin(double min) - { - this->min = min; - } - - void setMax(double max) - { - this->max = max; - } - - void setValue(double value) - { - this->value = value; - } - - void refresh() - { - bar.setValue(value); - } - - - protected: - double min; - double max; - double value; - QString unit; - QLabel label; - QProgressBar bar - };*/ + static const int updateInterval = 200; ///< Refresh interval in milliseconds + + void showEvent(QShowEvent* event); + void hideEvent(QHideEvent* event); private: Ui::uasInfo ui; diff --git a/src/ui/uas/UASListWidget.cc b/src/ui/uas/UASListWidget.cc index 1d6bd7814..498c3ff0f 100644 --- a/src/ui/uas/UASListWidget.cc +++ b/src/ui/uas/UASListWidget.cc @@ -81,6 +81,8 @@ void UASListWidget::changeEvent(QEvent *e) } } + + void UASListWidget::addUAS(UASInterface* uas) { if (uasViews.isEmpty()) -- 2.22.0