HomePositionManager.h 4 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2
/*=====================================================================

3
QGroundControl Open Source Ground Control Station
pixhawk's avatar
pixhawk committed
4

5
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
pixhawk's avatar
pixhawk committed
6

7
This file is part of the QGROUNDCONTROL project
pixhawk's avatar
pixhawk committed
8

9
    QGROUNDCONTROL is free software: you can redistribute it and/or modify
pixhawk's avatar
pixhawk committed
10 11 12 13
    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.

14
    QGROUNDCONTROL is distributed in the hope that it will be useful,
pixhawk's avatar
pixhawk committed
15 16 17 18 19
    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
20
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
pixhawk's avatar
pixhawk committed
21 22 23 24 25 26

======================================================================*/

#ifndef _UASMANAGER_H_
#define _UASMANAGER_H_

Don Gagne's avatar
Don Gagne committed
27 28
#include "UASInterface.h"

pixhawk's avatar
pixhawk committed
29 30
#include <QList>
#include <QMutex>
Don Gagne's avatar
Don Gagne committed
31 32 33

#include <Eigen/Eigen>

34
#include "QGCGeo.h"
Don Gagne's avatar
Don Gagne committed
35
#include "QGCSingleton.h"
pixhawk's avatar
pixhawk committed
36

37 38 39
/// Manages an offline home position as well as performance coordinate transformations
/// around a home position.
class HomePositionManager : public QObject
pixhawk's avatar
pixhawk committed
40 41
{
    Q_OBJECT
42
    
43
    DECLARE_QGC_SINGLETON(HomePositionManager, HomePositionManager)
pixhawk's avatar
pixhawk committed
44

Don Gagne's avatar
Don Gagne committed
45
public:
46
    /** @brief Get home position latitude */
47 48 49
    double getHomeLatitude() const {
        return homeLat;
    }
50
    /** @brief Get home position longitude */
51 52 53
    double getHomeLongitude() const {
        return homeLon;
    }
54
    /** @brief Get home position altitude */
55 56 57
    double getHomeAltitude() const {
        return homeAlt;
    }
lm's avatar
lm committed
58

59 60 61 62 63 64
    /** @brief Get the home position coordinate frame */
    int getHomeFrame() const
    {
        return homeFrame;
    }

65 66 67 68 69 70
    /** @brief Convert WGS84 coordinates to earth centric frame */
    Eigen::Vector3d wgs84ToEcef(const double & latitude, const double & longitude, const double & altitude);
    /** @brief Convert earth centric frame to EAST-NORTH-UP frame (x-y-z directions */
    Eigen::Vector3d ecefToEnu(const Eigen::Vector3d & ecef);
    /** @brief Convert WGS84 lat/lon coordinates to carthesian coordinates with home position as origin */
    void wgs84ToEnu(const double& lat, const double& lon, const double& alt, double* east, double* north, double* up);
LM's avatar
LM committed
71 72 73 74
    /** @brief Convert x,y,z coordinates to lat / lon / alt coordinates in east-north-up frame */
    void enuToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt);
    /** @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);
75

pixhawk's avatar
pixhawk committed
76
public slots:
77
    /** @brief Set the current home position, but do not change it on the UAVs */
78
    bool setHomePosition(double lat, double lon, double alt);
79

80 81 82
    /** @brief Set the current home position on all UAVs*/
    bool setHomePositionAndNotify(double lat, double lon, double alt);

83

84 85 86 87 88
    /** @brief Load settings */
    void loadSettings();
    /** @brief Store settings */
    void storeSettings();

89 90 91 92
signals:
    /** @brief Current home position changed */
    void homePositionChanged(double lat, double lon, double alt);
    
pixhawk's avatar
pixhawk committed
93
protected:
94 95 96
    double homeLat;
    double homeLon;
    double homeAlt;
97
    int homeFrame;
98 99 100 101
    Eigen::Quaterniond ecef_ref_orientation_;
    Eigen::Vector3d ecef_ref_point_;

    void initReference(const double & latitude, const double & longitude, const double & altitude);
102 103
    
private:
104 105 106
    /// @brief All access to HomePositionManager singleton is through HomePositionManager::instance
    HomePositionManager(QObject* parent = NULL);
    ~HomePositionManager();
pixhawk's avatar
pixhawk committed
107

108 109 110 111 112 113
public:
    /* Need to align struct pointer to prevent a memory assertion:
     * See http://eigen.tuxfamily.org/dox-devel/TopicUnalignedArrayAssert.html
     * for details
     */
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
pixhawk's avatar
pixhawk committed
114 115 116
};

#endif // _UASMANAGER_H_