From d666a61bf5b4e66a3793a7d9db2b96b30136d4b7 Mon Sep 17 00:00:00 2001 From: pip Date: Mon, 21 Feb 2011 13:21:02 +0000 Subject: [PATCH] Created a new UAVObject utility plugin to make UAVObject access much easier for all plugins git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2829 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/openpilotgcs/src/plugins/plugins.pro | 17 +- .../uavobjectutil/UAVObjectUtil.pluginspec | 10 + .../plugins/uavobjectutil/uavobjectutil.pri | 6 + .../plugins/uavobjectutil/uavobjectutil.pro | 14 ++ .../uavobjectutil_dependencies.pri | 3 + .../uavobjectutil/uavobjectutil_global.h | 40 ++++ .../uavobjectutil/uavobjectutilmanager.cpp | 195 ++++++++++++++++++ .../uavobjectutil/uavobjectutilmanager.h | 55 +++++ .../uavobjectutil/uavobjectutilplugin.cpp | 67 ++++++ .../uavobjectutil/uavobjectutilplugin.h | 49 +++++ 10 files changed, 451 insertions(+), 5 deletions(-) create mode 100644 ground/openpilotgcs/src/plugins/uavobjectutil/UAVObjectUtil.pluginspec create mode 100644 ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil.pri create mode 100644 ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil.pro create mode 100644 ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil_dependencies.pri create mode 100644 ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil_global.h create mode 100644 ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp create mode 100644 ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h create mode 100644 ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilplugin.cpp create mode 100644 ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilplugin.h diff --git a/ground/openpilotgcs/src/plugins/plugins.pro b/ground/openpilotgcs/src/plugins/plugins.pro index ba01c1a91..fe7fa5b59 100644 --- a/ground/openpilotgcs/src/plugins/plugins.pro +++ b/ground/openpilotgcs/src/plugins/plugins.pro @@ -49,6 +49,7 @@ plugin_uavtalk.depends += plugin_coreplugin plugin_opmap.subdir = opmap plugin_opmap.depends = plugin_coreplugin plugin_opmap.depends += plugin_uavobjects +plugin_opmap.depends += plugin_uavobjectutil SUBDIRS += plugin_opmap # Scope UAVGadget @@ -162,11 +163,17 @@ plugin_pipxtreme.depends += plugin_uavobjects plugin_pipxtreme.depends += plugin_rawhid SUBDIRS += plugin_pipxtreme -#Scope2 gadget -#plugin_scope2.subdir = scope2 -#plugin_scope2.depends = plugin_coreplugin -#plugin_scope2.depends += plugin_uavobjects -#SUBDIRS += plugin_scope2 +#Scope OpenGL Gadget +#plugin_scopeogl.subdir = scopeogl +#plugin_scopeogl.depends = plugin_coreplugin +#plugin_scopeogl.depends += plugin_uavobjects +#SUBDIRS += plugin_scopeogl + +# UAV Object Utility plugin +plugin_uavobjectutil.subdir = uavobjectutil +plugin_uavobjectutil.depends = plugin_coreplugin +plugin_uavobjectutil.depends += plugin_uavobjects +SUBDIRS += plugin_uavobjectutil # Magic Waypoint gadget plugin_magicwaypoint.subdir = magicwaypoint diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/UAVObjectUtil.pluginspec b/ground/openpilotgcs/src/plugins/uavobjectutil/UAVObjectUtil.pluginspec new file mode 100644 index 000000000..8f2a24d0b --- /dev/null +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/UAVObjectUtil.pluginspec @@ -0,0 +1,10 @@ + + The OpenPilot Project + (C) 2010 OpenPilot Project + The GNU Public License (GPL) Version 3 + Easy access to UAVOBjects + http://www.openpilot.org + + + + diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil.pri b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil.pri new file mode 100644 index 000000000..fde2f6de0 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil.pri @@ -0,0 +1,6 @@ +include(uavobjectutil_dependencies.pri) + +# Add the include path to the built-in uavobject include files. +INCLUDEPATH += $$PWD + +LIBS *= -l$$qtLibraryTarget(UAVObjectUtil) diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil.pro b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil.pro new file mode 100644 index 000000000..2776a2d25 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil.pro @@ -0,0 +1,14 @@ +TEMPLATE = lib +TARGET = UAVObjectUtil +DEFINES += UAVOBJECTUTIL_LIBRARY +include(../../openpilotgcsplugin.pri) +include(uavobjectutil_dependencies.pri) + +HEADERS += uavobjectutil_global.h \ + uavobjectutilmanager.h \ + uavobjectutilplugin.h + +SOURCES += uavobjectutilmanager.cpp \ + uavobjectutilplugin.cpp + +OTHER_FILES += UAVObjectUtil.pluginspec diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil_dependencies.pri b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil_dependencies.pri new file mode 100644 index 000000000..a88e53608 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil_dependencies.pri @@ -0,0 +1,3 @@ +include(../../plugins/coreplugin/coreplugin.pri) +include(../../libs/utils/utils.pri) +include(../../plugins/uavobjects/uavobjects.pri) diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil_global.h b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil_global.h new file mode 100644 index 000000000..095c880ef --- /dev/null +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutil_global.h @@ -0,0 +1,40 @@ +/** + ****************************************************************************** + * + * @file uavobjectutil_global.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @see The GNU Public License (GPL) Version 3 + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup UAVObjectUtilPlugin UAVObjectUtil Plugin + * @{ + * @brief The UAVUObjectUtil GCS plugin + *****************************************************************************/ +/* + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef UAVOBJECTUTIL_GLOBAL_H +#define UAVOBJECTUTIL_GLOBAL_H + +#include + +#if defined(UAVOBJECTUTIL_LIBRARY) +# define UAVOBJECTUTIL_EXPORT Q_DECL_EXPORT +#else +# define UAVOBJECTUTIL_EXPORT Q_DECL_IMPORT +#endif + +#endif diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp new file mode 100644 index 000000000..63e6f64dd --- /dev/null +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp @@ -0,0 +1,195 @@ +/** + ****************************************************************************** + * + * @file uavobjectutilmanager.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @see The GNU Public License (GPL) Version 3 + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup UAVObjectUtilPlugin UAVObjectUtil Plugin + * @{ + * @brief The UAVUObjectUtil GCS plugin + *****************************************************************************/ +/* + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "uavobjectutilmanager.h" + +#include "utils/homelocationutil.h" + +#include "extensionsystem/pluginmanager.h" +#include "uavobjectmanager.h" +#include "uavobject.h" + +#include +#include + +UAVObjectUtilManager::UAVObjectUtilManager() +{ + mutex = new QMutex(QMutex::Recursive); +} + +UAVObjectUtilManager::~UAVObjectUtilManager() +{ + if (mutex) + { + delete mutex; + mutex = NULL; + } +} + +// ****************************** +// HomeLocation + +int UAVObjectUtilManager::setHomeLocation(double LLA[3], bool save_to_sdcard) +{ + double ECEF[3]; + double RNE[9]; + double Be[3]; + + QMutexLocker locker(mutex); + + if (Utils::HomeLocationUtil().getDetails(LLA, ECEF, RNE, Be) < 0) + return -1; // error + + // ****************** + // save the new home location details + + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + if (!pm) return -2; + + UAVObjectManager *obm = pm->getObject(); + if (!obm) return -3; + + UAVDataObject *obj = dynamic_cast(obm->getObject(QString("HomeLocation"))); + if (!obj) return -4; + + UAVObjectField *ECEF_field = obj->getField(QString("ECEF")); + if (!ECEF_field) return -5; + + UAVObjectField *RNE_field = obj->getField(QString("RNE")); + if (!RNE_field) return -6; + + UAVObjectField *Be_field = obj->getField(QString("Be")); + if (!Be_field) return -7; + + obj->getField("Latitude")->setDouble(LLA[0] * 10e6); + obj->getField("Longitude")->setDouble(LLA[1] * 10e6); + obj->getField("Altitude")->setDouble(LLA[2]); + + for (int i = 0; i < 3; i++) + ECEF_field->setDouble(ECEF[i] * 100, i); + + for (int i = 0; i < 9; i++) + RNE_field->setDouble(RNE[i], i); + + for (int i = 0; i < 3; i++) + Be_field->setDouble(Be[i], i); + + obj->getField("Set")->setValue("TRUE"); + + obj->updated(); + + // ****************** + // save the new location to SD card + + if (save_to_sdcard) + { +// saveObjectToSD(obj); + } + + // ****************** + // debug + + qDebug() << "setting HomeLocation UAV Object .. " << endl; + QString s; + s = " LAT:" + QString::number(LLA[0], 'f', 7) + " LON:" + QString::number(LLA[1], 'f', 7) + " ALT:" + QString::number(LLA[2], 'f', 1); + qDebug() << s << endl; + s = " ECEF "; for (int i = 0; i < 3; i++) s += " " + QString::number((int)(ECEF[i] * 100)); + qDebug() << s << endl; + s = " RNE "; for (int i = 0; i < 9; i++) s += " " + QString::number(RNE[i], 'f', 7); + qDebug() << s << endl; + s = " Be "; for (int i = 0; i < 3; i++) s += " " + QString::number(Be[i], 'f', 2); + qDebug() << s << endl; + + // ****************** + + return 0; // OK +} + +int UAVObjectUtilManager::getHomeLocation(bool &set, double LLA[3]) +{ + QMutexLocker locker(mutex); + + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + if (!pm) return -1; + + UAVObjectManager *obm = pm->getObject(); + if (!obm) return -2; + + UAVDataObject *obj = dynamic_cast(obm->getObject(QString("HomeLocation"))); + if (!obj) return -3; + + set = obj->getField("Set")->getValue().toBool(); + + LLA[0] = obj->getField("Latitude")->getDouble(); + LLA[1] = obj->getField("Longitude")->getDouble(); + LLA[2] = obj->getField("Altitude")->getDouble(); + + return 0; // OK +} + +int UAVObjectUtilManager::getHomeLocation(bool &set, double LLA[3], double ECEF[3], double RNE[9], double Be[3]) +{ + QMutexLocker locker(mutex); + + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + if (!pm) return -1; + + UAVObjectManager *obm = pm->getObject(); + if (!obm) return -2; + + UAVDataObject *obj = dynamic_cast(obm->getObject(QString("HomeLocation"))); + if (!obj) return -3; + + UAVObjectField *ECEF_field = obj->getField(QString("ECEF")); + if (!ECEF_field) return -4; + + UAVObjectField *RNE_field = obj->getField(QString("RNE")); + if (!RNE_field) return -5; + + UAVObjectField *Be_field = obj->getField(QString("Be")); + if (!Be_field) return -6; + + set = obj->getField("Set")->getValue().toBool(); + + LLA[0] = obj->getField("Latitude")->getDouble(); + LLA[1] = obj->getField("Longitude")->getDouble(); + LLA[2] = obj->getField("Altitude")->getDouble(); + + for (int i = 0; i < 3; i++) + ECEF[i] = ECEF_field->getDouble(i); + + for (int i = 0; i < 9; i++) + RNE[i] = RNE_field->getDouble(i); + + for (int i = 0; i < 3; i++) + Be[i] = Be_field->getDouble(i); + + return 0; // OK +} + +// ****************************** diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h new file mode 100644 index 000000000..abea4aa14 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h @@ -0,0 +1,55 @@ +/** + ****************************************************************************** + * + * @file uavobjectmanager.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @see The GNU Public License (GPL) Version 3 + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup UAVObjectsPlugin UAVObjects Plugin + * @{ + * @brief The UAVUObjects GCS plugin + *****************************************************************************/ +/* + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef UAVOBJECTUTILMANAGER_H +#define UAVOBJECTUTILMANAGER_H + +#include "uavobjectutil_global.h" + +#include +#include +#include + +class UAVOBJECTUTIL_EXPORT UAVObjectUtilManager: public QObject +{ + Q_OBJECT + +public: + UAVObjectUtilManager(); + ~UAVObjectUtilManager(); + + int setHomeLocation(double LLA[3], bool save_to_sdcard); + int getHomeLocation(bool &set, double LLA[3]); + int getHomeLocation(bool &set, double LLA[3], double ECEF[3], double RNE[9], double Be[3]); + +private: + QMutex *mutex; + +}; + + +#endif diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilplugin.cpp b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilplugin.cpp new file mode 100644 index 000000000..cf557644f --- /dev/null +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilplugin.cpp @@ -0,0 +1,67 @@ +/** + ****************************************************************************** + * + * @file uavobjectutilplugin.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @see The GNU Public License (GPL) Version 3 + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup UAVObjectUtilPlugin UAVObjectUtil Plugin + * @{ + * @brief The UAVUObjectUtil GCS plugin + *****************************************************************************/ +/* + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "uavobjectutilplugin.h" + +UAVObjectUtilPlugin::UAVObjectUtilPlugin() +{ + +} + +UAVObjectUtilPlugin::~UAVObjectUtilPlugin() +{ + +} + +void UAVObjectUtilPlugin::extensionsInitialized() +{ + +} + +bool UAVObjectUtilPlugin::initialize(const QStringList & arguments, QString * errorString) +{ + Q_UNUSED(arguments) + Q_UNUSED(errorString) + + // Create object manager and expose object + UAVObjectUtilManager *objUtilMngr = new UAVObjectUtilManager(); + addAutoReleasedObject(objUtilMngr); + + // Initialize UAVObjects +// UAVObjectUtilInitialize(objMngr); + + + return true; +} + +void UAVObjectUtilPlugin::shutdown() +{ + +} + +Q_EXPORT_PLUGIN(UAVObjectUtilPlugin) diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilplugin.h b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilplugin.h new file mode 100644 index 000000000..5b5daf1c5 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilplugin.h @@ -0,0 +1,49 @@ +/** + ****************************************************************************** + * + * @file uavobjectutilplugin.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @see The GNU Public License (GPL) Version 3 + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup UAVObjectUtilPlugin UAVObjectUtil Plugin + * @{ + * @brief The UAVUObjectUtil GCS plugin + *****************************************************************************/ +/* + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef UAVOBJECTUTILPLUGIN_H +#define UAVOBJECTUTILPLUGIN_H + +#include "uavobjectutil_global.h" +#include +#include +#include "uavobjectutilmanager.h" + +class UAVOBJECTUTIL_EXPORT UAVObjectUtilPlugin: public ExtensionSystem::IPlugin +{ + Q_OBJECT + +public: + UAVObjectUtilPlugin(); + ~UAVObjectUtilPlugin(); + + void extensionsInitialized(); + bool initialize(const QStringList & arguments, QString * errorString); + void shutdown(); +}; + +#endif