From 8c83e87bdffc84c524cfd4162f81f5fcc7f25add Mon Sep 17 00:00:00 2001 From: pixhawk Date: Sun, 13 Jun 2010 19:10:50 +0200 Subject: [PATCH] Implemented setpoint changes for HSI widget --- images/style-mission.css | 8 +- qgroundcontrol.pro | 21 +- src/QGC.h | 11 ++ src/ui/DebugConsole.ui | 329 ++++++++++++++++---------------- src/ui/HDDisplay.cc | 10 + src/ui/HDDisplay.h | 2 + src/ui/HSIDisplay.cc | 272 +++++++++++++++++++------- src/ui/HSIDisplay.h | 52 ++++- src/ui/MainWindow.cc | 9 +- src/ui/UASControl.ui | 111 ++++++----- src/ui/UASInfo.ui | 18 +- src/ui/UASList.ui | 6 + src/ui/UASView.ui | 33 +--- src/ui/XMLCommProtocolWidget.cc | 22 ++- 14 files changed, 562 insertions(+), 342 deletions(-) create mode 100644 src/QGC.h diff --git a/images/style-mission.css b/images/style-mission.css index 849285979..8a201d100 100644 --- a/images/style-mission.css +++ b/images/style-mission.css @@ -107,7 +107,7 @@ QSpinBox { QPushButton { font-weight: bold; min-height: 18px; - max-height: 32px; + max-height: 18px; border: 2px solid #4A4A4F; border-radius: 5px; padding-left: 10px; @@ -127,10 +127,10 @@ QToolButton { font-weight: bold; min-height: 16px; min-width: 24px; - max-height: 32px; - border: 1px solid #EEEEEE; + max-height: 18px; + border: 2px solid #4A4A4F; border-radius: 5px; - background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #303030, stop: 1 #202020); + background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #232228, stop: 1 #020208); } QToolButton:checked { diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index a2b9126e6..7db59f38b 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -3,23 +3,23 @@ # from http://github.com/pixhawk/qmapcontrol/ # over bundled version in lib directory # Version from GIT repository is preferred -#include ( "../qmapcontrol/QMapControl/QMapControl.pri" ) #{ +# include ( "../qmapcontrol/QMapControl/QMapControl.pri" ) #{ # Include bundled version if necessary include(lib/QMapControl/QMapControl.pri) -#message("Including bundled QMapControl version as FALLBACK. This is fine on Linux and MacOS, but not the best choice in Windows") - - -QT += network opengl svg xml phonon +# message("Including bundled QMapControl version as FALLBACK. This is fine on Linux and MacOS, but not the best choice in Windows") +QT += network \ + opengl \ + svg \ + xml \ + phonon TEMPLATE = app TARGET = qgroundcontrol - BASEDIR = . BUILDDIR = build LANGUAGE = C++ - -CONFIG += debug_and_release console - +CONFIG += debug_and_release \ + console OBJECTS_DIR = $$BUILDDIR/obj MOC_DIR = $$BUILDDIR/moc UI_HEADERS_DIR = src/ui/generated @@ -142,7 +142,8 @@ HEADERS += src/MG.h \ src/ui/watchdog/WatchdogProcessView.h \ src/ui/watchdog/WatchdogView.h \ src/uas/UASWaypointManager.h \ - src/ui/HSIDisplay.h + src/ui/HSIDisplay.h \ + src/QGC.h SOURCES += src/main.cc \ src/Core.cc \ src/uas/UASManager.cc \ diff --git a/src/QGC.h b/src/QGC.h new file mode 100644 index 000000000..c2e813ab0 --- /dev/null +++ b/src/QGC.h @@ -0,0 +1,11 @@ +#ifndef QGC_H +#define QGC_H + +#include + +namespace QGC +{ + const QColor ColorCyan(55, 154, 195); +} + +#endif // QGC_H diff --git a/src/ui/DebugConsole.ui b/src/ui/DebugConsole.ui index 8f2371a2d..191cb1092 100644 --- a/src/ui/DebugConsole.ui +++ b/src/ui/DebugConsole.ui @@ -1,165 +1,164 @@ - - - DebugConsole - - - - 0 - 0 - 488 - 390 - - - - Form - - - - 6 - - - 4 - - - 6 - - - - - - - Link - - - - - - - Select the link to monitor - - - - - - - 0.0 kB/s - - - - - - - Ignore MAVLINK protocol messages in display - - - Ignore MAVLINK - - - - - - - Display and send bytes in HEX representation - - - HEX - - - - - - - Saves CPU ressources, automatically set view to hold if data rate is too high to prevent fast scrolling - - - Saves CPU ressources, automatically set view to hold if data rate is too high to prevent fast scrolling - - - Enable auto hold to lower the CPU consumption - - - Auto hold - - - - - - - - - - - - Enter data/text below to send - - - true - - - - - - - Type the bytes to send here, use 0xAA format for HEX (Check HEX checkbox above) - - - - - - - - - Send the ASCII text or HEX values over the link - - - Send - - - - :/images/devices/network-wireless.svg:/images/devices/network-wireless.svg - - - - - - - Hold - - - true - - - - - - - Clear - - - - - - - - - - - - - clearButton - clicked() - receiveText - clear() - - - 356 - 278 - - - 199 - 146 - - - - - + + + DebugConsole + + + + 0 + 0 + 435 + 185 + + + + Form + + + + 6 + + + 4 + + + 6 + + + + + + + + 130 + 16777215 + + + + Select the link to monitor + + + + + + + 0.0 kB/s + + + + + + + Ignore MAVLINK protocol messages in display + + + No MAVLINK + + + + + + + Display and send bytes in HEX representation + + + HEX + + + + + + + Saves CPU ressources, automatically set view to hold if data rate is too high to prevent fast scrolling + + + Saves CPU ressources, automatically set view to hold if data rate is too high to prevent fast scrolling + + + Enable auto hold to lower the CPU consumption + + + Auto hold + + + + + + + + + + + + Enter data/text below to send + + + true + + + + + + + Type the bytes to send here, use 0xAA format for HEX (Check HEX checkbox above) + + + + + + + + + Send the ASCII text or HEX values over the link + + + Send + + + + :/images/devices/network-wireless.svg:/images/devices/network-wireless.svg + + + + + + + Hold + + + true + + + + + + + Clear + + + + + + + + + + + + + clearButton + clicked() + receiveText + clear() + + + 356 + 278 + + + 199 + 146 + + + + + diff --git a/src/ui/HDDisplay.cc b/src/ui/HDDisplay.cc index 454e5bdbe..b866ca6f1 100644 --- a/src/ui/HDDisplay.cc +++ b/src/ui/HDDisplay.cc @@ -581,6 +581,16 @@ float HDDisplay::refToScreenY(float y) return (scalingFactor * y); } +float HDDisplay::screenToRefX(float x) +{ + return x/scalingFactor; +} + +float HDDisplay::screenToRefY(float y) +{ + return y/scalingFactor; +} + void HDDisplay::drawLine(float refX1, float refY1, float refX2, float refY2, float width, const QColor& color, QPainter* painter) { QPen pen(Qt::SolidLine); diff --git a/src/ui/HDDisplay.h b/src/ui/HDDisplay.h index 67c11c7ad..4b34a7e8a 100644 --- a/src/ui/HDDisplay.h +++ b/src/ui/HDDisplay.h @@ -70,6 +70,8 @@ protected: float refLineWidthToPen(float line); float refToScreenX(float x); float refToScreenY(float y); + float screenToRefX(float x); + float screenToRefY(float y); void rotatePolygonClockWiseRad(QPolygonF& p, float angle, QPointF origin); void drawPolygon(QPolygonF refPolygon, QPainter* painter); void drawLine(float refX1, float refY1, float refX2, float refY2, float width, const QColor& color, QPainter* painter); diff --git a/src/ui/HSIDisplay.cc b/src/ui/HSIDisplay.cc index 4452cf25d..37a686530 100644 --- a/src/ui/HSIDisplay.cc +++ b/src/ui/HSIDisplay.cc @@ -35,6 +35,7 @@ This file is part of the PIXHAWK project #include "UASManager.h" #include "HSIDisplay.h" #include "MG.h" +#include "QGC.h" #include @@ -62,11 +63,31 @@ HSIDisplay::HSIDisplay(QWidget *parent) : x(0), y(0), z(0), - //yaw(0), - localAvailable(0) + vx(0), + vy(0), + vz(0), + speed(0), + localAvailable(0), + roll(0), + pitch(0), + yaw(0.0f), + bodyXSetCoordinate(0.0f), + bodyYSetCoordinate(0.0f), + bodyZSetCoordinate(0.0f), + bodyYawSet(0.0f), + uiXSetCoordinate(0.0f), + uiYSetCoordinate(0.0f), + uiZSetCoordinate(0.0f), + uiYawSet(0.0f), + metricWidth(2.0f) { connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); refreshTimer->setInterval(80); + + // FIXME + float bottomMargin = 3.0f; + xCenterPos = vwidth/2.0f; + yCenterPos = vheight/2.0f - bottomMargin; } void HSIDisplay::paintEvent(QPaintEvent * event) @@ -83,21 +104,12 @@ void HSIDisplay::paintDisplay() { // Center location of the HSI gauge items - float xCenterPos = vwidth/2.0f; - float yCenterPos = vheight/2.0f; + float bottomMargin = 3.0f; // Size of the ring instrument const float margin = 0.1f; // 10% margin of total width on each side - float baseRadius = (vwidth - vwidth * 2.0f * margin) / 2.0f; - -// quint64 refreshInterval = 100; -// quint64 currTime = MG::TIME::getGroundTimeNow(); -// if (currTime - lastPaintTime < refreshInterval) -// { -// // FIXME Need to find the source of the spurious paint events -// //return; -// } -// lastPaintTime = currTime; + float baseRadius = (vheight - vheight * 2.0f * margin) / 2.0f - bottomMargin / 2.0f; + // Draw instruments // TESTING THIS SHOULD BE MOVED INTO A QGRAPHICSVIEW // Update scaling factor @@ -109,75 +121,133 @@ void HSIDisplay::paintDisplay() QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::HighQualityAntialiasing, true); + + // Draw background painter.fillRect(QRect(0, 0, width(), height()), backgroundColor); - const QColor ringColor = QColor(200, 250, 200); // Draw base instrument // ---------------------- + const QColor ringColor = QColor(200, 250, 200); const int ringCount = 2; for (int i = 0; i < ringCount; i++) { - float radius = (vwidth - vwidth * 2.0f * margin) / (2.0f * i+1) / 2.0f; - drawCircle(vwidth/2.0f, vheight/2.0f, radius, 0.1f, ringColor, &painter); + float radius = (vwidth - vwidth * 2.0f * margin) / (2.0f * i+1) / 2.0f - bottomMargin / 2.0f; + drawCircle(xCenterPos, yCenterPos, radius, 0.1f, ringColor, &painter); } // Draw center indicator - drawCircle(vwidth/2.0f, vheight/2.0f, 1.0f, 0.1f, ringColor, &painter); - - // Draw orientation labels - paintText(tr("N"), ringColor, 3.5f, xCenterPos - 1.0f, yCenterPos - baseRadius - 5.5f, &painter); - paintText(tr("S"), ringColor, 3.5f, xCenterPos - 1.0f, yCenterPos + baseRadius + 1.5f, &painter); - paintText(tr("E"), ringColor, 3.5f, xCenterPos + baseRadius + 2.0f, yCenterPos - 1.75f, &painter); - paintText(tr("W"), ringColor, 3.5f, xCenterPos - baseRadius - 5.5f, yCenterPos - 1.75f, &painter); + QPolygonF p(3); + p.replace(0, QPointF(xCenterPos, yCenterPos-2.8484f)); + p.replace(1, QPointF(xCenterPos-2.0f, yCenterPos+2.0f)); + p.replace(2, QPointF(xCenterPos+2.0f, yCenterPos+2.0f)); + drawPolygon(p, &painter); // ---------------------- + // Draw satellites + drawGPS(painter); + // Draw state indicator // Draw position QColor positionColor(20, 20, 200); - drawPositionSetpoint(xCenterPos, yCenterPos, baseRadius, positionColor, &painter); + drawPositionDirection(xCenterPos, yCenterPos, baseRadius, positionColor, &painter); // Draw attitude QColor attitudeColor(200, 20, 20); - drawAttitudeSetpoint(xCenterPos, yCenterPos, baseRadius, attitudeColor, &painter); + drawAttitudeDirection(xCenterPos, yCenterPos, baseRadius, attitudeColor, &painter); + // Draw position setpoints in body coordinates - // Draw satellites - drawGPS(); + if (uiXSetCoordinate != 0 || uiYSetCoordinate != 0) + { + QColor spColor(150, 150, 150); + drawSetpointXY(uiXSetCoordinate, uiYSetCoordinate, uiYawSet, spColor, painter); + } + + if (bodyXSetCoordinate != 0 || bodyYSetCoordinate != 0) + { + // Draw setpoint + drawSetpointXY(bodyXSetCoordinate, bodyYSetCoordinate, bodyYawSet, QGC::ColorCyan, painter); + // Draw travel direction line + QPointF m(bodyXSetCoordinate, bodyYSetCoordinate); + QPointF s = metricBodyToRefX(m); + drawLine(s.x(), s.y(), xCenterPos, yCenterPos, 1.5f, QGC::ColorCyan, &painter); + } + + // Labels on outer part and bottom - if (localAvailable > 0) + //if (localAvailable > 0) { + // Position QString str; str.sprintf("%05.2f %05.2f %05.2f m", x, y, z); - paintText(str, ringColor, 4.5f, xCenterPos + baseRadius - 5.5f, yCenterPos + baseRadius - 20.75f, &painter); + paintText(str, ringColor, 3.0f, xCenterPos + baseRadius - 30.75f, vheight - 5.0f, &painter); + + // Speed + str.sprintf("%05.2f m/s", speed); + paintText(str, ringColor, 3.0f, xCenterPos, vheight - 5.0f, &painter); } + // Draw orientation labels + // Translate and rotate coordinate frame + painter.translate((xCenterPos)*scalingFactor, (yCenterPos)*scalingFactor); + painter.rotate(yaw); + paintText(tr("N"), ringColor, 3.5f, - 1.0f, - baseRadius - 5.5f, &painter); + paintText(tr("S"), ringColor, 3.5f, - 1.0f, + baseRadius + 1.5f, &painter); + paintText(tr("E"), ringColor, 3.5f, + baseRadius + 2.0f, - 1.75f, &painter); + paintText(tr("W"), ringColor, 3.5f, - baseRadius - 5.5f, - 1.75f, &painter); + + // FIXME Just for testing + bodyXSetCoordinate = 0.95 * bodyXSetCoordinate + 0.05 * uiXSetCoordinate; + bodyYSetCoordinate = 0.95 * bodyYSetCoordinate + 0.05 * uiYSetCoordinate; + bodyZSetCoordinate = 0.95 * bodyZSetCoordinate + 0.05 * uiZSetCoordinate; + bodyYawSet = 0.95 * bodyYawSet + 0.05 * uiYawSet; +} - //drawSystemIndicator(10.0f-gaugeWidth/2.0f, 20.0f, 10.0f, 40.0f, 15.0f, &painter); - //drawGauge(15.0f, 15.0f, gaugeWidth/2.0f, 0, 1.0f, "thrust", values.value("thrust", 0.0f), gaugeColor, &painter, qMakePair(0.45f, 0.8f), qMakePair(0.8f, 1.0f), true); - //drawGauge(15.0f+gaugeWidth*1.7f, 15.0f, gaugeWidth/2.0f, 0, 10.0f, "altitude", values.value("altitude", 0.0f), gaugeColor, &painter, qMakePair(1.0f, 2.5f), qMakePair(0.0f, 0.5f), true); - - // Left spacing from border / other gauges, measured from left edge to center - // float leftSpacing = gaugeWidth * spacing; - // float xCoord = leftSpacing + gaugeWidth/2.0f; - // - // float topSpacing = leftSpacing; - // float yCoord = topSpacing + gaugeWidth/2.0f; - // - // for (int i = 0; i < acceptList->size(); ++i) - // { - // QString value = acceptList->at(i); - // drawGauge(xCoord, yCoord, gaugeWidth/2.0f, minValues.value(value, -1.0f), maxValues.value(value, 1.0f), value, values.value(value, minValues.value(value, 0.0f)), gaugeColor, &painter, goodRanges.value(value, qMakePair(0.0f, 0.5f)), critRanges.value(value, qMakePair(0.7f, 1.0f)), true); - // xCoord += gaugeWidth + leftSpacing; - // // Move one row down if necessary - // if (xCoord + gaugeWidth > vwidth) - // { - // yCoord += topSpacing + gaugeWidth; - // xCoord = leftSpacing + gaugeWidth/2.0f; - // } - // } +QPointF HSIDisplay::screenToMetricBody(QPointF ref) +{ + return QPointF(-((screenToRefY(ref.y()) - yCenterPos)/ vwidth) * metricWidth, ((screenToRefX(ref.x()) - xCenterPos) / vwidth) * metricWidth); +} + +QPointF HSIDisplay::refToMetricBody(QPointF &ref) +{ + return QPointF(-((ref.y() - yCenterPos)/ vwidth) * metricWidth, ((ref.x() - xCenterPos) / vwidth) * metricWidth); +} + +/** + * @see refToScreenX() + */ +QPointF HSIDisplay::metricBodyToRefX(QPointF &metric) +{ + return QPointF(((metric.y())/ metricWidth) * vwidth + xCenterPos, ((-metric.x()) / metricWidth) * vwidth + yCenterPos); +} + +void HSIDisplay::mouseDoubleClickEvent(QMouseEvent * event) +{ + static bool dragStarted; + static float startX; + + if (event->MouseButtonDblClick) + { + //setBodySetpointCoordinateXY(-refToMetric(screenToRefY(event->y()) - yCenterPos), refToMetric(screenToRefX(event->x()) - xCenterPos)); + + QPointF p = screenToMetricBody(event->posF()); + setBodySetpointCoordinateXY(p.x(), p.y()); + qDebug() << "Double click at x: " << screenToRefX(event->x()) - xCenterPos << "y:" << screenToRefY(event->y()) - yCenterPos; + } + else if (event->MouseButtonPress) + { + if (event->button() == Qt::RightButton) + { + + } + else if (event->button() == Qt::LeftButton) + { + + } + } } /** @@ -186,19 +256,23 @@ void HSIDisplay::paintDisplay() */ void HSIDisplay::setActiveUAS(UASInterface* uas) { - HDDisplay::setActiveUAS(uas); - //qDebug() << "ATTEMPTING TO SET UAS"; if (this->uas != NULL && this->uas != uas) { // Disconnect any previously connected active MAV //disconnect(uas, SIGNAL(valueChanged(UASInterface*,QString,double,quint64)), this, SLOT(updateValue(UASInterface*,QString,double,quint64))); } + + HDDisplay::setActiveUAS(uas); + //qDebug() << "ATTEMPTING TO SET UAS"; + + connect(uas, SIGNAL(gpsSatelliteStatusChanged(int,int,float,float,float,bool)), this, SLOT(updateSatellite(int,int,float,float,float,bool))); connect(uas, SIGNAL(localPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateLocalPosition(UASInterface*,double,double,double,quint64))); connect(uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateGlobalPosition(UASInterface*,double,double,double,quint64))); connect(uas, SIGNAL(attitudeThrustSetPointChanged(UASInterface*,double,double,double,double,quint64)), this, SLOT(updateAttitudeSetpoints(UASInterface*,double,double,double,double,quint64))); connect(uas, SIGNAL(positionSetPointsChanged(int,float,float,float,float,quint64)), this, SLOT(updatePositionSetpoints(int,float,float,float,float,quint64))); + connect(uas, SIGNAL(speedChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateSpeed(UASInterface*,double,double,double,quint64))); // Now connect the new UAS @@ -210,6 +284,36 @@ void HSIDisplay::setActiveUAS(UASInterface* uas) //} } +void HSIDisplay::updateSpeed(UASInterface* uas, double vx, double vy, double vz, quint64 time) +{ + Q_UNUSED(uas); + Q_UNUSED(time); + this->vx = vx; + this->vy = vy; + this->vz = vz; + this->speed = sqrt(pow(vx, 2.0f) + pow(vy, 2.0f) + pow(vz, 2.0f)); +} + +void HSIDisplay::setBodySetpointCoordinateXY(double x, double y) +{ + // Set coordinates and send them out to MAV + + qDebug() << "Setting new setpoint at x: " << x << "metric y:" << y; + uiXSetCoordinate = x; + uiYSetCoordinate = y; +} + +void HSIDisplay::setBodySetpointCoordinateZ(double z) +{ + // Set coordinates and send them out to MAV + uiZSetCoordinate = z; +} + +void HSIDisplay::sendBodySetPointCoordinates() +{ + // Send the coordinates to the MAV +} + void HSIDisplay::updateAttitudeSetpoints(UASInterface* uas, double rollDesired, double pitchDesired, double yawDesired, double thrustDesired, quint64 usec) { Q_UNUSED(uas); @@ -287,14 +391,36 @@ QColor HSIDisplay::getColorForSNR(float snr) return color; } -void HSIDisplay::drawGPS() +void HSIDisplay::drawSetpointXY(float x, float y, float yaw, const QColor &color, QPainter &painter) { - float xCenter = vwidth/2.0f; - float yCenter = vwidth/2.0f; - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setRenderHint(QPainter::HighQualityAntialiasing, true); + float radius = vwidth / 20.0f; + QPen pen(color); + pen.setWidthF(refLineWidthToPen(0.4f)); + pen.setColor(color); + painter.setPen(pen); + painter.setBrush(Qt::NoBrush); + QPointF in(x, y); + QPointF p = metricBodyToRefX(in); + drawCircle(p.x(), p.y(), radius, 0.4f, color, &painter); + radius *= 0.8; + drawLine(p.x(), p.y(), p.x()+sin(yaw) * radius, p.y()-cos(yaw) * radius, refLineWidthToPen(0.4f), color, &painter); + painter.setBrush(color); + drawCircle(p.x(), p.y(), radius * 0.1f, 0.1f, color, &painter); +} + +void HSIDisplay::drawSafetyArea(const QPointF &topLeft, const QPointF &bottomRight, const QColor &color, QPainter &painter) +{ + QPen pen(color); + pen.setWidthF(refLineWidthToPen(0.1f)); + pen.setColor(color); + painter.setPen(pen); + painter.drawRect(QRectF(topLeft, bottomRight)); +} +void HSIDisplay::drawGPS(QPainter &painter) +{ + float xCenter = xCenterPos; + float yCenter = xCenterPos; // Max satellite circle radius const float margin = 0.15f; // 20% margin of total width on each side @@ -349,18 +475,20 @@ void HSIDisplay::drawGPS() float xPos = xCenter + (sin(((sat->azimuth/255.0f)*360.0f)/180.0f * M_PI) * cos(sat->elevation/180.0f * M_PI)) * radius; float yPos = yCenter - (cos(((sat->azimuth/255.0f)*360.0f)/180.0f * M_PI) * cos(sat->elevation/180.0f * M_PI)) * radius; + // Draw circle for satellite, filled for used satellites drawCircle(xPos, yPos, vwidth*0.02f, 1.0f, color, &painter); + // Draw satellite PRN paintText(QString::number(sat->id), QColor(255, 255, 255), 2.9f, xPos+1.7f, yPos+2.0f, &painter); } } } -void HSIDisplay::drawObjects() +void HSIDisplay::drawObjects(QPainter &painter) { - + Q_UNUSED(painter); } -void HSIDisplay::drawPositionSetpoint(float xRef, float yRef, float radius, const QColor& color, QPainter* painter) +void HSIDisplay::drawPositionDirection(float xRef, float yRef, float radius, const QColor& color, QPainter* painter) { // Draw the needle const float maxWidth = radius / 10.0f; @@ -392,10 +520,10 @@ void HSIDisplay::drawPositionSetpoint(float xRef, float yRef, float radius, cons painter->setBrush(indexBrush); drawPolygon(p, painter); - qDebug() << "DRAWING POS SETPOINT X:" << posXSet << "Y:" << posYSet << angle; + //qDebug() << "DRAWING POS SETPOINT X:" << posXSet << "Y:" << posYSet << angle; } -void HSIDisplay::drawAttitudeSetpoint(float xRef, float yRef, float radius, const QColor& color, QPainter* painter) +void HSIDisplay::drawAttitudeDirection(float xRef, float yRef, float radius, const QColor& color, QPainter* painter) { // Draw the needle const float maxWidth = radius / 10.0f; @@ -427,7 +555,7 @@ void HSIDisplay::drawAttitudeSetpoint(float xRef, float yRef, float radius, cons // TODO Draw Yaw indicator - qDebug() << "DRAWING ATT SETPOINT X:" << attXSet << "Y:" << attYSet << angle; + //qDebug() << "DRAWING ATT SETPOINT X:" << attXSet << "Y:" << attYSet << angle; } void HSIDisplay::drawAltitudeSetpoint(float xRef, float yRef, float radius, const QColor& color, QPainter* painter) @@ -446,3 +574,13 @@ void HSIDisplay::drawAltitudeSetpoint(float xRef, float yRef, float radius, cons // label.sprintf("%05.1f", value); // paintText(label, color, 4.5f, xRef-7.5f, yRef-2.0f, painter); } + +void HSIDisplay::updateJoystick(double roll, double pitch, double yaw, double thrust, int xHat, int yHat) +{ + +} + +void HSIDisplay::pressKey(int key) +{ + +} diff --git a/src/ui/HSIDisplay.h b/src/ui/HSIDisplay.h index 217ec8010..4c7899ec6 100644 --- a/src/ui/HSIDisplay.h +++ b/src/ui/HSIDisplay.h @@ -37,6 +37,7 @@ This file is part of the PIXHAWK project #include #include #include +#include #include #include "HDDisplay.h" @@ -55,19 +56,38 @@ public slots: void updatePositionSetpoints(int uasid, float xDesired, float yDesired, float zDesired, float yawDesired, quint64 usec); void updateLocalPosition(UASInterface*, double x, double y, double z, quint64 usec); void updateGlobalPosition(UASInterface*, double lat, double lon, double alt, quint64 usec); + void updateSpeed(UASInterface* uas, double vx, double vy, double vz, quint64 time); void paintEvent(QPaintEvent * event); + /** @brief Update state from joystick */ + void updateJoystick(double roll, double pitch, double yaw, double thrust, int xHat, int yHat); + void pressKey(int key); protected slots: void paintDisplay(); - void drawGPS(); - void drawObjects(); - void drawPositionSetpoint(float xRef, float yRef, float radius, const QColor& color, QPainter* painter); - void drawAttitudeSetpoint(float xRef, float yRef, float radius, const QColor& color, QPainter* painter); + void drawGPS(QPainter &painter); + void drawObjects(QPainter &painter); + void drawPositionDirection(float xRef, float yRef, float radius, const QColor& color, QPainter* painter); + void drawAttitudeDirection(float xRef, float yRef, float radius, const QColor& color, QPainter* painter); void drawAltitudeSetpoint(float xRef, float yRef, float radius, const QColor& color, QPainter* painter); + void setBodySetpointCoordinateXY(double x, double y); + void setBodySetpointCoordinateZ(double z); + /** @brief Send the current ui setpoint coordinates as new setpoint to the MAV */ + void sendBodySetPointCoordinates(); + /** @brief Draw one setpoint */ + void drawSetpointXY(float x, float y, float yaw, const QColor &color, QPainter &painter); + /** @brief Draw the limiting safety area */ + void drawSafetyArea(const QPointF &topLeft, const QPointF &bottomRight, const QColor &color, QPainter &painter); + void mouseDoubleClickEvent(QMouseEvent* event); protected: static QColor getColorForSNR(float snr); + /** @brief Screen coordinates of widget to metric coordinates in body frame */ + QPointF screenToMetricBody(QPointF ref); + /** @brief Reference coordinates to metric coordinates */ + QPointF refToMetricBody(QPointF &ref); + /** @brief Metric coordinates to reference coordinates */ + QPointF metricBodyToRefX(QPointF &metric); /** * @brief Private data container class to be used within the HSI widget @@ -132,11 +152,31 @@ protected: float lat; float lon; float alt; - quint64 globalAvailable; ///< Last global position update time + quint64 globalAvailable; ///< Last global position update time float x; float y; float z; - quint64 localAvailable; ///< Last local position update time + float vx; + float vy; + float vz; + float speed; + quint64 localAvailable; ///< Last local position update time + float roll; + float pitch; + float yaw; + float bodyXSetCoordinate; ///< X Setpoint coordinate active on the MAV + float bodyYSetCoordinate; ///< Y Setpoint coordinate active on the MAV + float bodyZSetCoordinate; ///< Z Setpoint coordinate active on the MAV + float bodyYawSet; ///< Yaw setpoint coordinate active on the MAV + float uiXSetCoordinate; ///< X Setpoint coordinate wanted by the UI + float uiYSetCoordinate; ///< Y Setpoint coordinate wanted by the UI + float uiZSetCoordinate; ///< Z Setpoint coordinate wanted by the UI + float uiYawSet; ///< Yaw Setpoint wanted by the UI + float metricWidth; ///< Width the instrument represents in meters (the width of the ground shown by the widget) + + // + float xCenterPos; + float yCenterPos; private: }; diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 3c48f41d4..626d8a45e 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -490,10 +490,11 @@ void MainWindow::loadEngineerView() container3->setWidget(info); addDockWidget(Qt::LeftDockWidgetArea, container3); - // WAYPOINT LIST - QDockWidget* container5 = new QDockWidget(tr("Waypoint List"), this); - container5->setWidget(waypoints); - addDockWidget(Qt::BottomDockWidgetArea, container5); + // HORIZONTAL SITUATION INDICATOR + QDockWidget* container6 = new QDockWidget(tr("Horizontal Situation Indicator"), this); + container6->setWidget(hsi); + hsi->start(); + addDockWidget(Qt::BottomDockWidgetArea, container6); // DEBUG CONSOLE QDockWidget* container7 = new QDockWidget(tr("Communication Console"), this); diff --git a/src/ui/UASControl.ui b/src/ui/UASControl.ui index 7ce5c3e33..127e85e44 100644 --- a/src/ui/UASControl.ui +++ b/src/ui/UASControl.ui @@ -6,21 +6,27 @@ 0 0 - 387 - 212 + 380 + 190 Form - - - 20 + + + 6 + + + 12 - + 6 - + + 6 + + UNCONNECTED @@ -30,27 +36,14 @@ - - - - Qt::Horizontal - - - - 0 - 172 - - - - - + Activate Engine - + Qt::Vertical @@ -60,13 +53,26 @@ - 218 - 6 + 20 + 0 - + + + + Qt::Horizontal + + + + 31 + 159 + + + + + Liftoff @@ -77,56 +83,56 @@ - - - - - + + - Halt + Land - :/images/actions/system-log-out.svg:/images/actions/system-log-out.svg + :/images/control/land.svg:/images/control/land.svg - - + + - Set Mode + Halt - :/images/devices/network-wireless.svg:/images/devices/network-wireless.svg + :/images/actions/system-log-out.svg:/images/actions/system-log-out.svg - - + + - Qt::Vertical + Qt::Horizontal - 20 - 0 + 30 + 159 - - + + + + + - Land + Set Mode - :/images/control/land.svg:/images/control/land.svg + :/images/devices/network-wireless.svg:/images/devices/network-wireless.svg - + No actions executed so far @@ -136,6 +142,19 @@ + + + + Qt::Vertical + + + + 20 + 0 + + + + diff --git a/src/ui/UASInfo.ui b/src/ui/UASInfo.ui index a9a5a93cf..029e796c1 100644 --- a/src/ui/UASInfo.ui +++ b/src/ui/UASInfo.ui @@ -17,6 +17,9 @@ + + 6 + @@ -109,19 +112,6 @@ - - - - Qt::Horizontal - - - - 40 - 108 - - - - @@ -398,7 +388,7 @@ 0 - 197 + 0 diff --git a/src/ui/UASList.ui b/src/ui/UASList.ui index 39ce14ed8..27857f497 100644 --- a/src/ui/UASList.ui +++ b/src/ui/UASList.ui @@ -10,6 +10,12 @@ 300 + + + 500 + 0 + + Form diff --git a/src/ui/UASView.ui b/src/ui/UASView.ui index 92a715da4..39c09c344 100644 --- a/src/ui/UASView.ui +++ b/src/ui/UASView.ui @@ -26,7 +26,7 @@ Form - QWidget#colorIcon {} + QWidget#colorIcon {} QWidget { background-color: none; @@ -95,19 +95,6 @@ QGroupBox#heartbeatIcon { background-color: red; } -QToolButton { - font-weight: bold; - font-size: 12px; - border: 1px solid #999999; - border-radius: 5px; - min-width:44px; - max-width: 44px; - min-height: 44px; - max-height: 44px; - padding: 0px; - background-color: none; -} - QToolButton#typeButton { font-weight: bold; font-size: 12px; @@ -126,7 +113,7 @@ QPushButton { font-size: 12px; border: 1px solid #999999; border-radius: 10px; - min-width:12px; + min-width: 20px; max-width: 40px; min-height: 16px; max-height: 16px; @@ -203,14 +190,14 @@ QProgressBar::chunk#thrustBar { - + 0 0 - 350 + 0 0 @@ -558,7 +545,7 @@ QProgressBar::chunk#thrustBar { - 18 + 26 22 @@ -575,7 +562,7 @@ QProgressBar::chunk#thrustBar { - 18 + 26 22 @@ -592,7 +579,7 @@ QProgressBar::chunk#thrustBar { - 18 + 26 22 @@ -609,7 +596,7 @@ QProgressBar::chunk#thrustBar { - 18 + 26 22 @@ -637,7 +624,7 @@ QProgressBar::chunk#thrustBar { - 18 + 26 22 @@ -654,7 +641,7 @@ QProgressBar::chunk#thrustBar { - 18 + 26 22 diff --git a/src/ui/XMLCommProtocolWidget.cc b/src/ui/XMLCommProtocolWidget.cc index 387b69b18..907cd0fd6 100644 --- a/src/ui/XMLCommProtocolWidget.cc +++ b/src/ui/XMLCommProtocolWidget.cc @@ -47,17 +47,18 @@ void XMLCommProtocolWidget::selectXMLFile() { m_ui->fileNameLabel->setText(fileNames.first()); QFile file(fileNames.first()); - // Store filename for next time - settings.setValue(mavlinkXML, fileNames.first()); + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { const QString instanceText(QString::fromUtf8(file.readAll())); setXML(instanceText); + // Store filename for next time + settings.setValue(mavlinkXML, QFileInfo(file).absoluteFilePath()); } else { QMessageBox msgBox; - msgBox.setText("Could not write XML file. Permission denied"); + msgBox.setText("Could not read XML file. Permission denied"); msgBox.exec(); } } @@ -114,10 +115,25 @@ void XMLCommProtocolWidget::selectOutputDirectory() void XMLCommProtocolWidget::generate() { + // Check if input file is present + if (!QFileInfo(m_ui->fileNameLabel->text().trimmed()).isFile()) + { + QMessageBox::critical(this, tr("Please select an XML input file first"), tr("You have to select an input XML file before generating C files."), QMessageBox::Ok); + return; + } + + // Check if output dir is selected + if (!QFileInfo(m_ui->outputDirNameLabel->text().trimmed()).isDir()) + { + QMessageBox::critical(this, tr("Please select output directory first"), tr("You have to select an output directory before generating C files."), QMessageBox::Ok); + return; + } + // First save file save(); // Clean log m_ui->compileLog->clear(); + MAVLinkXMLParser* parser = new MAVLinkXMLParser(m_ui->fileNameLabel->text().trimmed(), m_ui->outputDirNameLabel->text().trimmed()); connect(parser, SIGNAL(parseState(QString)), m_ui->compileLog, SLOT(appendHtml(QString))); bool result = parser->generate(); -- 2.22.0