Commit 62d95365 authored by Don Gagne's avatar Don Gagne

Replaced by toolbar dropdowns

parent 0641f7f2
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>uasControl</class>
<widget class="QWidget" name="uasControl">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>200</width>
<height>228</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>150</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>267</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="toolTip">
<string>Control widget to send basic control actions to the micro air vehicle</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowstretch="5,1,40,1,40,40,40,1000" columnstretch="5,20,20,25,5">
<property name="margin">
<number>4</number>
</property>
<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="0" column="1" rowspan="2" colspan="3">
<widget class="QLabel" name="controlStatusLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>10</height>
</size>
</property>
<property name="toolTip">
<string>Currently controlled system</string>
</property>
<property name="statusTip">
<string>Currently controlled system</string>
</property>
<property name="text">
<string>UNCONNECTED</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>216</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="liftoffButton">
<property name="minimumSize">
<size>
<width>25</width>
<height>16</height>
</size>
</property>
<property name="toolTip">
<string>Liftoff / Launch</string>
</property>
<property name="statusTip">
<string>Liftoff / Launch</string>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="landButton">
<property name="minimumSize">
<size>
<width>25</width>
<height>16</height>
</size>
</property>
<property name="toolTip">
<string>Fly straight to landing spot</string>
</property>
<property name="statusTip">
<string>Fly straight to landing spot</string>
</property>
<property name="text">
<string>Land</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="shutdownButton">
<property name="minimumSize">
<size>
<width>25</width>
<height>16</height>
</size>
</property>
<property name="toolTip">
<string>Only active on the ground: Poweroff system</string>
</property>
<property name="statusTip">
<string>Only active on the ground: Poweroff system</string>
</property>
<property name="text">
<string>Halt</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="1" colspan="2">
<widget class="QComboBox" name="modeComboBox">
<property name="minimumSize">
<size>
<width>25</width>
<height>16</height>
</size>
</property>
<property name="toolTip">
<string>Select MAV operation mode</string>
</property>
<property name="statusTip">
<string>Select MAV operation mode</string>
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QPushButton" name="setModeButton">
<property name="minimumSize">
<size>
<width>25</width>
<height>16</height>
</size>
</property>
<property name="toolTip">
<string>Transmit and enable mode on MAV</string>
</property>
<property name="statusTip">
<string>Transmit and enable mode on MAV</string>
</property>
<property name="text">
<string>Set</string>
</property>
</widget>
</item>
<item row="6" column="1" colspan="3">
<widget class="QLabel" name="lastActionLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>10</height>
</size>
</property>
<property name="toolTip">
<string>Status label</string>
</property>
<property name="statusTip">
<string>Status label</string>
</property>
<property name="text">
<string>No actions executed so far</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="4" 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="2" column="1" colspan="3">
<widget class="QPushButton" name="controlButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="toolTip">
<string>Main control button</string>
</property>
<property name="statusTip">
<string>Main control button</string>
</property>
<property name="text">
<string>Activate Engine</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="3">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UASList</class>
<widget class="QWidget" name="UASList">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>300</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>3</number>
</property>
</layout>
</widget>
<resources/>
<connections/>
</ui>
This diff is collapsed.
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK is free software: you can redistribute it and/or modify
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/>.
======================================================================*/
/**
* @file
* @brief Definition of widget controlling one MAV
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#include <QString>
#include <QTimer>
#include <QLabel>
#include <QProcess>
#include <QPalette>
#include "UASControlWidget.h"
#include "MultiVehicleManager.h"
#include "UAS.h"
#include "QGC.h"
#include "AutoPilotPluginManager.h"
#include "FirmwarePluginManager.h"
UASControlWidget::UASControlWidget(QWidget *parent) : QWidget(parent),
_uas(NULL),
armed(false)
{
ui.setupUi(this);
_activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle());
connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &UASControlWidget::_activeVehicleChanged);
connect(ui.setModeButton, SIGNAL(clicked()), this, SLOT(transmitMode()));
ui.liftoffButton->hide();
ui.landButton->hide();
ui.shutdownButton->hide();
ui.gridLayout->setAlignment(Qt::AlignTop);
}
void UASControlWidget::updateModesList()
{
if (!_uas) {
return;
}
_modeList = FirmwarePluginManager::instance()->firmwarePluginForAutopilot((MAV_AUTOPILOT)_uas->getAutopilotType())->flightModes();
// Set combobox items
ui.modeComboBox->clear();
foreach (QString flightMode, _modeList) {
ui.modeComboBox->addItem(flightMode);
}
// Select first mode in list
ui.modeComboBox->setCurrentIndex(0);
ui.modeComboBox->update();
}
void UASControlWidget::_activeVehicleChanged(Vehicle* vehicle)
{
if (_uas) {
disconnect(ui.controlButton, SIGNAL(clicked()), _uas, SLOT(armSystem()));
disconnect(ui.liftoffButton, SIGNAL(clicked()), _uas, SLOT(launch()));
disconnect(ui.landButton, SIGNAL(clicked()), _uas, SLOT(home()));
disconnect(ui.shutdownButton, SIGNAL(clicked()), _uas, SLOT(shutdown()));
disconnect(_uas, SIGNAL(statusChanged(int)), this, SLOT(updateState(int)));
_uas = NULL;
}
// Connect user interface controls
if (vehicle) {
_uas = vehicle->uas();
connect(ui.controlButton, SIGNAL(clicked()), this, SLOT(cycleContextButton()));
connect(ui.liftoffButton, SIGNAL(clicked()), _uas, SLOT(launch()));
connect(ui.landButton, SIGNAL(clicked()), _uas, SLOT(home()));
connect(ui.shutdownButton, SIGNAL(clicked()), _uas, SLOT(shutdown()));
connect(_uas, SIGNAL(statusChanged(int)), this, SLOT(updateState(int)));
ui.controlStatusLabel->setText(tr("Connected to ") + _uas->getUASName());
setBackgroundColor(_uas->getColor());
this->updateModesList();
this->updateArmText();
}
}
UASControlWidget::~UASControlWidget()
{
}
void UASControlWidget::updateArmText()
{
if (armed) {
ui.controlButton->setText(tr("DISARM SYSTEM"));
} else {
ui.controlButton->setText(tr("ARM SYSTEM"));
}
}
/**
* Set the background color based on the MAV color. If the MAV is selected as the
* currently actively controlled system, the frame color is highlighted
*/
void UASControlWidget::setBackgroundColor(QColor color)
{
// UAS color
QColor uasColor = color;
QString colorstyle;
QString borderColor = "#4A4A4F";
borderColor = "#FA4A4F";
uasColor = uasColor.darker(400);
colorstyle = colorstyle.sprintf("QLabel { border-radius: 3px; padding: 0px; margin: 0px; background-color: #%02X%02X%02X; border: 0px solid %s; }",
uasColor.red(), uasColor.green(), uasColor.blue(), borderColor.toStdString().c_str());
setStyleSheet(colorstyle);
QPalette palette = this->palette();
palette.setBrush(QPalette::Window, QBrush(uasColor));
setPalette(palette);
setAutoFillBackground(true);
}
void UASControlWidget::updateState(int state)
{
switch (state) {
case (int)MAV_STATE_ACTIVE:
armed = true;
break;
case (int)MAV_STATE_STANDBY:
armed = false;
break;
}
this->updateArmText();
}
void UASControlWidget::transmitMode()
{
if (_uas) {
uint8_t base_mode;
uint32_t custom_mode;
QString flightMode = ui.modeComboBox->itemText(ui.modeComboBox->currentIndex());
if (FirmwarePluginManager::instance()->firmwarePluginForAutopilot((MAV_AUTOPILOT)_uas->getAutopilotType())->setFlightMode(flightMode, &base_mode, &custom_mode)) {
if (armed) {
base_mode |= MAV_MODE_FLAG_SAFETY_ARMED;
}
if (_uas->isHilEnabled() || _uas->isHilActive()) {
base_mode |= MAV_MODE_FLAG_HIL_ENABLED;
}
_uas->setMode(base_mode, custom_mode);
QString modeText = ui.modeComboBox->currentText();
ui.lastActionLabel->setText(QString("Sent new mode %1 to %2").arg(flightMode).arg(_uas->getUASName()));
}
}
}
void UASControlWidget::cycleContextButton()
{
if (_uas) {
if (!armed) {
_uas->armSystem();
ui.lastActionLabel->setText(QString("Arm %1").arg(_uas->getUASName()));
} else {
_uas->disarmSystem();
ui.lastActionLabel->setText(QString("Disarm %1").arg(_uas->getUASName()));
}
}
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of class UASControlWidget
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#ifndef _UASCONTROLWIDGET_H_
#define _UASCONTROLWIDGET_H_
#include <QWidget>
#include <QLineEdit>
#include <QString>
#include <QPushButton>
#include "ui_UASControl.h"
#include "UASInterface.h"
#include "Vehicle.h"
/**
* @brief Widget controlling one MAV
*/
class UASControlWidget : public QWidget
{
Q_OBJECT
public:
UASControlWidget(QWidget *parent = 0);
~UASControlWidget();
public slots:
/** @brief Update modes list for selected system */
void updateModesList();
/** @brief Trigger next context action */
void cycleContextButton();
/** @brief Transmit the operation mode */
void transmitMode();
/** @brief Update state */
void updateState(int state);
/** @brief Update internal state machine */
void updateArmText();
protected slots:
/** @brief Set the background color for the widget */
void setBackgroundColor(QColor color);
protected:
UAS* _uas;
QStringList _modeList; ///< Mode list for the current UAS
bool armed; ///< Engine state
private slots:
void _activeVehicleChanged(Vehicle* vehicle);
private:
Ui::uasControl ui;
};
#endif // _UASCONTROLWIDGET_H_
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK is free software: you can redistribute it and/or modify
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/>.
======================================================================*/
/**
* @file
* @brief List of unmanned vehicles
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#include <QString>
#include <QTimer>
#include <QLabel>
#include <QDebug>
#include <QApplication>
#include "MG.h"
#include "UASListWidget.h"
#include "MultiVehicleManager.h"
#include "UAS.h"
#include "UASView.h"
#include "QGCUnconnectedInfoWidget.h"
#include "MainWindow.h"
#include "LinkManager.h"
UASListWidget::UASListWidget(QWidget *parent) : QWidget(parent),
uWidget(NULL),
m_ui(new Ui::UASList)
{
// Use a timer to update the link health display.
updateTimer = new QTimer(this);
connect(updateTimer,SIGNAL(timeout()),this,SLOT(updateStatus()));
m_ui->setupUi(this);
m_ui->verticalLayout->setAlignment(Qt::AlignTop);
this->setMinimumWidth(262);
linkToBoxMapping = QMap<LinkInterface*, QGroupBox*>();
uasToBoxMapping = QMap<UASInterface*, QGroupBox*>();
uasViews = QMap<UASInterface*, UASView*>();
this->setVisible(false);
connect(LinkManager::instance(), SIGNAL(linkDeleted(LinkInterface*)), this, SLOT(removeLink(LinkInterface*)));
connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleAdded, this, &UASListWidget::_vehicleAdded);
connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleRemoved, this, &UASListWidget::_vehicleRemoved);
// Get a list of all existing UAS
foreach (Vehicle* vehicle, MultiVehicleManager::instance()->vehicles())
{
_vehicleAdded(vehicle);
}
}
UASListWidget::~UASListWidget()
{
delete m_ui;
}
void UASListWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type())
{
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
// XXX This is just to prevent
// upfront crashes, will probably need further inspection
void UASListWidget::removeLink(LinkInterface* link)
{
QGroupBox* box = linkToBoxMapping.value(link, NULL);
if (box) {
// Just stop updating the status for now - we should
// remove the UAS probably
linkToBoxMapping.remove(link);
}
}
void UASListWidget::updateStatus()
{
QMapIterator<LinkInterface*, QGroupBox*> i(linkToBoxMapping);
while (i.hasNext()) {
i.next();
LinkInterface* link = i.key();
// Paranoid sanity check
if (!LinkManager::instance()->containsLink(link))
continue;
if (!link)
continue;
MAVLinkProtocol* mavlink = MAVLinkProtocol::instance();
// Build the tooltip out of the protocol parsing data: received, dropped, and parsing errors.
QString displayString("");
int c;
if ((c = mavlink->getReceivedPacketCount(link)) != -1)
{
displayString += QString(tr("<br/>Received: %2")).arg(QString::number(c));
}
if ((c = mavlink->getDroppedPacketCount(link)) != -1)
{
displayString += QString(tr("<br/>Dropped: %2")).arg(QString::number(c));
}
if ((c = mavlink->getParsingErrorCount(link)) != -1)
{
displayString += QString(tr("<br/>Errors: %2")).arg(QString::number(c));
}
if (!displayString.isEmpty())
{
displayString = QString("<b>%1</b>").arg(i.key()->getName()) + displayString;
}
// qDebug() << p << ": " + displayString;
i.value()->setToolTip(displayString);
}
}
void UASListWidget::_vehicleAdded(Vehicle* vehicle)
{
UAS* uas = vehicle->uas();
// If the list was empty, remove the unconnected widget and start the update timer.
if (uasViews.isEmpty())
{
updateTimer->start(5000);
if (uWidget)
{
m_ui->verticalLayout->removeWidget(uWidget);
delete uWidget;
uWidget = NULL;
}
}
if (!uasViews.contains(uas))
{
// Only display the UAS in a single link.
QList<LinkInterface*> x = vehicle->links();
if (x.size())
{
LinkInterface* li = x.first();
// Find an existing QGroupBox for this LinkInterface or create a
// new one.
QGroupBox* newBox;
if (linkToBoxMapping.contains(li))
{