From fb05e12568738d59fcb4f6b43813dedcd4db5aa6 Mon Sep 17 00:00:00 2001 From: lm Date: Wed, 9 Jun 2010 10:38:33 +0200 Subject: [PATCH 1/2] Update UI control elements from vehicle, allows multi-operator mode --- src/ui/uas/UASControlWidget.cc | 48 +++++++++++++++++++++++++++++------------- src/ui/uas/UASControlWidget.h | 7 +++++- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/ui/uas/UASControlWidget.cc b/src/ui/uas/UASControlWidget.cc index ff2f5be..f28f749 100644 --- a/src/ui/uas/UASControlWidget.cc +++ b/src/ui/uas/UASControlWidget.cc @@ -55,7 +55,8 @@ This file is part of the PIXHAWK project #define CONTROL_MODE_TEST1_INDEX 6 UASControlWidget::UASControlWidget(QWidget *parent) : QWidget(parent), - uas(NULL) + uas(NULL), + engineOn(false) { ui.setupUi(this); @@ -94,6 +95,9 @@ void UASControlWidget::setUAS(UASInterface* uas) ui.controlStatusLabel->setText(tr("Connected to ") + uas->getUASName()); + connect(uas, SIGNAL(modeChanged(int,QString,QString)), this, SLOT(updateMode(int,QString,QString))); + connect(uas, SIGNAL(statusChanged(int)), this, SLOT(updateState(int))); + this->uas = uas; } } @@ -102,6 +106,28 @@ UASControlWidget::~UASControlWidget() { } +void UASControlWidget::updateMode(int uas,QString mode,QString description) +{ + Q_UNUSED(uas); + Q_UNUSED(mode); + Q_UNUSED(description); +} + +void UASControlWidget::updateState(int state) +{ + switch (state) + { + case (int)MAV_STATE_ACTIVE: + engineOn = true; + ui.controlButton->setText(tr("Stop Engine")); + break; + case (int)MAV_STATE_STANDBY: + engineOn = false; + ui.controlButton->setText(tr("Activate Engine")); + break; + } +} + void UASControlWidget::setMode(int mode) { // Adapt context button mode @@ -151,34 +177,26 @@ void UASControlWidget::transmitMode() void UASControlWidget::cycleContextButton() { - //switch(uas->getMode()); - static int state = 0; - UAS* mav = dynamic_cast(this->uas); if (mav) { - switch (state) + if (engineOn) { - case 0: ui.controlButton->setText(tr("Stop Engine")); mav->setMode(MAV_MODE_MANUAL); mav->enable_motors(); ui.lastActionLabel->setText(QString("Enabled motors on %1").arg(uas->getUASName())); - state++; - break; - case 1: + } + else + { ui.controlButton->setText(tr("Activate Engine")); mav->setMode(MAV_MODE_LOCKED); mav->disable_motors(); ui.lastActionLabel->setText(QString("Disabled motors on %1").arg(uas->getUASName())); - state = 0; - break; - case 2: - //ui.controlButton->setText(tr("Force Landing")); - ui.controlButton->setText(tr("KILL VEHICLE")); - break; } + //ui.controlButton->setText(tr("Force Landing")); + //ui.controlButton->setText(tr("KILL VEHICLE")); } } diff --git a/src/ui/uas/UASControlWidget.h b/src/ui/uas/UASControlWidget.h index 33ad1e0..e5d1609 100644 --- a/src/ui/uas/UASControlWidget.h +++ b/src/ui/uas/UASControlWidget.h @@ -53,12 +53,17 @@ public slots: void cycleContextButton(); /** @brief Set the operation mode of the MAV */ void setMode(int mode); - /** @brief Transmit the operation mode **/ + /** @brief Transmit the operation mode */ void transmitMode(); + /** @brief Update the mode */ + void updateMode(int uas,QString mode,QString description); + /** @brief Update state */ + void updateState(int state); protected: UASInterface* uas; unsigned int uasMode; + bool engineOn; private: Ui::uasControl ui; From 5d47074be53d6f630ae9c5d7c169bd5e1074f88d Mon Sep 17 00:00:00 2001 From: lm Date: Wed, 9 Jun 2010 10:54:24 +0200 Subject: [PATCH 2/2] Update UI control elements from vehicle, allows multi-operator mode --- src/uas/UAS.cc | 1 + src/ui/uas/UASControlWidget.cc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 2bbc092..c34c070 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -161,6 +161,7 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) this->status = (int)state.status; getStatusForCode((int)state.status, uasState, stateDescription); emit statusChanged(this, uasState, stateDescription); + emit statusChanged(this->status); stateAudio = " changed status to " + uasState; } diff --git a/src/ui/uas/UASControlWidget.cc b/src/ui/uas/UASControlWidget.cc index f28f749..92192ce 100644 --- a/src/ui/uas/UASControlWidget.cc +++ b/src/ui/uas/UASControlWidget.cc @@ -181,7 +181,7 @@ void UASControlWidget::cycleContextButton() if (mav) { - if (engineOn) + if (!engineOn) { ui.controlButton->setText(tr("Stop Engine")); mav->setMode(MAV_MODE_MANUAL);