Commit cec2d6f5 authored by lm's avatar lm

A lot of bugfixing of window positions, plots, buttons, initialization values

parent a33541b9
......@@ -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);
......
......@@ -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:
......
......@@ -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 <QDebug>
......@@ -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("<font color=\"%1\">%2</font>").arg(QGC::colorGreen.name(), tr("Link %1 is connected.").arg(currLink->getName())));
}
else
{
m_ui->connectButton->setText(tr("Connect"));
m_ui->receiveText->appendHtml(QString("<font color=\"%1\">%2</font>").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("<font color=\"%1\">%2</font>").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);
......
......@@ -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 */
......
......@@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>402</width>
<height>185</height>
<width>463</width>
<height>159</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0">
<property name="horizontalSpacing">
<number>6</number>
</property>
......@@ -51,7 +51,7 @@
<string>Ignore MAVLINK protocol messages in display</string>
</property>
<property name="text">
<string>No MAVLINK</string>
<string>Hide MAVLINK</string>
</property>
</widget>
</item>
......@@ -77,7 +77,7 @@
<string>Enable auto hold to lower the CPU consumption</string>
</property>
<property name="text">
<string>Hold</string>
<string>Auto Hold</string>
</property>
</widget>
</item>
......@@ -120,7 +120,7 @@
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="10,10,10">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="10,10,10,0">
<property name="spacing">
<number>5</number>
</property>
......@@ -155,6 +155,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="connectButton">
<property name="text">
<string>Disconn.</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
};
......
......@@ -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
......
......@@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>328</width>
<height>357</height>
<width>210</width>
<height>141</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>210</width>
......@@ -19,19 +25,26 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowstretch="10,10,0,10,10,10,10,100" columnstretch="0,10,5,5,10,0">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,100,50,50,100,0">
<item row="0" column="0" rowspan="6">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>31</width>
<height>159</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1" colspan="4">
<widget class="QLabel" name="controlStatusLabel">
<property name="minimumSize">
<size>
<width>50</width>
<height>20</height>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
......@@ -45,6 +58,19 @@
</property>
</widget>
</item>
<item row="0" column="5" rowspan="6">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>159</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1" colspan="4">
<widget class="QPushButton" name="controlButton">
<property name="minimumSize">
......@@ -58,40 +84,11 @@
</property>
</widget>
</item>
<item row="2" column="1" colspan="4">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>2</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" rowspan="7">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>31</width>
<height>159</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<item row="2" column="1">
<widget class="QPushButton" name="liftoffButton">
<property name="minimumSize">
<size>
<width>60</width>
<width>40</width>
<height>12</height>
</size>
</property>
......@@ -104,11 +101,11 @@
</property>
</widget>
</item>
<item row="3" column="2" colspan="2">
<item row="2" column="2" colspan="2">
<widget class="QPushButton" name="landButton">
<property name="minimumSize">
<size>
<width>60</width>
<width>40</width>
<height>12</height>
</size>
</property>
......@@ -121,11 +118,11 @@
</property>
</widget>
</item>
<item row="3" column="4">
<item row="2" column="4">
<widget class="QPushButton" name="shutdownButton">
<property name="minimumSize">
<size>
<width>60</width>
<width>40</width>
<height>12</height>
</size>
</property>
......@@ -138,20 +135,7 @@
</property>
</widget>
</item>
<item row="0" column="5" rowspan="7">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>159</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1" colspan="2">
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="modeComboBox">
<property name="minimumSize">
<size>
......@@ -161,7 +145,7 @@
</property>
</widget>
</item>
<item row="4" column="3" colspan="2">
<item row="3" column="3" colspan="2">
<widget class="QPushButton" name="setModeButton">
<property name="minimumSize">
<size>
......@@ -178,52 +162,36 @@
</property>
</widget>
</item>
<item row="6" column="1" colspan="4">
<widget class="QLabel" name="lastActionLabel">
<item row="4" column="3" colspan="2">
<widget class="QPushButton" name="setHomeButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>12</height>
<width>40</width>
<height>16</height>
</size>
</property>
<property name="text">
<string>No actions executed so far</string>
<string>Set Origin</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
<property name="icon">
<iconset resource="../../mavground.qrc">
<normaloff>:/images/actions/go-home.svg</normaloff>:/images/actions/go-home.svg</iconset>
</property>
</widget>
</item>
<item row="7" column="0" colspan="6">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="1" colspan="2">
<widget class="QPushButton" name="setHomeButton">
<item row="5" column="1" colspan="4">
<widget class="QLabel" name="lastActionLabel">
<property name="minimumSize">
<size>
<width>60</width>
<height>16</height>
<width>0</width>
<height>12</height>
</size>
</property>
<property name="text">
<string>Set Origin</string>
<string>No actions executed so far</string>
</property>
<property name="icon">
<iconset resource="../../mavground.qrc">
<normaloff>:/images/actions/go-home.svg</normaloff>:/images/actions/go-home.svg</iconset>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>223</width>
<height>138</height>
<width>230</width>
<height>161</height>
</rect>
</property>
<property name="windowTitle">
......@@ -105,7 +105,7 @@
<number>100</number>
</property>
<property name="value">
<number>80</number>
<number>0</number>
</property>
<property name="textVisible">
<bool>true</bool>
......@@ -363,7 +363,7 @@
</size>
</property>
<property name="value">
<number>24</number>
<number>0</number>
</property>
<property name="textVisible">
<bool>true</bool>
......@@ -442,7 +442,7 @@
</size>
</property>
<property name="value">
<number>24</number>
<number>0</number>
</property>
</widget>
</item>
......
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
......@@ -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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
......@@ -64,23 +63,23 @@ d_curve(NULL)
{
this->plotid = plotid;
this->plotInterval = interval;
maxValue = DBL_MIN;
minValue = DBL_MAX;
//lastMaxTimeAdded = QTime();
curves = QMap<QString, QwtPlotCurve*>();
data = QMap<QString, TimeSeriesData*>();
scaleMaps = QMap<QString, QwtScaleMap*>();
yScaleEngine = new QwtLinearScaleEngine();
setAxisScaleEngine(QwtPlot::yLeft, yScaleEngine);
/* Create color map */
colors = QList<QColor>();
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<double>(qMin(averageWindow,static_cast<unsigned int>(count)));
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -29,6 +29,8 @@ This file is part of the PIXHAWK project
*
*/
#include <QtGlobal>
#include <float.h>
#include <UASInfoWidget.h>
#include <UASManager.h>
......@@ -69,14 +71,14 @@ UASInfoWidget::UASInfoWidget(QWidget *parent, QString name) : QWidget(parent)
this->load = 0;
receiveLoss = 0;
sendLoss = 0;
changed = true;
errors = QMap<QString, int>();
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<int>(this->chargeLevel));
ui.batteryBar->setValue(qMax(0,qMin(static_cast<int>(this->chargeLevel), 100)));
ui.loadLabel->setText(QString::number(this->load, 'f', loadDecimals));
ui.loadBar->setValue(static_cast<int>(this->load));
ui.loadBar->setValue(qMax(0, qMin(static_cast<int>(this->load), 100)));
ui.receiveLossBar->setValue(receiveLoss);
ui.receiveLossLabel->setText(QString::number(receiveLoss,'f', 2));
ui.receiveLossBar->setValue(qMax(0, qMin(static_cast<int>(receiveLoss), 100)));
ui.receiveLossLabel->setText(QString::number(receiveLoss, 'f', 2));
ui.sendLossBar->setValue(sendLoss);
ui.sendLossLabel->setText(QString::number(sendLoss, 'f', 2));
......
......@@ -89,56 +89,15 @@ protected:
double load;
float receiveLoss;
float sendLoss;
bool changed;
QTimer* updateTimer;
QString name;
quint64 startTime;
QMap<QString, int> errors;
// double lastRemainingTime;
// double lastChargeLevel;
// double startVoltage;
// double fullVoltage;
// double emptyVoltage;
// double currentVoltage;
// Battery Type
// BatteryType batteryType;
// Number of cells
// int cells;
/*
QMap<QString, QProgressBar*>* 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;
......
......@@ -81,6 +81,8 @@ void UASListWidget::changeEvent(QEvent *e)
}
}
void UASListWidget::addUAS(UASInterface* uas)
{
if (uasViews.isEmpty())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment