From 9da3ccc70852bd653d620a26de2738d4bcfd9511 Mon Sep 17 00:00:00 2001 From: pip Date: Fri, 21 Jan 2011 20:49:51 +0000 Subject: [PATCH] Includes example usage of the WorldMagModel module. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2517 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../src/plugins/opmap/opmapgadgetwidget.cpp | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/ground/src/plugins/opmap/opmapgadgetwidget.cpp b/ground/src/plugins/opmap/opmapgadgetwidget.cpp index 71aa2e060..4de4cfcb8 100644 --- a/ground/src/plugins/opmap/opmapgadgetwidget.cpp +++ b/ground/src/plugins/opmap/opmapgadgetwidget.cpp @@ -36,9 +36,12 @@ #include #include #include +#include #include +#include "utils/worldmagmodel.h" + #include "uavtalk/telemetrymanager.h" #include "extensionsystem/pluginmanager.h" #include "uavobjects/uavobjectmanager.h" @@ -46,7 +49,7 @@ #include "uavobjects/positionactual.h" #include "uavobjects/homelocation.h" -//#define allow_manual_home_location_move +// #define allow_manual_home_location_move // ************************************************************************************* @@ -1092,15 +1095,13 @@ void OPMapGadgetWidget::setHome(internals::PointLatLng pos_lat_lon) // ********* -// #if defined(allow_manual_home_location_move) - home_position.coord = internals::PointLatLng(latitude, longitude); + home_position.coord = internals::PointLatLng(latitude, longitude); - m_map->Home->SetCoord(home_position.coord); - m_map->Home->RefreshPos(); + m_map->Home->SetCoord(home_position.coord); + m_map->Home->RefreshPos(); - // move the magic waypoint to keep it within the safe area boundry - keepMagicWaypointWithInSafeArea(); -// #endif + // move the magic waypoint to keep it within the safe area boundry + keepMagicWaypointWithInSafeArea(); } @@ -1696,6 +1697,28 @@ void OPMapGadgetWidget::onSetHomeAct_triggered() return; setHome(context_menu_lat_lon); + + // *************** + // calculate the magnetic model + + double X, Y, Z; + QDateTime dt = QDateTime::currentDateTimeUtc(); + + Utils::WorldMagModel *wmm = new Utils::WorldMagModel(); + if (wmm) + { + if (wmm->GetMagVector(home_position.coord.Lat(), home_position.coord.Lng(), home_position.altitude, dt.date().month(), dt.date().day(), dt.date().year(), &X, &Y, &Z) >= 0) + { + QString s = "lat:" + QString::number(home_position.coord.Lat(), 'f', 7) + " lon:" + QString::number(home_position.coord.Lng(), 'f', 7); + s += " x:" + QString::number(X, 'f', 2) + " y:" + QString::number(Y, 'f', 2) + " z:" + QString::number(Z, 'f', 2); + + qDebug() << "opmap HomePosition WMM .. " << s << endl; + } + + delete wmm; + } + + // *************** } void OPMapGadgetWidget::onGoHomeAct_triggered()