Commit 05dc22fc authored by lm's avatar lm

Working towards working maps without runtime issues

parent 93715738
......@@ -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;
}
}
......
......@@ -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();
......
......@@ -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()) {
......
......@@ -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
......
......@@ -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<HUD*>( headUpDockWidget->widget() );
if (tmpHud) {
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
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