From 9b10842f5d7badd2b5fa47ecb5ebbd9b0dd172de Mon Sep 17 00:00:00 2001 From: pip Date: Mon, 21 Feb 2011 13:33:10 +0000 Subject: [PATCH] Updated some parts of the map plugin to use the new UAVObject utility. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2831 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../src/plugins/opmap/OPMapGadget.pluginspec | 3 +- .../openpilotgcs/src/plugins/opmap/opmap.pro | 7 + .../src/plugins/opmap/opmapgadgetwidget.cpp | 180 +++--------------- .../src/plugins/opmap/opmapgadgetwidget.h | 3 - 4 files changed, 36 insertions(+), 157 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/opmap/OPMapGadget.pluginspec b/ground/openpilotgcs/src/plugins/opmap/OPMapGadget.pluginspec index 51ea9843b..ecca99386 100644 --- a/ground/openpilotgcs/src/plugins/opmap/OPMapGadget.pluginspec +++ b/ground/openpilotgcs/src/plugins/opmap/OPMapGadget.pluginspec @@ -8,5 +8,6 @@ - + + diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap.pro b/ground/openpilotgcs/src/plugins/opmap/opmap.pro index c0ebb1704..5bb709d01 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap.pro +++ b/ground/openpilotgcs/src/plugins/opmap/opmap.pro @@ -1,11 +1,14 @@ TEMPLATE = lib TARGET = OPMapGadget + include(../../openpilotgcsplugin.pri) include(../../plugins/coreplugin/coreplugin.pri) include(../../libs/opmapcontrol/opmapcontrol.pri) include(../../plugins/uavobjects/uavobjects.pri) +include(../../plugins/uavobjectutil/uavobjectutil.pri) include(../../plugins/uavtalk/uavtalk.pri) include(../../libs/utils/utils.pri) + HEADERS += opmapplugin.h \ opmapgadgetoptionspage.h \ opmapgadgetfactory.h \ @@ -17,6 +20,7 @@ HEADERS += opmapplugin.h \ opmap_zoom_slider_widget.h \ opmap_statusbar_widget.h \ opmap_overlay_widget.h + SOURCES += opmapplugin.cpp \ opmapgadgetwidget.cpp \ opmapgadgetoptionspage.cpp \ @@ -28,7 +32,9 @@ SOURCES += opmapplugin.cpp \ opmap_zoom_slider_widget.cpp \ opmap_statusbar_widget.cpp \ opmap_overlay_widget.cpp + OTHER_FILES += OPMapGadget.pluginspec + FORMS += opmapgadgetoptionspage.ui \ opmap_widget.ui \ # opmap_waypointeditor_dialog.ui \ @@ -36,4 +42,5 @@ FORMS += opmapgadgetoptionspage.ui \ opmap_zoom_slider_widget.ui \ opmap_statusbar_widget.ui \ opmap_overlay_widget.ui + RESOURCES += opmap.qrc diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp index 656ca9c69..097426a01 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp @@ -47,6 +47,7 @@ #include "uavtalk/telemetrymanager.h" #include "extensionsystem/pluginmanager.h" +#include "uavobjectutilmanager.h" #include "uavobjectmanager.h" #include "uavobject.h" #include "objectpersistence.h" @@ -973,32 +974,25 @@ void OPMapGadgetWidget::onTelemetryConnect() { telemetry_connected = true; - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - if (!pm) return; + bool set; + double LLA[3]; - UAVObjectManager *obm = pm->getObject(); - if (!obm) return; + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + if (!pm) return; + UAVObjectUtilManager *obum = pm->getObject(); + if (!obum) return; - UAVDataObject *obj; -// UAVObjectField *field; + // *********************** + // fetch the home location - // *********************** - // fetch the home location + if (obum->getHomeLocation(set, LLA) < 0) + return; // error - obj = dynamic_cast(obm->getObject(QString("HomeLocation"))); - if (!obj) return; - - double lat = obj->getField("Latitude")->getDouble() * 1e-7; - double lon = obj->getField("Longitude")->getDouble() * 1e-7; -// double alt = obj->getField("Altitude")->getDouble(); - setHome(internals::PointLatLng(lat, lon)); + setHome(internals::PointLatLng(LLA[0], LLA[1])); if (m_map) m_map->SetCurrentPosition(home_position.coord); // set the map position -// field = obj->getField(QString("Be")); -// if (!field) return; - // *********************** } @@ -2264,42 +2258,19 @@ bool OPMapGadgetWidget::getUAV_LLA(double &latitude, double &longitude, double & bool OPMapGadgetWidget::getGPS_LLA(double &latitude, double &longitude, double &altitude) { - UAVObject *obj; + double LLA[3]; - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - if (!pm) return false; - UAVObjectManager *om = pm->getObject(); - if (!om) return false; + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + if (!pm) return false; + UAVObjectUtilManager *obum = pm->getObject(); + if (!obum) return false; - obj = dynamic_cast(om->getObject(QString("GPSPosition"))); - if (!obj) return false; - latitude = obj->getField(QString("Latitude"))->getDouble(); - longitude = obj->getField(QString("Longitude"))->getDouble(); - altitude = obj->getField(QString("Altitude"))->getDouble(); + if (obum->getGPSPosition(LLA) < 0) + return false; // error - latitude *= 1E-7; - longitude *= 1E-7; - - if (latitude != latitude) latitude = 0; // nan detection -// if (isNan(latitude)) latitude = 0; // nan detection - else -// if (!isFinite(latitude)) latitude = 0; -// else - if (latitude > 90) latitude = 90; - else - if (latitude < -90) latitude = -90; - - if (longitude != longitude) longitude = 0; // nan detection - else -// if (longitude > std::numeric_limits::max()) longitude = 0; // +infinite -// else -// if (longitude < -std::numeric_limits::max()) longitude = 0; // -infinite -// else - if (longitude > 180) longitude = 180; - else - if (longitude < -180) longitude = -180; - - if (altitude != altitude) altitude = 0; // nan detection + latitude = LLA[0]; + longitude = LLA[1]; + altitude = LLA[2]; return true; } @@ -2322,42 +2293,6 @@ double OPMapGadgetWidget::getUAV_Yaw() return yaw; } -// ************************************************************************************* -// save an object to SD card - -void OPMapGadgetWidget::saveObjectToSD(UAVObject *obj) -{ - if (!obj) return; - - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - if (!pm) return; - - UAVObjectManager *obm = pm->getObject(); - if (!obm) return; - - ObjectPersistence *objper = dynamic_cast( obm->getObject(ObjectPersistence::NAME) ); - if (!objper) return; - - connect(objper, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(uavObjectTransactionCompleted(UAVObject *, bool))); - - ObjectPersistence::DataFields data; - data.Operation = ObjectPersistence::OPERATION_SAVE; - data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; - data.ObjectID = obj->getObjID(); - data.InstanceID = obj->getInstID(); - - objper->setData(data); - objper->updated(); -} - -void OPMapGadgetWidget::uavObjectTransactionCompleted(UAVObject *obj, bool success) -{ - Q_UNUSED(success); - - // Disconnect from sending object - if (obj) obj->disconnect(this); -} - // ************************************************************************************* void OPMapGadgetWidget::setMapFollowingMode() @@ -2390,76 +2325,15 @@ void OPMapGadgetWidget::setMapFollowingMode() void OPMapGadgetWidget::setHomeLocationObject() { - double LLA[3]; - double ECEF[3]; - double RNE[9]; - double Be[3]; - - LLA[0] = home_position.coord.Lat(); - LLA[1] = home_position.coord.Lng(); - LLA[2] = home_position.altitude; - - if (Utils::HomeLocationUtil().getDetails(LLA, ECEF, RNE, Be) < 0) - return; // error - - // ****************** - // save the new home location details + double LLA[3] = {home_position.coord.Lat(), home_position.coord.Lng(), home_position.altitude}; ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); if (!pm) return; + UAVObjectUtilManager *obum = pm->getObject(); + if (!obum) return; - UAVObjectManager *obm = pm->getObject(); - if (!obm) return; - - UAVDataObject *obj = dynamic_cast(obm->getObject(QString("HomeLocation"))); - if (!obj) return; - - UAVObjectField *ECEF_field = obj->getField(QString("ECEF")); - if (!ECEF_field) return; - - UAVObjectField *RNE_field = obj->getField(QString("RNE")); - if (!RNE_field) return; - - UAVObjectField *Be_field = obj->getField(QString("Be")); - if (!Be_field) return; - - obj->getField("Set")->setValue("TRUE"); - - obj->getField("Latitude")->setValue(LLA[0] * 10e6); - obj->getField("Longitude")->setValue(LLA[1] * 10e6); - obj->getField("Altitude")->setValue(LLA[2]); - - for (int i = 0; i < 3; i++) - ECEF_field->setValue(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->updated(); - - // ****************** - // save the new location to SD card - -// saveObjectToSD(obj); - - // ****************** - // debug - - qDebug() << "opmap 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; - - // ****************** + if (obum->setHomeLocation(LLA, true) < 0) + return; // error } // ************************************************************************************* diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h index 437e69818..478b137b8 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h @@ -114,7 +114,6 @@ public slots: void homePositionUpdated(UAVObject *); void onTelemetryConnect(); void onTelemetryDisconnect(); - void uavObjectTransactionCompleted(UAVObject *obj, bool success); protected: void resizeEvent(QResizeEvent *event); @@ -325,8 +324,6 @@ private: bool getGPS_LLA(double &latitude, double &longitude, double &altitude); double getUAV_Yaw(); - void saveObjectToSD(UAVObject *obj); - void setMapFollowingMode(); void setHomeLocationObject();