diff --git a/src/uas/UASManager.cc b/src/uas/UASManager.cc index f0997d87b7a03971898924e9575c88e4d4795c84..f43b08708f10d2ebfcb67ba163b275000a4ba6b5 100644 --- a/src/uas/UASManager.cc +++ b/src/uas/UASManager.cc @@ -73,10 +73,12 @@ void UASManager::loadSettings() settings.endGroup(); } -void UASManager::setHomePosition(double lat, double lon, double alt) +bool UASManager::setHomePosition(double lat, double lon, double alt) { // Checking for NaN and infitiny - if (lat == lat && lon == lon && alt == alt && !std::isinf(lat) && !std::isinf(lon) && !std::isinf(alt)) { + if (lat == lat && lon == lon && alt == alt && !std::isinf(lat) && !std::isinf(lon) && !std::isinf(alt) + && lat <= 90.0 && lat >= -90.0 && lon <= 180.0 && lon >= -180.0) { + bool changed = false; if (homeLat != lat) changed = true; if (homeLon != lon) changed = true; @@ -87,6 +89,9 @@ void UASManager::setHomePosition(double lat, double lon, double alt) homeAlt = alt; if (changed) emit homePositionChanged(homeLat, homeLon, homeAlt); + return true; + } else { + return false; } } diff --git a/src/uas/UASManager.h b/src/uas/UASManager.h index 39788e476d00593272b15dd580abb2a4c07a55ac..2a02f2a3761af2db055ce98003ca875bf9379a9a 100644 --- a/src/uas/UASManager.h +++ b/src/uas/UASManager.h @@ -175,7 +175,7 @@ public slots: bool shutdownActiveUAS(); /** @brief Set the current home position */ - void setHomePosition(double lat, double lon, double alt); + bool setHomePosition(double lat, double lon, double alt); /** @brief Load settings */ void loadSettings(); diff --git a/src/uas/UASWaypointManager.cc b/src/uas/UASWaypointManager.cc index 9fc5d3754b4854bc34d99733f20278cc773efc8d..c5471b0c81efd8e3deac8707ce11e77a46f5704c 100644 --- a/src/uas/UASWaypointManager.cc +++ b/src/uas/UASWaypointManager.cc @@ -273,7 +273,9 @@ int UASWaypointManager::setCurrentWaypoint(quint16 seq) } /** + * @warning Make sure the waypoint stays valid for the whole application lifecycle! * @param enforceFirstActive Enforces that the first waypoint is set as active + * @see createWaypoint() is more suitable for most use cases */ void UASWaypointManager::addWaypoint(Waypoint *wp, bool enforceFirstActive) { @@ -288,6 +290,22 @@ void UASWaypointManager::addWaypoint(Waypoint *wp, bool enforceFirstActive) } } +/** + * @param enforceFirstActive Enforces that the first waypoint is set as active + */ +Waypoint* UASWaypointManager::createWaypoint(bool enforceFirstActive) +{ + Waypoint* wp = new Waypoint(); + wp->setId(waypoints.size()); + if (enforceFirstActive && waypoints.size() == 0) wp->setCurrent(true); + waypoints.insert(waypoints.size(), wp); + connect(wp, SIGNAL(changed(Waypoint*)), this, SLOT(notifyOfChange(Waypoint*))); + + emit waypointListChanged(); + emit waypointListChanged(uas.getUASID()); + return wp; +} + int UASWaypointManager::removeWaypoint(quint16 seq) { if (seq < waypoints.size()) { diff --git a/src/uas/UASWaypointManager.h b/src/uas/UASWaypointManager.h index 8cb55d5a70ef103e1b3be01a5b13cb677c5c92ac..a38503f0bcd03e466d634ae19068d630bda6c516 100644 --- a/src/uas/UASWaypointManager.h +++ b/src/uas/UASWaypointManager.h @@ -128,6 +128,7 @@ public slots: /** @name Waypoint list operations */ /*@{*/ void addWaypoint(Waypoint *wp, bool enforceFirstActive=true); ///< adds a new waypoint to the end of the list and changes its sequence number accordingly + Waypoint* createWaypoint(bool enforceFirstActive=true); ///< Creates a waypoint int removeWaypoint(quint16 seq); ///< locally remove the specified waypoint from the storage void moveWaypoint(quint16 cur_seq, quint16 new_seq); ///< locally move a waypoint from its current position cur_seq to a new position new_seq void saveWaypoints(const QString &saveFile); ///< saves the local waypoint list to saveFile diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 4fd2fec47fe4ccd8f4bbb55aca79e990f953b084..bf0e00d1ce10d85c67431dde6f6971ffaea26c6b 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -70,7 +70,8 @@ MainWindow::MainWindow(QWidget *parent): changingViewsFlag(false), styleFileName(QCoreApplication::applicationDirPath() + "/style-indoor.css"), autoReconnect(false), - currentStyle(QGC_MAINWINDOW_STYLE_INDOOR) + currentStyle(QGC_MAINWINDOW_STYLE_INDOOR), + lowPowerMode(false) { loadSettings(); if (!settings.contains("CURRENT_VIEW")) { @@ -163,6 +164,9 @@ MainWindow::MainWindow(QWidget *parent): link->connect(); } + // Set low power mode + enableLowPowerMode(lowPowerMode); + // Initialize window state windowStateVal = windowState(); } @@ -1048,6 +1052,7 @@ void MainWindow::loadSettings() settings.beginGroup("QGC_MAINWINDOW"); autoReconnect = settings.value("AUTO_RECONNECT", autoReconnect).toBool(); currentStyle = (QGC_MAINWINDOW_STYLE)settings.value("CURRENT_STYLE", currentStyle).toInt(); + lowPowerMode = settings.value("LOW_POWER_MODE", lowPowerMode).toBool(); settings.endGroup(); } @@ -1065,6 +1070,8 @@ void MainWindow::storeSettings() if (UASManager::instance()->getUASList().length() > 0) settings.setValue(getWindowStateKey(), saveState(QGC::applicationVersion())); // Save the current view only if a UAS is connected if (UASManager::instance()->getUASList().length() > 0) settings.setValue("CURRENT_VIEW_WITH_UAS_CONNECTED", currentView); + // Save the current power mode + settings.setValue("LOW_POWER_MODE", lowPowerMode); settings.sync(); } @@ -1886,7 +1893,7 @@ void MainWindow::presentView() } } - // ACTIVATE MAP WIDGET + // ACTIVATE HUD WIDGET if (headUpDockWidget) { HUD* tmpHud = dynamic_cast( headUpDockWidget->widget() ); if (tmpHud) { diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index c3b6c888ebc75a033ba781bd2887d3ed4dd505e8..db0c38a30e8a3c5d580152b69a3008f1c4278742 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -103,6 +103,11 @@ public: return autoReconnect; } + /** @brief Get low power mode setting */ + bool lowPowerModeEnabled() { + return lowPowerMode; + } + public slots: // /** @brief Store the mainwindow settings */ // void storeSettings(); @@ -160,6 +165,8 @@ public slots: void selectStylesheet(); /** @brief Automatically reconnect last link */ void enableAutoReconnect(bool enabled); + /** @brief Save power by reducing update rates */ + void enableLowPowerMode(bool enabled) { lowPowerMode = enabled; } /** @brief Switch to native application style */ void loadNativeStyle(); /** @brief Switch to indoor mission style */ @@ -430,6 +437,7 @@ protected: bool autoReconnect; QGC_MAINWINDOW_STYLE currentStyle; Qt::WindowStates windowStateVal; + bool lowPowerMode; ///< If enabled, QGC reduces the update rates of all widgets private: Ui::MainWindow ui; diff --git a/src/ui/uas/UASView.cc b/src/ui/uas/UASView.cc index 66305faa9c2f410e7c8e690282be4cb8fee39569..41a173c64a9565c8c57970d0a912c01f1f9dbfd4 100644 --- a/src/ui/uas/UASView.cc +++ b/src/ui/uas/UASView.cc @@ -39,38 +39,44 @@ This file is part of the PIXHAWK project #include "UASManager.h" #include "UASView.h" #include "UASWaypointManager.h" +#include "MainWindow.h" #include "ui_UASView.h" UASView::UASView(UASInterface* uas, QWidget *parent) : - QWidget(parent), - startTime(0), - timeout(false), - iconIsRed(true), - timeRemaining(0), - chargeLevel(0), - uas(uas), - load(0), - state("UNKNOWN"), - stateDesc(tr("Unknown state")), - mode("MAV_MODE_UNKNOWN"), - thrust(0), - isActive(false), - x(0), - y(0), - z(0), - totalSpeed(0), - lat(0), - lon(0), - alt(0), - groundDistance(0), - localFrame(false), - removeAction(new QAction("Delete this system", this)), - renameAction(new QAction("Rename..", this)), - selectAction(new QAction("Control this system", this )), - selectAirframeAction(new QAction("Choose Airframe", this)), - setBatterySpecsAction(new QAction("Set Battery Options", this)), - m_ui(new Ui::UASView) -{ + QWidget(parent), + startTime(0), + timeout(false), + iconIsRed(true), + timeRemaining(0), + chargeLevel(0), + uas(uas), + load(0), + state("UNKNOWN"), + stateDesc(tr("Unknown state")), + mode("MAV_MODE_UNKNOWN"), + thrust(0), + isActive(false), + x(0), + y(0), + z(0), + totalSpeed(0), + lat(0), + lon(0), + alt(0), + groundDistance(0), + localFrame(false), + removeAction(new QAction("Delete this system", this)), + renameAction(new QAction("Rename..", this)), + selectAction(new QAction("Control this system", this )), + selectAirframeAction(new QAction("Choose Airframe", this)), + setBatterySpecsAction(new QAction("Set Battery Options", this)), + lowPowerModeEnabled(false), + m_ui(new Ui::UASView) +{ + // FIXME XXX + lowPowerModeEnabled = MainWindow::instance()->lowPowerModeEnabled(); + + m_ui->setupUi(this); // Setup communication @@ -129,7 +135,12 @@ UASView::UASView(UASInterface* uas, QWidget *parent) : // Heartbeat fade refreshTimer = new QTimer(this); connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); - refreshTimer->start(updateInterval); + if (lowPowerModeEnabled) + { + refreshTimer->start(updateInterval*10); + } else { + refreshTimer->start(updateInterval); + } // Hide kill and shutdown buttons per default m_ui->killButton->hide(); @@ -248,7 +259,7 @@ void UASView::showEvent(QShowEvent* event) // React only to internal (pre-display) // events Q_UNUSED(event); - refreshTimer->start(updateInterval); + refreshTimer->start(updateInterval*10); } void UASView::hideEvent(QHideEvent* event) @@ -305,24 +316,24 @@ void UASView::setSystemType(UASInterface* uas, unsigned int systemType) m_ui->typeButton->setIcon(QIcon(":/images/mavs/unknown.svg")); break; case 6: { - // A groundstation is a special system type, update widget - QString result; - m_ui->nameLabel->setText(tr("OCU ") + result.sprintf("%03d", uas->getUASID())); - m_ui->waypointLabel->setText(""); - m_ui->timeRemainingLabel->setText("Online:"); - m_ui->batteryBar->hide(); - m_ui->thrustBar->hide(); - m_ui->stateLabel->hide(); - m_ui->statusTextLabel->hide(); - m_ui->waypointLabel->hide(); - m_ui->liftoffButton->hide(); - m_ui->haltButton->hide(); - m_ui->landButton->hide(); - m_ui->shutdownButton->hide(); - m_ui->abortButton->hide(); - m_ui->typeButton->setIcon(QIcon(":/images/mavs/groundstation.svg")); - } - break; + // A groundstation is a special system type, update widget + QString result; + m_ui->nameLabel->setText(tr("OCU ") + result.sprintf("%03d", uas->getUASID())); + m_ui->waypointLabel->setText(""); + m_ui->timeRemainingLabel->setText("Online:"); + m_ui->batteryBar->hide(); + m_ui->thrustBar->hide(); + m_ui->stateLabel->hide(); + m_ui->statusTextLabel->hide(); + m_ui->waypointLabel->hide(); + m_ui->liftoffButton->hide(); + m_ui->haltButton->hide(); + m_ui->landButton->hide(); + m_ui->shutdownButton->hide(); + m_ui->abortButton->hide(); + m_ui->typeButton->setIcon(QIcon(":/images/mavs/groundstation.svg")); + } + break; default: m_ui->typeButton->setIcon(QIcon(":/images/mavs/unknown.svg")); break; @@ -458,15 +469,15 @@ void UASView::selectAirframe() // Get list of airframes from UAS QStringList airframes; airframes << "Generic" - << "Multiplex Easystar" - << "Multiplex Twinstar" - << "Multiplex Merlin" - << "Pixhawk Cheetah" - << "Mikrokopter" - << "Reaper" - << "Predator" - << "Coaxial" - << "Pteryx"; + << "Multiplex Easystar" + << "Multiplex Twinstar" + << "Multiplex Merlin" + << "Pixhawk Cheetah" + << "Mikrokopter" + << "Reaper" + << "Predator" + << "Coaxial" + << "Pteryx"; bool ok; QString item = QInputDialog::getItem(this, tr("Select Airframe for %1").arg(uas->getUASName()), @@ -591,12 +602,15 @@ void UASView::refresh() } iconIsRed = !iconIsRed; } else { - // Fade heartbeat icon - // Make color darker - heartbeatColor = heartbeatColor.darker(150); - - //m_ui->heartbeatIcon->setAutoFillBackground(true); - m_ui->heartbeatIcon->setStyleSheet(colorstyle.arg(heartbeatColor.name())); + if (!lowPowerModeEnabled) + { + // Fade heartbeat icon + // Make color darker + heartbeatColor = heartbeatColor.darker(150); + + //m_ui->heartbeatIcon->setAutoFillBackground(true); + m_ui->heartbeatIcon->setStyleSheet(colorstyle.arg(heartbeatColor.name())); + } } //setUpdatesEnabled(true); diff --git a/src/ui/uas/UASView.h b/src/ui/uas/UASView.h index 296338eb5d5ef1539de872ad5d5f1e61b0bc3b36..c29edafbbdd1dd59784e51ce7654f89544063170 100644 --- a/src/ui/uas/UASView.h +++ b/src/ui/uas/UASView.h @@ -122,7 +122,8 @@ protected: QAction* selectAction; QAction* selectAirframeAction; QAction* setBatterySpecsAction; - static const int updateInterval = 300; + static const int updateInterval = 700; + bool lowPowerModeEnabled; ///< Low power mode reduces update rates void mouseDoubleClickEvent (QMouseEvent * event);