diff --git a/QGCApplication.pro b/QGCApplication.pro index 5e606a094a50ed5cab9e760f3c62456eb93f1092..b579b4181ab4e4c30d175789b511d3a429008bf5 100644 --- a/QGCApplication.pro +++ b/QGCApplication.pro @@ -240,6 +240,7 @@ HEADERS += \ src/comm/TCPLink.h \ src/comm/UDPLink.h \ src/GAudioOutput.h \ + src/HomePositionManager.h \ src/LogCompressor.h \ src/MG.h \ src/QGC.h \ @@ -263,8 +264,6 @@ HEADERS += \ src/uas/FileManager.h \ src/uas/UAS.h \ src/uas/UASInterface.h \ - src/uas/UASManager.h \ - src/uas/UASManagerInterface.h \ src/uas/UASMessageHandler.h \ src/uas/UASWaypointManager.h \ src/ui/flightdisplay/FlightDisplay.h \ @@ -377,6 +376,7 @@ SOURCES += \ src/comm/TCPLink.cc \ src/comm/UDPLink.cc \ src/GAudioOutput.cc \ + src/HomePositionManager.cc \ src/LogCompressor.cc \ src/main.cc \ src/QGC.cc \ @@ -395,7 +395,6 @@ SOURCES += \ src/QmlControls/ScreenToolsController.cc \ src/uas/FileManager.cc \ src/uas/UAS.cc \ - src/uas/UASManager.cc \ src/uas/UASMessageHandler.cc \ src/uas/UASWaypointManager.cc \ src/ui/flightdisplay/FlightDisplay.cc \ diff --git a/src/uas/UASManager.cc b/src/HomePositionManager.cc similarity index 58% rename from src/uas/UASManager.cc rename to src/HomePositionManager.cc index b187b46dfa88fcfd0a47cf6f801dcb3749e4a352..a53209394855bf175117900aab1eb538b3b79ea4 100644 --- a/src/uas/UASManager.cc +++ b/src/HomePositionManager.cc @@ -1,12 +1,25 @@ -/*================================================================== -======================================================================*/ - -/** - * @file - * @brief Implementation of class UASManager - * @author Lorenz Meier - * - */ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + 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 . + + ======================================================================*/ #include #include @@ -15,7 +28,7 @@ #include "UAS.h" #include "UASInterface.h" -#include "UASManager.h" +#include "HomePositionManager.h" #include "QGC.h" #include "QGCMessageBox.h" #include "QGCApplication.h" @@ -25,26 +38,24 @@ #define MEAN_EARTH_DIAMETER 12756274.0 #define UMR 0.017453292519943295769236907684886 -IMPLEMENT_QGC_SINGLETON(UASManager, UASManagerInterface) +IMPLEMENT_QGC_SINGLETON(HomePositionManager, HomePositionManager) -UASManager::UASManager(QObject* parent) : - UASManagerInterface(parent), - offlineUASWaypointManager(NULL), +HomePositionManager::HomePositionManager(QObject* parent) : + QObject(parent), homeLat(47.3769), homeLon(8.549444), homeAlt(470.0), homeFrame(MAV_FRAME_GLOBAL) { loadSettings(); - setLocalNEDSafetyBorders(1, -1, 0, -1, 1, -1); } -UASManager::~UASManager() +HomePositionManager::~HomePositionManager() { storeSettings(); } -void UASManager::storeSettings() +void HomePositionManager::storeSettings() { QSettings settings; settings.beginGroup("QGC_UASMANAGER"); @@ -54,7 +65,7 @@ void UASManager::storeSettings() settings.endGroup(); } -void UASManager::loadSettings() +void HomePositionManager::loadSettings() { QSettings settings; settings.beginGroup("QGC_UASMANAGER"); @@ -72,7 +83,7 @@ void UASManager::loadSettings() settings.endGroup(); } -bool UASManager::setHomePosition(double lat, double lon, double alt) +bool HomePositionManager::setHomePosition(double lat, double lon, double alt) { // Checking for NaN and infitiny // and checking for borders @@ -101,7 +112,7 @@ bool UASManager::setHomePosition(double lat, double lon, double alt) return changed; } -bool UASManager::setHomePositionAndNotify(double lat, double lon, double alt) +bool HomePositionManager::setHomePositionAndNotify(double lat, double lon, double alt) { // Checking for NaN and infitiny // and checking for borders @@ -114,28 +125,7 @@ bool UASManager::setHomePositionAndNotify(double lat, double lon, double alt) return changed; } -/** - * @param x1 Point 1 coordinate in x dimension - * @param y1 Point 1 coordinate in y dimension - * @param z1 Point 1 coordinate in z dimension - * - * @param x2 Point 2 coordinate in x dimension - * @param y2 Point 2 coordinate in y dimension - * @param z2 Point 2 coordinate in z dimension - */ -void UASManager::setLocalNEDSafetyBorders(double x1, double y1, double z1, double x2, double y2, double z2) -{ - nedSafetyLimitPosition1.x() = x1; - nedSafetyLimitPosition1.y() = y1; - nedSafetyLimitPosition1.z() = z1; - - nedSafetyLimitPosition2.x() = x2; - nedSafetyLimitPosition2.y() = y2; - nedSafetyLimitPosition2.z() = z2; -} - - -void UASManager::initReference(const double & latitude, const double & longitude, const double & altitude) +void HomePositionManager::initReference(const double & latitude, const double & longitude, const double & altitude) { Eigen::Matrix3d R; double s_long, s_lat, c_long, c_lat; @@ -159,7 +149,7 @@ void UASManager::initReference(const double & latitude, const double & longitude ecef_ref_point_ = wgs84ToEcef(latitude, longitude, altitude); } -Eigen::Vector3d UASManager::wgs84ToEcef(const double & latitude, const double & longitude, const double & altitude) +Eigen::Vector3d HomePositionManager::wgs84ToEcef(const double & latitude, const double & longitude, const double & altitude) { const double a = 6378137.0; // semi-major axis const double e_sq = 6.69437999014e-3; // first eccentricity squared @@ -179,12 +169,12 @@ Eigen::Vector3d UASManager::wgs84ToEcef(const double & latitude, const double & return ecef; } -Eigen::Vector3d UASManager::ecefToEnu(const Eigen::Vector3d & ecef) +Eigen::Vector3d HomePositionManager::ecefToEnu(const Eigen::Vector3d & ecef) { return ecef_ref_orientation_ * (ecef - ecef_ref_point_); } -void UASManager::wgs84ToEnu(const double& lat, const double& lon, const double& alt, double* east, double* north, double* up) +void HomePositionManager::wgs84ToEnu(const double& lat, const double& lon, const double& alt, double* east, double* north, double* up) { Eigen::Vector3d ecef = wgs84ToEcef(lat, lon, alt); Eigen::Vector3d enu = ecefToEnu(ecef); @@ -193,49 +183,17 @@ void UASManager::wgs84ToEnu(const double& lat, const double& lon, const double& *up = enu.z(); } -//void UASManager::wgs84ToNed(const double& lat, const double& lon, const double& alt, double* north, double* east, double* down) -//{ - -//} - - - -void UASManager::enuToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt) +void HomePositionManager::enuToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt) { *lat=homeLat+y/MEAN_EARTH_DIAMETER*360./PI; *lon=homeLon+x/MEAN_EARTH_DIAMETER*360./PI/cos(homeLat*UMR); *alt=homeAlt+z; } -void UASManager::nedToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt) +void HomePositionManager::nedToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt) { *lat=homeLat+x/MEAN_EARTH_DIAMETER*360./PI; *lon=homeLon+y/MEAN_EARTH_DIAMETER*360./PI/cos(homeLat*UMR); *alt=homeAlt-z; } - -/** - * This function will change QGC's home position on a number of conditions only - */ -void UASManager::uavChangedHomePosition(int uav, double lat, double lon, double alt) -{ - // Accept home position changes from the active UAS - if (uav == MultiVehicleManager::instance()->activeVehicle()->id()) - { - if (setHomePosition(lat, lon, alt)) - { - // XXX DO NOT UPDATE THE WHOLE FLEET - - -// foreach (UASInterface* mav, systems) -// { -// // Only update the other systems, not the original source -// if (mav->getUASID() != uav) -// { -// mav->setHomePosition(homeLat, homeLon, homeAlt); -// } -// } - } - } -} diff --git a/src/uas/UASManager.h b/src/HomePositionManager.h similarity index 60% rename from src/uas/UASManager.h rename to src/HomePositionManager.h index 0f47129ebc40f53ce36c62103784935da095db92..e45500f34a46137883452d64b2183d7bb2ea8f06 100644 --- a/src/uas/UASManager.h +++ b/src/HomePositionManager.h @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station -(c) 2009 - 2011 QGROUNDCONTROL PROJECT +(c) 2009 - 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project @@ -21,17 +21,9 @@ This file is part of the QGROUNDCONTROL project ======================================================================*/ -/** - * @file - * @brief Definition of class UASManager - * @author Lorenz Meier - * - */ - #ifndef _UASMANAGER_H_ #define _UASMANAGER_H_ -#include "UASManagerInterface.h" #include "UASInterface.h" #include @@ -42,17 +34,13 @@ This file is part of the QGROUNDCONTROL project #include "QGCGeo.h" #include "QGCSingleton.h" -/** - * @brief Central manager for all connected aerial vehicles - * - * This class keeps a list of all connected / configured UASs. It also stores which - * UAS is currently select with respect to user input or manual controls. - **/ -class UASManager : public UASManagerInterface +/// Manages an offline home position as well as performance coordinate transformations +/// around a home position. +class HomePositionManager : public QObject { Q_OBJECT - DECLARE_QGC_SINGLETON(UASManager, UASManagerInterface) + DECLARE_QGC_SINGLETON(HomePositionManager, HomePositionManager) public: /** @brief Get home position latitude */ @@ -85,40 +73,6 @@ public: /** @brief Convert x,y,z coordinates to lat / lon / alt coordinates in north-east-down frame */ void nedToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt); - void getLocalNEDSafetyLimits(double* x1, double* y1, double* z1, double* x2, double* y2, double* z2) - { - *x1 = nedSafetyLimitPosition1.x(); - *y1 = nedSafetyLimitPosition1.y(); - *z1 = nedSafetyLimitPosition1.z(); - - *x2 = nedSafetyLimitPosition2.x(); - *y2 = nedSafetyLimitPosition2.y(); - *z2 = nedSafetyLimitPosition2.z(); - } - - /** @brief Check if a position is in the local NED safety limits */ - bool isInLocalNEDSafetyLimits(double x, double y, double z) - { - if (x < nedSafetyLimitPosition1.x() && - y > nedSafetyLimitPosition1.y() && - z < nedSafetyLimitPosition1.z() && - x > nedSafetyLimitPosition2.x() && - y < nedSafetyLimitPosition2.y() && - z > nedSafetyLimitPosition2.z()) - { - // Within limits - return true; - } - else - { - // Not within limits - return false; - } - } - -// void wgs84ToNed(const double& lat, const double& lon, const double& alt, double* north, double* east, double* down); - - public slots: /** @brief Set the current home position, but do not change it on the UAVs */ bool setHomePosition(double lat, double lon, double alt); @@ -126,35 +80,30 @@ public slots: /** @brief Set the current home position on all UAVs*/ bool setHomePositionAndNotify(double lat, double lon, double alt); - /** @brief Set the safety limits in local position frame */ - void setLocalNEDSafetyBorders(double x1, double y1, double z1, double x2, double y2, double z2); - - /** @brief Update home position based on the position from one of the UAVs */ - void uavChangedHomePosition(int uav, double lat, double lon, double alt); /** @brief Load settings */ void loadSettings(); /** @brief Store settings */ void storeSettings(); - +signals: + /** @brief Current home position changed */ + void homePositionChanged(double lat, double lon, double alt); + protected: - UASWaypointManager *offlineUASWaypointManager; double homeLat; double homeLon; double homeAlt; int homeFrame; Eigen::Quaterniond ecef_ref_orientation_; Eigen::Vector3d ecef_ref_point_; - Eigen::Vector3d nedSafetyLimitPosition1; - Eigen::Vector3d nedSafetyLimitPosition2; void initReference(const double & latitude, const double & longitude, const double & altitude); private: - /// @brief All access to UASManager singleton is through UASManager::instance - UASManager(QObject* parent = NULL); - ~UASManager(); + /// @brief All access to HomePositionManager singleton is through HomePositionManager::instance + HomePositionManager(QObject* parent = NULL); + ~HomePositionManager(); public: /* Need to align struct pointer to prevent a memory assertion: diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index f4f42243d87936da74e774ce181d4aebb81dce18..62bb9cd20a52eed7356e24cab43154c660860681 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -63,7 +63,7 @@ G_END_DECLS #endif #include "QGCSingleton.h" #include "LinkManager.h" -#include "UASManager.h" +#include "HomePositionManager.h" #include "UASMessageHandler.h" #include "AutoPilotPluginManager.h" #include "QGCTemporaryFile.h" @@ -602,21 +602,21 @@ void QGCApplication::_createSingletons(void) Q_ASSERT(linkManager); // Needs LinkManager - UASManagerInterface* uasManager = UASManager::_createSingleton(); + HomePositionManager* uasManager = HomePositionManager::_createSingleton(); Q_UNUSED(uasManager); Q_ASSERT(uasManager); - // Need UASManager + // Need HomePositionManager AutoPilotPluginManager* pluginManager = AutoPilotPluginManager::_createSingleton(); Q_UNUSED(pluginManager); Q_ASSERT(pluginManager); - // Need UASManager + // Need HomePositionManager UASMessageHandler* messageHandler = UASMessageHandler::_createSingleton(); Q_UNUSED(messageHandler); Q_ASSERT(messageHandler); - // Needs UASManager + // Needs HomePositionManager FactSystem* factSystem = FactSystem::_createSingleton(); Q_UNUSED(factSystem); Q_ASSERT(factSystem); @@ -648,7 +648,7 @@ void QGCApplication::_destroySingletons(void) FactSystem::_deleteSingleton(); UASMessageHandler::_deleteSingleton(); AutoPilotPluginManager::_deleteSingleton(); - UASManager::_deleteSingleton(); + HomePositionManager::_deleteSingleton(); LinkManager::_deleteSingleton(); GAudioOutput::_deleteSingleton(); MultiVehicleManager::_deleteSingleton(); diff --git a/src/QGCSingleton.h b/src/QGCSingleton.h index 809022fe69892357a602a550a27e7ca287529293..3b07d2f7dfe3ff1d866a60b8b23d311b019df2fd 100644 --- a/src/QGCSingleton.h +++ b/src/QGCSingleton.h @@ -36,7 +36,6 @@ /// Include this macro in your Derived Class definition /// @param className Derived Class name /// @param interfaceName If your class is accessed through an interface specify that, if not specify Derived class name. -/// For example DECLARE_QGC_SINGLETON(UASManager, UASManagerInterface) #define DECLARE_QGC_SINGLETON(className, interfaceName) \ public: \ static interfaceName* instance(bool nullOk = false); \ @@ -54,7 +53,6 @@ /// Include this macro in your Derived Class implementation /// @param className Derived Class name /// @param interfaceName If your class is accessed through an interface specify that, if not specify Derived class name. -/// For example DECLARE_QGC_SINGLETON(UASManager, UASManagerInterface) #define IMPLEMENT_QGC_SINGLETON(className, interfaceName) \ interfaceName* className::_instance = NULL; \ interfaceName* className::_mockInstance = NULL; \ @@ -114,7 +112,7 @@ class UnitTest; /// This is done in order to make sure they are all created on the main thread. As such no other code other than Unit Test /// code has access to the constructor/destructor. QGCSingleton supports replacing singletons with a mock implementation. /// In this case your object must derive from an interface which in turn derives from QGCSingleton. Youu can then use -/// the setMock method to add and remove you mock implementation. See UASManager example usage. In order to provide the +/// the setMock method to add and remove you mock implementation. See HomePositionManager example usage. In order to provide the /// appropriate methods to make all this work you need to use the DECLARE_QGC_SINGLETON and IMPLEMENT_QGC_SINGLETON /// macros as follows: /// @code{.unparsed} diff --git a/src/VehicleSetup/SetupView.cc b/src/VehicleSetup/SetupView.cc index 7abd562a0dd8331e199716aa093c89e2cfdfbb47..2bb35a81791de8d8fe269d88e441e495ee439276 100644 --- a/src/VehicleSetup/SetupView.cc +++ b/src/VehicleSetup/SetupView.cc @@ -26,7 +26,6 @@ #include "SetupView.h" -#include "UASManager.h" #include "AutoPilotPluginManager.h" #include "VehicleComponent.h" #include "QGCQmlWidgetHolder.h" diff --git a/src/VehicleSetup/SetupViewTest.cc b/src/VehicleSetup/SetupViewTest.cc index c7f05e60f4557e043329d364df299b5ad30c1e55..a9b58f8a2065998d6bf27fb79554a52be6ff99a2 100644 --- a/src/VehicleSetup/SetupViewTest.cc +++ b/src/VehicleSetup/SetupViewTest.cc @@ -28,7 +28,6 @@ #include "MockLink.h" #include "QGCMessageBox.h" #include "SetupView.h" -#include "UASManager.h" #include "MultiVehicleManager.h" UT_REGISTER_TEST(SetupViewTest) diff --git a/src/ViewWidgets/CustomCommandWidgetController.h b/src/ViewWidgets/CustomCommandWidgetController.h index 1b713e2d86b5413cd07f6d123719aed80c71994d..63a67a2b8b22fc1367621912ed841120a70be650 100644 --- a/src/ViewWidgets/CustomCommandWidgetController.h +++ b/src/ViewWidgets/CustomCommandWidgetController.h @@ -28,7 +28,6 @@ #include "UASInterface.h" #include "AutoPilotPlugin.h" -#include "UASManagerInterface.h" #include "FactPanelController.h" class CustomCommandWidgetController : public FactPanelController diff --git a/src/ViewWidgets/ViewWidgetController.cc b/src/ViewWidgets/ViewWidgetController.cc index fb5a30799b62c798c6dd827e40f5192ac1d50249..71295f244f179a520d5d812f6db028e0dba3047c 100644 --- a/src/ViewWidgets/ViewWidgetController.cc +++ b/src/ViewWidgets/ViewWidgetController.cc @@ -22,7 +22,6 @@ ======================================================================*/ #include "ViewWidgetController.h" -#include "UASManager.h" #include "MultiVehicleManager.h" ViewWidgetController::ViewWidgetController(void) : diff --git a/src/ViewWidgets/ViewWidgetController.h b/src/ViewWidgets/ViewWidgetController.h index 70f9c36d887de9456f47c76dc3359c2ad80373e2..4b8bc30a1007779502902dd01cbbae26e311d9c4 100644 --- a/src/ViewWidgets/ViewWidgetController.h +++ b/src/ViewWidgets/ViewWidgetController.h @@ -28,7 +28,6 @@ #include "UASInterface.h" #include "AutoPilotPlugin.h" -#include "UASManagerInterface.h" #include "Vehicle.h" class ViewWidgetController : public QObject diff --git a/src/comm/QGCFlightGearLink.cc b/src/comm/QGCFlightGearLink.cc index 68e8d9d5d4ed5a0a59f4b2225a64447f2e9f5053..2945c1d0eb4c4c546732952aa81dca38db99f9f9 100644 --- a/src/comm/QGCFlightGearLink.cc +++ b/src/comm/QGCFlightGearLink.cc @@ -43,6 +43,7 @@ This file is part of the QGROUNDCONTROL project #include "QGC.h" #include "QGCFileDialog.h" #include "QGCMessageBox.h" +#include "HomePositionManager.h" // FlightGear _fgProcess start and connection is quite fragile. Uncomment the define below to get higher level of debug output // for tracking down problems. @@ -954,11 +955,11 @@ bool QGCFlightGearLink::connectSimulation() } // We start out at our home position - _fgArgList << QString("--lat=%1").arg(UASManager::instance()->getHomeLatitude()); - _fgArgList << QString("--lon=%1").arg(UASManager::instance()->getHomeLongitude()); + _fgArgList << QString("--lat=%1").arg(HomePositionManager::instance()->getHomeLatitude()); + _fgArgList << QString("--lon=%1").arg(HomePositionManager::instance()->getHomeLongitude()); // The altitude is not set because an altitude not equal to the ground altitude leads to a non-zero default throttle in flightgear // Without the altitude-setting the aircraft is positioned on the ground - //_fgArgList << QString("--altitude=%1").arg(UASManager::instance()->getHomeAltitude()); + //_fgArgList << QString("--altitude=%1").arg(HomePositionManager::instance()->getHomeAltitude()); #ifdef DEBUG_FLIGHTGEAR_CONNECT // This tell FlightGear to output highest debug level of log output. Handy for debuggin failures by looking at the FG diff --git a/src/comm/QGCXPlaneLink.cc b/src/comm/QGCXPlaneLink.cc index a40e260330f48c5b25ad4d5a7e532379eb8912cf..21718d63b8dc7d0d67d0fd633497c0357b337531 100644 --- a/src/comm/QGCXPlaneLink.cc +++ b/src/comm/QGCXPlaneLink.cc @@ -40,6 +40,7 @@ This file is part of the QGROUNDCONTROL project #include "UAS.h" #include "UASInterface.h" #include "QGCMessageBox.h" +#include "HomePositionManager.h" QGCXPlaneLink::QGCXPlaneLink(UASInterface* mav, QString remoteHost, QHostAddress localHost, quint16 localPort) : mav(mav), diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 505efb0b2a0bceb525defc42b9105f60ac801b54..09122de81dcdd30a39e5ae9173cfa66085ed931e 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -23,7 +23,7 @@ #include "UAS.h" #include "LinkInterface.h" -#include "UASManager.h" +#include "HomePositionManager.h" #include "QGC.h" #include "GAudioOutput.h" #include "MAVLinkProtocol.h" @@ -2672,10 +2672,10 @@ void UAS::home() { mavlink_message_t msg; - double latitude = UASManager::instance()->getHomeLatitude(); - double longitude = UASManager::instance()->getHomeLongitude(); - double altitude = UASManager::instance()->getHomeAltitude(); - int frame = UASManager::instance()->getHomeFrame(); + double latitude = HomePositionManager::instance()->getHomeLatitude(); + double longitude = HomePositionManager::instance()->getHomeLongitude(); + double altitude = HomePositionManager::instance()->getHomeAltitude(); + int frame = HomePositionManager::instance()->getHomeFrame(); mavlink_msg_command_long_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, uasId, MAV_COMP_ID_ALL, MAV_CMD_OVERRIDE_GOTO, 1, MAV_GOTO_DO_CONTINUE, MAV_GOTO_HOLD_AT_CURRENT_POSITION, frame, 0, latitude, longitude, altitude); _vehicle->sendMessage(msg); diff --git a/src/uas/UASManagerInterface.h b/src/uas/UASManagerInterface.h deleted file mode 100644 index dd93988cf54af94585a7a38507e4d953b3c55a7a..0000000000000000000000000000000000000000 --- a/src/uas/UASManagerInterface.h +++ /dev/null @@ -1,89 +0,0 @@ -/*===================================================================== - - QGroundControl Open Source Ground Control Station - - (c) 2009 - 2014 QGROUNDCONTROL PROJECT - - 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 . - - ======================================================================*/ - -/** - * @file - * @brief Definition of class UASManager - * @author Lorenz Meier - * - */ - -#ifndef _UASMANAGERINTERFACE_H_ -#define _UASMANAGERINTERFACE_H_ - -#include -#include - -#include - -#include "UASInterface.h" -#include "QGCGeo.h" -#include "QGCSingleton.h" - -/** - * @brief Central manager for all connected aerial vehicles - * - * This class keeps a list of all connected / configured UASs. It also stores which - * UAS is currently select with respect to user input or manual controls. - * - * This is the abstract base class for UASManager. Although there is normally only - * a single UASManger we still use a abstract base interface since this allows us - * to create mock versions of the UASManager for testing purposes. - * - * See UASManager.h for method documentation - **/ -class UASManagerInterface : public QGCSingleton -{ - Q_OBJECT - -public: - virtual double getHomeLatitude() const = 0; - virtual double getHomeLongitude() const = 0; - virtual double getHomeAltitude() const = 0; - virtual int getHomeFrame() const = 0; - virtual Eigen::Vector3d wgs84ToEcef(const double & latitude, const double & longitude, const double & altitude) = 0; - virtual Eigen::Vector3d ecefToEnu(const Eigen::Vector3d & ecef) = 0; - virtual void wgs84ToEnu(const double& lat, const double& lon, const double& alt, double* east, double* north, double* up) = 0; - virtual void enuToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt) = 0; - virtual void nedToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt) = 0; - virtual void getLocalNEDSafetyLimits(double* x1, double* y1, double* z1, double* x2, double* y2, double* z2) = 0; - virtual bool isInLocalNEDSafetyLimits(double x, double y, double z) = 0; - -public slots: - virtual bool setHomePosition(double lat, double lon, double alt) = 0; - virtual bool setHomePositionAndNotify(double lat, double lon, double alt) = 0; - virtual void setLocalNEDSafetyBorders(double x1, double y1, double z1, double x2, double y2, double z2) = 0; - virtual void uavChangedHomePosition(int uav, double lat, double lon, double alt) = 0; - virtual void loadSettings() = 0; - virtual void storeSettings() = 0; - -signals: - /** @brief Current home position changed */ - void homePositionChanged(double lat, double lon, double alt); - -protected: - UASManagerInterface(QObject* parent = NULL) : - QGCSingleton(parent) { } -}; - -#endif // _UASMANAGERINTERFACE_H_ diff --git a/src/uas/UASWaypointManager.cc b/src/uas/UASWaypointManager.cc index 82e657058b29d04cda55626e92b6114afa1b696e..3622773040a59b5fcb59a467de86073737aa017a 100644 --- a/src/uas/UASWaypointManager.cc +++ b/src/uas/UASWaypointManager.cc @@ -32,7 +32,7 @@ This file is part of the QGROUNDCONTROL project #include "UASWaypointManager.h" #include "UAS.h" #include "mavlink_types.h" -#include "UASManager.h" +#include "HomePositionManager.h" #include "QGCMessageBox.h" #include "Vehicle.h" @@ -1164,7 +1164,7 @@ float UASWaypointManager::getAltitudeRecommendation() if (waypointsEditable.count() > 0) { return waypointsEditable.last()->getAltitude(); } else { - return UASManager::instance()->getHomeAltitude() + getHomeAltitudeOffsetDefault(); + return HomePositionManager::instance()->getHomeAltitude() + getHomeAltitudeOffsetDefault(); } } diff --git a/src/ui/HSIDisplay.cc b/src/ui/HSIDisplay.cc index 9c9d3567b81a28e75c8aaf82a61da70cb641a328..7f2b73dfe85d6eab4ac8a29e07cb4bc52fb0fcad 100644 --- a/src/ui/HSIDisplay.cc +++ b/src/ui/HSIDisplay.cc @@ -38,7 +38,7 @@ This file is part of the QGROUNDCONTROL project #include #include "MultiVehicleManager.h" -#include "UASManager.h" +#include "HomePositionManager.h" #include "HSIDisplay.h" #include "QGC.h" #include "Waypoint.h" @@ -435,11 +435,6 @@ void HSIDisplay::renderOverlay() paintText(str, valueColor, 2.6f, 10, vheight - 4.0f, &painter); } - // Draw Safety - double x1, y1, z1, x2, y2, z2; - UASManager::instance()->getLocalNEDSafetyLimits(&x1, &y1, &z1, &x2, &y2, &z2); - // drawSafetyArea(QPointF(x1, y1), QPointF(x2, y2), QGC::colorYellow, painter); - // Draw status message paintText(statusMessage, statusColor, 2.8f, 8, 15, &painter); @@ -1372,7 +1367,7 @@ void HSIDisplay::drawWaypoints(QPainter& painter) // Transform the lat/lon for this waypoint into the local frame double e, n, u; - UASManager::instance()->wgs84ToEnu(w->getX(), w->getY(),w->getZ(), &e, &n, &u); + HomePositionManager::instance()->wgs84ToEnu(w->getX(), w->getY(),w->getZ(), &e, &n, &u); in = QPointF(n, e); } // Otherwise we don't process this waypoint. diff --git a/src/ui/MAVLinkDecoder.cc b/src/ui/MAVLinkDecoder.cc index 6fc661383adb94acfcc61b16621986a13660a2c8..be443803cfec48203b63673ba08fc0aa4b214810 100644 --- a/src/ui/MAVLinkDecoder.cc +++ b/src/ui/MAVLinkDecoder.cc @@ -1,5 +1,4 @@ #include "MAVLinkDecoder.h" -#include "UASManager.h" #include diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 1632c2cd119eee005b8e95c201d0c0e900f749e0..ad6f9bd9dbd6c4f4529f601d7945688bfb0e89c6 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -73,6 +73,7 @@ This file is part of the QGROUNDCONTROL project #include "QGCDockWidget.h" #include "MultiVehicleManager.h" #include "CustomCommandWidget.h" +#include "HomePositionManager.h" #ifdef UNITTEST_BUILD #include "QmlControls/QmlTestWidget.h" @@ -655,7 +656,7 @@ void MainWindow::closeEvent(QCloseEvent *event) _storeCurrentViewState(); storeSettings(); - UASManager::instance()->storeSettings(); + HomePositionManager::instance()->storeSettings(); event->accept(); } diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 6db461f3725fbd7e33aae5eff63825636ca28460..3c2140878a09588a0ae4813c4879c2f15890dd4b 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -41,7 +41,6 @@ This file is part of the QGROUNDCONTROL project #include "LinkManager.h" #include "LinkInterface.h" #include "UASInterface.h" -#include "UASManager.h" #include "UASControlWidget.h" #include "UASInfoWidget.h" #include "WaypointList.h" diff --git a/src/ui/WaypointList.cc b/src/ui/WaypointList.cc index 6f27aed458b0f8923b0e0c5a0a03f581c143ec94..5337c725f97b14aa3584cd82700487d793951497 100644 --- a/src/ui/WaypointList.cc +++ b/src/ui/WaypointList.cc @@ -37,7 +37,7 @@ This file is part of the PIXHAWK project #include #include -#include +#include #include #include #include @@ -314,8 +314,8 @@ void WaypointList::addEditable(bool onCurrentPosition) } else { updateStatusLabel(tr("Added default GLOBAL (Relative alt.) waypoint.")); } - wp = new Waypoint(0, UASManager::instance()->getHomeLatitude(), - UASManager::instance()->getHomeLongitude(), + wp = new Waypoint(0, HomePositionManager::instance()->getHomeLatitude(), + HomePositionManager::instance()->getHomeLongitude(), WPM->getAltitudeRecommendation(), 0, WPM->getAcceptanceRadiusRecommendation(), 0, 0,true, true, (MAV_FRAME)WPM->getFrameRecommendation(), MAV_CMD_NAV_WAYPOINT); WPM->addWaypointEditable(wp); } @@ -337,8 +337,8 @@ void WaypointList::addEditable(bool onCurrentPosition) { // MAV connected, but position unknown, add default waypoint updateStatusLabel(tr("WARNING: No position known. Adding default LOCAL (NED) waypoint")); - wp = new Waypoint(0, UASManager::instance()->getHomeLatitude(), - UASManager::instance()->getHomeLongitude(), + wp = new Waypoint(0, HomePositionManager::instance()->getHomeLatitude(), + HomePositionManager::instance()->getHomeLongitude(), WPM->getAltitudeRecommendation(), 0, WPM->getAcceptanceRadiusRecommendation(), 0, 0,true, true, (MAV_FRAME)WPM->getFrameRecommendation(), MAV_CMD_NAV_WAYPOINT); WPM->addWaypointEditable(wp); } @@ -347,8 +347,8 @@ void WaypointList::addEditable(bool onCurrentPosition) { //Since no UAV available, create first default waypoint. updateStatusLabel(tr("No UAV connected. Adding default GLOBAL (NED) waypoint")); - wp = new Waypoint(0, UASManager::instance()->getHomeLatitude(), - UASManager::instance()->getHomeLongitude(), + wp = new Waypoint(0, HomePositionManager::instance()->getHomeLatitude(), + HomePositionManager::instance()->getHomeLongitude(), WPM->getAltitudeRecommendation(), 0, WPM->getAcceptanceRadiusRecommendation(), 0, 0,true, true, (MAV_FRAME)WPM->getFrameRecommendation(), MAV_CMD_NAV_WAYPOINT); WPM->addWaypointEditable(wp); } diff --git a/src/ui/map/QGCMapWidget.cc b/src/ui/map/QGCMapWidget.cc index d48f41697580ceac3efbf007bf9b3cfcd715b7e8..92b5347690ca1e4c8b5beb65cc6d9661948f75e3 100644 --- a/src/ui/map/QGCMapWidget.cc +++ b/src/ui/map/QGCMapWidget.cc @@ -2,7 +2,7 @@ #include "QGCMapWidget.h" #include "QGCMapToolBar.h" #include "UASInterface.h" -#include "UASManager.h" +#include "HomePositionManager.h" #include "MAV2DIcon.h" #include "Waypoint2DIcon.h" #include "UASWaypointManager.h" @@ -123,7 +123,7 @@ bool QGCMapWidget::setHomeActionTriggered() QGCMessageBox::information(tr("Error"), tr("Please connect first")); return false; } - UASManagerInterface *uasManager = UASManager::instance(); + HomePositionManager *uasManager = HomePositionManager::instance(); if (!uasManager) { return false; } // Enter an altitude @@ -187,7 +187,7 @@ void QGCMapWidget::showEvent(QShowEvent* event) connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleAdded, this, &QGCMapWidget::_vehicleAdded); connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &QGCMapWidget::_activeVehicleChanged); - connect(UASManager::instance(), SIGNAL(homePositionChanged(double,double,double)), this, SLOT(updateHomePosition(double,double,double)), Qt::UniqueConnection); + connect(HomePositionManager::instance(), SIGNAL(homePositionChanged(double,double,double)), this, SLOT(updateHomePosition(double,double,double)), Qt::UniqueConnection); foreach (Vehicle* vehicle, MultiVehicleManager::instance()->vehicles()) { _vehicleAdded(vehicle); @@ -213,7 +213,7 @@ void QGCMapWidget::showEvent(QShowEvent* event) } // Set home - updateHomePosition(UASManager::instance()->getHomeLatitude(), UASManager::instance()->getHomeLongitude(), UASManager::instance()->getHomeAltitude()); + updateHomePosition(HomePositionManager::instance()->getHomeLatitude(), HomePositionManager::instance()->getHomeLongitude(), HomePositionManager::instance()->getHomeAltitude()); // Set currently selected system _activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle());