1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00

Added getGPSPosition() function to the UAVObject utility

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2830 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2011-02-21 13:32:22 +00:00 committed by pip
parent d666a61bf5
commit a5f17b148b
4 changed files with 43 additions and 10 deletions

View File

@ -6,5 +6,6 @@
<url>http://www.openpilot.org</url> <url>http://www.openpilot.org</url>
<dependencyList> <dependencyList>
<dependency name="Core" version="1.0.0"/> <dependency name="Core" version="1.0.0"/>
</dependencyList> <dependency name="UAVObjects" version="1.0.0"/>
</dependencyList>
</plugin> </plugin>

View File

@ -193,3 +193,40 @@ int UAVObjectUtilManager::getHomeLocation(bool &set, double LLA[3], double ECEF[
} }
// ****************************** // ******************************
// GPS
int UAVObjectUtilManager::getGPSPosition(double LLA[3])
{
QMutexLocker locker(mutex);
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
if (!pm) return -1;
UAVObjectManager *obm = pm->getObject<UAVObjectManager>();
if (!obm) return -2;
UAVDataObject *obj = dynamic_cast<UAVDataObject*>(obm->getObject(QString("GPSPosition")));
if (!obj) return -3;
LLA[0] = obj->getField(QString("Latitude"))->getDouble() * 1E-7;
LLA[1] = obj->getField(QString("Longitude"))->getDouble() * 1E-7;
LLA[2] = obj->getField(QString("Altitude"))->getDouble();
if (LLA[0] != LLA[0]) LLA[0] = 0; // nan detection
else
if (LLA[0] > 90) LLA[0] = 90;
else
if (LLA[0] < -90) LLA[0] = -90;
if (LLA[1] != LLA[1]) LLA[1] = 0; // nan detection
else
if (LLA[1] > 180) LLA[1] = 180;
else
if (LLA[1] < -180) LLA[1] = -180;
if (LLA[2] != LLA[2]) LLA[2] = 0; // nan detection
return 0; // OK
}
// ******************************

View File

@ -25,6 +25,7 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UAVOBJECTUTILMANAGER_H #ifndef UAVOBJECTUTILMANAGER_H
#define UAVOBJECTUTILMANAGER_H #define UAVOBJECTUTILMANAGER_H
@ -46,6 +47,8 @@ public:
int getHomeLocation(bool &set, double LLA[3]); int getHomeLocation(bool &set, double LLA[3]);
int getHomeLocation(bool &set, double LLA[3], double ECEF[3], double RNE[9], double Be[3]); int getHomeLocation(bool &set, double LLA[3], double ECEF[3], double RNE[9], double Be[3]);
int getGPSPosition(double LLA[3]);
private: private:
QMutex *mutex; QMutex *mutex;

View File

@ -30,17 +30,14 @@
UAVObjectUtilPlugin::UAVObjectUtilPlugin() UAVObjectUtilPlugin::UAVObjectUtilPlugin()
{ {
} }
UAVObjectUtilPlugin::~UAVObjectUtilPlugin() UAVObjectUtilPlugin::~UAVObjectUtilPlugin()
{ {
} }
void UAVObjectUtilPlugin::extensionsInitialized() void UAVObjectUtilPlugin::extensionsInitialized()
{ {
} }
bool UAVObjectUtilPlugin::initialize(const QStringList & arguments, QString * errorString) bool UAVObjectUtilPlugin::initialize(const QStringList & arguments, QString * errorString)
@ -48,20 +45,15 @@ bool UAVObjectUtilPlugin::initialize(const QStringList & arguments, QString * er
Q_UNUSED(arguments) Q_UNUSED(arguments)
Q_UNUSED(errorString) Q_UNUSED(errorString)
// Create object manager and expose object // Create manager and expose object
UAVObjectUtilManager *objUtilMngr = new UAVObjectUtilManager(); UAVObjectUtilManager *objUtilMngr = new UAVObjectUtilManager();
addAutoReleasedObject(objUtilMngr); addAutoReleasedObject(objUtilMngr);
// Initialize UAVObjects
// UAVObjectUtilInitialize(objMngr);
return true; return true;
} }
void UAVObjectUtilPlugin::shutdown() void UAVObjectUtilPlugin::shutdown()
{ {
} }
Q_EXPORT_PLUGIN(UAVObjectUtilPlugin) Q_EXPORT_PLUGIN(UAVObjectUtilPlugin)