From aafc43304a989758b8791935d3e3c35ef61b9bb8 Mon Sep 17 00:00:00 2001 From: LM Date: Fri, 13 Jan 2012 13:33:19 +0100 Subject: [PATCH] Minor cleanups in various places --- qgroundcontrol.pri | 22 +++++++-- src/input/JoystickInput.cc | 107 +++++++++++++++++++----------------------- src/uas/UAS.cc | 42 +++++++++++++++-- src/uas/UAS.h | 13 +++-- src/uas/UASInterface.h | 11 +++-- src/uas/UASManager.cc | 9 ++-- src/ui/QGCMAVLinkInspector.cc | 61 +++++++++++++++++++++++- src/ui/QGCMAVLinkInspector.h | 11 +++++ src/ui/QGCMAVLinkInspector.ui | 14 +++++- 9 files changed, 210 insertions(+), 80 deletions(-) diff --git a/qgroundcontrol.pri b/qgroundcontrol.pri index 1638f81..37add31 100644 --- a/qgroundcontrol.pri +++ b/qgroundcontrol.pri @@ -42,8 +42,8 @@ macx|macx-g++42|macx-g++: { # COMPILER_VERSION = $$system(gcc -v) #message(Using compiler $$COMPILER_VERSION) - CONFIG += x86 cocoa phonon - CONFIG -= x86_64 + CONFIG += x86_64 cocoa phonon + CONFIG -= x86 #HARDWARE_PLATFORM = $$system(uname -a) #contains( $$HARDWARE_PLATFORM, "9.6.0" ) || contains( $$HARDWARE_PLATFORM, "9.7.0" ) || contains( $$HARDWARE_PLATFORM, "9.8.0" ) || contains( $$HARDWARE_PLATFORM, "9.9.0" ) { @@ -94,7 +94,7 @@ macx|macx-g++42|macx-g++: { QMAKE_POST_LINK += && cp -rf $$BASEDIR/files $$TARGETDIR/qgroundcontrol.app/Contents/MacOS # Copy libraries QMAKE_POST_LINK += && mkdir -p $$TARGETDIR/qgroundcontrol.app/Contents/libs - QMAKE_POST_LINK += && cp -rf $$BASEDIR/lib/mac32/lib/* $$TARGETDIR/qgroundcontrol.app/Contents/libs + QMAKE_POST_LINK += && cp -rf $$BASEDIR/lib/mac64/lib/* $$TARGETDIR/qgroundcontrol.app/Contents/libs # Fix library paths inside executable QMAKE_POST_LINK += && install_name_tool -change libOpenThreads.dylib "@executable_path/../libs/libOpenThreads.dylib" $$TARGETDIR/qgroundcontrol.app/Contents/MacOS/qgroundcontrol @@ -164,11 +164,11 @@ macx|macx-g++42|macx-g++: { # Include OpenSceneGraph libraries INCLUDEPATH += -framework GLUT \ -framework Cocoa \ - $$BASEDIR/lib/mac32/include + $$BASEDIR/lib/mac64/include LIBS += -framework GLUT \ -framework Cocoa \ - -L$$BASEDIR/lib/mac32/lib \ + -L$$BASEDIR/lib/mac64/lib \ -lOpenThreads \ -losg \ -losgViewer \ @@ -178,6 +178,18 @@ macx|macx-g++42|macx-g++: { -losgWidget #} + exists(/usr/local/include/google/protobuf) { + message("Building support for Protocol Buffers") + DEPENDENCIES_PRESENT += protobuf + # Include Protocol Buffers libraries + LIBS += -L/usr/local/lib \ + -lprotobuf \ + -lprotobuf-lite \ + -lprotoc + + DEFINES += QGC_PROTOBUF_ENABLED + } + exists(/opt/local/include/libfreenect)|exists(/usr/local/include/libfreenect) { message("Building support for libfreenect") DEPENDENCIES_PRESENT += libfreenect diff --git a/src/input/JoystickInput.cc b/src/input/JoystickInput.cc index 01d6e4f..0e7dea9 100644 --- a/src/input/JoystickInput.cc +++ b/src/input/JoystickInput.cc @@ -1,24 +1,4 @@ /*===================================================================== - -PIXHAWK Micro Air Vehicle Flying Robotics Toolkit - -(c) 2009, 2010 PIXHAWK PROJECT - -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 . - ======================================================================*/ /** @@ -44,17 +24,17 @@ This file is part of the PIXHAWK project * @image html http://pixhawk.ethz.ch/wiki/_media/standards/body-frame.png Aeronautical frame */ JoystickInput::JoystickInput() : - sdlJoystickMin(-32768.0f), - sdlJoystickMax(32767.0f), - defaultIndex(0), - uas(NULL), - uasButtonList(QList()), - done(false), - thrustAxis(2), - xAxis(0), - yAxis(1), - yawAxis(3), - joystickName(tr("Unitinialized")) + sdlJoystickMin(-32768.0f), + sdlJoystickMax(32767.0f), + defaultIndex(0), + uas(NULL), + uasButtonList(QList()), + done(false), + thrustAxis(2), + xAxis(0), + yAxis(1), + yawAxis(3), + joystickName(tr("Unitinialized")) { for (int i = 0; i < 10; i++) { calibrationPositive[i] = sdlJoystickMax; @@ -69,12 +49,12 @@ JoystickInput::JoystickInput() : JoystickInput::~JoystickInput() { - { - QMutexLocker locker(&this->m_doneMutex); - done = true; - } - this->wait(); - this->deleteLater(); + done = true; + while (done) + { + QGC::SLEEP::usleep(5000); + } + this->deleteLater(); } @@ -82,9 +62,11 @@ void JoystickInput::setActiveUAS(UASInterface* uas) { // Only connect / disconnect is the UAS is of a controllable UAS class UAS* tmp = 0; - if (this->uas) { + if (this->uas) + { tmp = dynamic_cast(this->uas); - if(tmp) { + if(tmp) + { disconnect(this, SIGNAL(joystickChanged(double,double,double,double,int,int)), tmp, SLOT(setManualControlCommands(double,double,double,double))); disconnect(this, SIGNAL(buttonPressed(int)), tmp, SLOT(receiveButton(int))); } @@ -97,7 +79,8 @@ void JoystickInput::setActiveUAS(UASInterface* uas) connect(this, SIGNAL(joystickChanged(double,double,double,double,int,int)), tmp, SLOT(setManualControlCommands(double,double,double,double))); connect(this, SIGNAL(buttonPressed(int)), tmp, SLOT(receiveButton(int))); } - if (!isRunning()) { + if (!isRunning()) + { start(); } } @@ -113,17 +96,20 @@ void JoystickInput::init() int numJoysticks = SDL_NumJoysticks(); // Wait for joysticks if none is connected - while (numJoysticks == 0) { - MG::SLEEP::msleep(200); + while (numJoysticks == 0) + { + MG::SLEEP::msleep(800); // INITIALIZE SDL Joystick support - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) { + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) + { printf("Couldn't initialize SimpleDirectMediaLayer: %s\n", SDL_GetError()); } numJoysticks = SDL_NumJoysticks(); } printf("%d Input devices found:\n", numJoysticks); - for(int i=0; i < SDL_NumJoysticks(); i++ ) { + for(int i=0; i < SDL_NumJoysticks(); i++ ) + { printf("\t- %s\n", SDL_JoystickName(i)); joystickName = QString(SDL_JoystickName(i)); } @@ -147,16 +133,14 @@ void JoystickInput::run() init(); forever - { - { - QMutexLocker locker(&this->m_doneMutex); - if(done) - { - done = false; - break; - } - } - while(SDL_PollEvent(&event)) { + { + if (done) + { + done = false; + exit(); + } + while(SDL_PollEvent(&event)) + { SDL_JoystickUpdate(); @@ -197,7 +181,8 @@ void JoystickInput::run() } // Display all axes - for(int i = 0; i < SDL_JoystickNumAxes(joystick); i++) { + for(int i = 0; i < SDL_JoystickNumAxes(joystick); i++) + { //qDebug() << "\rAXIS" << i << "is: " << SDL_JoystickGetAxis(joystick, i); } @@ -268,15 +253,19 @@ void JoystickInput::run() // Display all buttons - for(int i = 0; i < SDL_JoystickNumButtons(joystick); i++) { + for(int i = 0; i < SDL_JoystickNumButtons(joystick); i++) + { //qDebug() << "BUTTON" << i << "is: " << SDL_JoystickGetAxis(joystick, i); - if(SDL_JoystickGetButton(joystick, i)) { + if(SDL_JoystickGetButton(joystick, i)) + { emit buttonPressed(i); // Check if button is a UAS select button - if (uasButtonList.contains(i)) { + if (uasButtonList.contains(i)) + { UASInterface* uas = UASManager::instance()->getUASForId(i); - if (uas) { + if (uas) + { UASManager::instance()->setActiveUAS(uas); } } diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 7c8aa43..8053f13 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -185,6 +185,38 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) // qDebug() << __FILE__ << __LINE__ << "ADDED LINK!" << link->getName(); } + if (!components.contains(message.compid)) + { + QString componentName; + + switch (message.compid) + { + case MAV_COMP_ID_ALL: + { + componentName = "ANONYMOUS"; + break; + } + case MAV_COMP_ID_IMU: + { + componentName = "IMU #1"; + break; + } + case MAV_COMP_ID_CAMERA: + { + componentName = "CAMERA"; + break; + } + case MAV_COMP_ID_MISSIONPLANNER: + { + componentName = "MISSIONPLANNER"; + break; + } + } + + components.insert(message.compid, componentName); + emit componentCreated(uasId, message.compid, componentName); + } + // qDebug() << "UAS RECEIVED from" << message.sysid << "component" << message.compid << "msg id" << message.msgid << "seq no" << message.seq; // Only accept messages from this system (condition 1) @@ -2261,15 +2293,17 @@ void UAS::removeLink(QObject* object) } } -/** - * @brief Get the links associated with this robot - * - **/ + QList* UAS::getLinks() { return links; } +QMap UAS::getComponents() +{ + return components; +} + void UAS::setBattery(BatteryType type, int cells) diff --git a/src/uas/UAS.h b/src/uas/UAS.h index 093122d..c514973 100644 --- a/src/uas/UAS.h +++ b/src/uas/UAS.h @@ -81,6 +81,9 @@ public: int getAirframe() const { return airframe; } + /** @brief Get the components */ + QMap getComponents(); + /** @brief The time interval the robot is switched on */ quint64 getUptime() const; /** @brief Get the status flag for the communication */ @@ -90,13 +93,16 @@ public: /** @brief Get the links associated with this robot */ QList* getLinks(); - double getLocalX() const { + double getLocalX() const + { return localX; } - double getLocalY() const { + double getLocalY() const + { return localY; } - double getLocalZ() const { + double getLocalZ() const + { return localZ; } double getLatitude() const { @@ -160,6 +166,7 @@ protected: //COMMENTS FOR TEST UNIT QList motorValues; QList motorNames; + QMap components; ///< IDs and names of all detected onboard components double thrustSum; ///< Sum of forward/up thrust of all thrust actuators, in Newtons double thrustMax; ///< Maximum forward/up thrust of this vehicle, in Newtons diff --git a/src/uas/UASInterface.h b/src/uas/UASInterface.h index 07e193f..f929af8 100644 --- a/src/uas/UASInterface.h +++ b/src/uas/UASInterface.h @@ -198,9 +198,12 @@ public: /** @brief Get the type of the autopilot (PIXHAWK, APM, UDB, PPZ,..) */ virtual int getAutopilotType() = 0; virtual QString getAutopilotTypeName() = 0; - virtual void setAutopilotType(int apType)= 0; + virtual void setAutopilotType(int apType) = 0; - QColor getColor() { + virtual QMap getComponents() = 0; + + QColor getColor() + { return color; } @@ -315,8 +318,10 @@ protected: QColor color; signals: - /** @brief The robot state has changed **/ + /** @brief The robot state has changed */ void statusChanged(int stateFlag); + /** @brief A new component was detected or created */ + void componentCreated(int uas, int component, const QString& name); /** @brief The robot state has changed * * @param uas this robot diff --git a/src/uas/UASManager.cc b/src/uas/UASManager.cc index 7c247f5..08d82c4 100644 --- a/src/uas/UASManager.cc +++ b/src/uas/UASManager.cc @@ -258,13 +258,15 @@ void UASManager::addUAS(UASInterface* uas) // returns the UAS once the UASCreated() signal // is emitted. The code is thus NOT redundant. bool firstUAS = false; - if (activeUAS == NULL) { + if (activeUAS == NULL) + { firstUAS = true; activeUAS = uas; } // Only execute if there is no UAS at this index - if (!systems.contains(uas)) { + if (!systems.contains(uas)) + { systems.append(uas); connect(uas, SIGNAL(destroyed(QObject*)), this, SLOT(removeUAS(QObject*))); // Set home position on UAV if set in UI @@ -275,7 +277,8 @@ void UASManager::addUAS(UASInterface* uas) } // If there is no active UAS yet, set the first one as the active UAS - if (firstUAS) { + if (firstUAS) + { setActiveUAS(uas); } } diff --git a/src/ui/QGCMAVLinkInspector.cc b/src/ui/QGCMAVLinkInspector.cc index d4c353c..48cc8f0 100644 --- a/src/ui/QGCMAVLinkInspector.cc +++ b/src/ui/QGCMAVLinkInspector.cc @@ -2,6 +2,7 @@ #include "QGCMAVLink.h" #include "QGCMAVLinkInspector.h" +#include "UASManager.h" #include "ui_QGCMAVLinkInspector.h" #include @@ -11,12 +12,15 @@ const unsigned int QGCMAVLinkInspector::updateInterval = 1000U; QGCMAVLinkInspector::QGCMAVLinkInspector(MAVLinkProtocol* protocol, QWidget *parent) : QWidget(parent), + selectedSystemID(0), + selectedComponentID(0), ui(new Ui::QGCMAVLinkInspector) { ui->setupUi(this); /* Insert system */ - ui->systemComboBox->addItem(tr("All Systems"), -1); + ui->systemComboBox->addItem(tr("All Systems"), 0); + ui->componentComboBox->addItem(tr("All Components"), 0); mavlink_message_info_t msg[256] = MAVLINK_MESSAGE_INFO; memcpy(messageInfo, msg, sizeof(mavlink_message_info_t)*256); @@ -29,9 +33,62 @@ QGCMAVLinkInspector::QGCMAVLinkInspector(MAVLinkProtocol* protocol, QWidget *par header << tr("Type"); ui->treeWidget->setHeaderLabels(header); connect(&updateTimer, SIGNAL(timeout()), this, SLOT(refreshView())); + + + // ARM UI + connect(ui->systemComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectDropDownMenuSystem(int))); + connect(ui->componentComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectDropDownMenuComponent(int))); + + // ARM external connections + connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addSystem(UASInterface*))); + + // Start updateTimer.start(updateInterval); } +void QGCMAVLinkInspector::addSystem(UASInterface* uas) +{ + ui->systemComboBox->addItem(uas->getUASName(), uas->getUASID()); +} + +void QGCMAVLinkInspector::selectDropDownMenuSystem(int dropdownid) +{ + selectedSystemID = ui->systemComboBox->itemData(dropdownid).toInt(); + rebuildComponentList(); +} + +void QGCMAVLinkInspector::selectDropDownMenuComponent(int dropdownid) +{ + selectedComponentID = ui->componentComboBox->itemData(dropdownid).toInt(); +} + +void QGCMAVLinkInspector::rebuildComponentList() +{ + ui->componentComboBox->clear(); + + // Fill + UASInterface* uas = UASManager::instance()->getUASForId(selectedSystemID); + if (uas) + { + QMap components = uas->getComponents(); + + foreach (int id, components.keys()) + { + QString name = components.value(id); + ui->componentComboBox->addItem(name, id); + } + } +} + +void QGCMAVLinkInspector::addComponent(int uas, int component, const QString& name) +{ + Q_UNUSED(component); + Q_UNUSED(name); + if (uas != selectedSystemID) return; + + rebuildComponentList(); +} + void QGCMAVLinkInspector::refreshView() { for (int i = 0; i < 256; ++i)//mavlink_message_t msg, receivedMessages) @@ -76,6 +133,8 @@ void QGCMAVLinkInspector::refreshView() void QGCMAVLinkInspector::receiveMessage(LinkInterface* link,mavlink_message_t message) { Q_UNUSED(link); + if (selectedSystemID != 0 && selectedSystemID != message.sysid) return; + if (selectedComponentID != 0 && selectedComponentID != message.compid) return; // Only overwrite if system filter is set memcpy(receivedMessages+message.msgid, &message, sizeof(mavlink_message_t)); diff --git a/src/ui/QGCMAVLinkInspector.h b/src/ui/QGCMAVLinkInspector.h index 4623b24..cf7cbe7 100644 --- a/src/ui/QGCMAVLinkInspector.h +++ b/src/ui/QGCMAVLinkInspector.h @@ -12,6 +12,7 @@ namespace Ui { } class QTreeWidgetItem; +class UASInterface; class QGCMAVLinkInspector : public QWidget { @@ -24,8 +25,16 @@ public: public slots: void receiveMessage(LinkInterface* link,mavlink_message_t message); void refreshView(); + void addSystem(UASInterface* uas); + void addComponent(int uas, int component, const QString& name); + /** @Brief Select a system through the drop down menu */ + void selectDropDownMenuSystem(int dropdownid); + /** @Brief Select a component through the drop down menu */ + void selectDropDownMenuComponent(int dropdownid); protected: + int selectedSystemID; ///< Currently selected system + int selectedComponentID; ///< Currently selected component QMap lastMessageUpdate; ///< Used to switch between highlight and non-highlighting color QMap messagesHz; ///< Used to store update rate in Hz QMap messageCount; ///< Used to store the message count @@ -36,6 +45,8 @@ protected: // Update one message field void updateField(int msgid, int fieldid, QTreeWidgetItem* item); + /** @brief Rebuild the list of components */ + void rebuildComponentList(); static const unsigned int updateInterval; static const float updateHzLowpass; diff --git a/src/ui/QGCMAVLinkInspector.ui b/src/ui/QGCMAVLinkInspector.ui index 3d461ac..eff2dec 100644 --- a/src/ui/QGCMAVLinkInspector.ui +++ b/src/ui/QGCMAVLinkInspector.ui @@ -17,7 +17,7 @@ 6 - + @@ -29,13 +29,23 @@ - System Filter + System + + + + + + + Component + + +