MissionItem.h 7.3 KB
Newer Older
pixhawk's avatar
pixhawk committed
1
/*=====================================================================
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL 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.
 
 QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/
pixhawk's avatar
pixhawk committed
23

24 25
#ifndef MissionItem_H
#define MissionItem_H
pixhawk's avatar
pixhawk committed
26 27 28

#include <QObject>
#include <QString>
29
#include <QtQml>
30
#include <QTextStream>
31 32
#include <QGeoCoordinate>

lm's avatar
lm committed
33
#include "QGCMAVLink.h"
lm's avatar
lm committed
34
#include "QGC.h"
35
#include "MavlinkQmlSingleton.h"
pixhawk's avatar
pixhawk committed
36

37
class MissionItem : public QObject
pixhawk's avatar
pixhawk committed
38 39 40
{
    Q_OBJECT
public:
41
    MissionItem(
Gus Grubba's avatar
Gus Grubba committed
42
        QObject *parent = 0,
43 44 45 46 47 48 49 50 51 52 53 54 55 56
        quint16 id = 0,
        double  x = 0.0,
        double  y = 0.0,
        double  z = 0.0,
        double  param1 = 0.0,
        double  param2 = 0.0,
        double  param3 = 0.0,
        double  param4 = 0.0,
        bool    autocontinue = true,
        bool    current = false,
        int     frame = MAV_FRAME_GLOBAL,
        int     action = MAV_CMD_NAV_WAYPOINT,
        const QString& description=QString(""));

57 58
    MissionItem(const MissionItem& other);
    ~MissionItem();
pixhawk's avatar
pixhawk committed
59

60
    const MissionItem& operator=(const MissionItem& other);
61

62
    Q_PROPERTY(bool hasCoordinate READ hasCoordinate NOTIFY hasCoordinateChanged)
63
    Q_PROPERTY(QGeoCoordinate coordinate READ coordinate NOTIFY coordinateChanged)
64 65 66
    
    Q_PROPERTY(QString commandName READ commandName NOTIFY commandNameChanged)
    Q_PROPERTY(MavlinkQmlSingleton::Qml_MAV_CMD command READ command WRITE setCommand NOTIFY commandChanged)
67
    
68 69 70 71
    Q_PROPERTY(double  longitude READ longitude  NOTIFY longitudeChanged)
    Q_PROPERTY(double  latitude  READ latitude   NOTIFY latitudeChanged)
    Q_PROPERTY(double  altitude  READ altitude   NOTIFY altitudeChanged)
    Q_PROPERTY(quint16 id        READ id         CONSTANT)
72 73 74
    
    Q_PROPERTY(QStringList valueLabels READ valueLabels NOTIFY commandChanged)
    Q_PROPERTY(QStringList valueStrings READ valueStrings NOTIFY valueStringsChanged)
75 76 77 78 79 80

    double  latitude()  { return _x; }
    double  longitude() { return _y; }
    double  altitude()  { return _z; }
    quint16 id()        { return _id; }

81
    quint16 getId() const {
82
        return _id;
83 84
    }
    double getX() const {
85
        return _x;
86 87
    }
    double getY() const {
88
        return _y;
89 90
    }
    double getZ() const {
91
        return _z;
92 93
    }
    double getLatitude() const {
94
        return _x;
95 96
    }
    double getLongitude() const {
97
        return _y;
98 99
    }
    double getAltitude() const {
100
        return _z;
101 102
    }
    double getYaw() const {
103
        return _yaw;
104 105
    }
    bool getAutoContinue() const {
106
        return _autocontinue;
107 108
    }
    bool getCurrent() const {
109
        return _current;
110 111
    }
    double getLoiterOrbit() const {
112
        return _orbit;
113 114
    }
    double getAcceptanceRadius() const {
115
        return _param2;
116 117
    }
    double getHoldTime() const {
118
        return _param1;
119 120
    }
    double getParam1() const {
121
        return _param1;
122 123
    }
    double getParam2() const {
124
        return _param2;
125 126
    }
    double getParam3() const {
127
        return _orbit;
128 129
    }
    double getParam4() const {
130
        return _yaw;
131 132
    }
    double getParam5() const {
133
        return _x;
134 135
    }
    double getParam6() const {
136
        return _y;
137 138
    }
    double getParam7() const {
139
        return _z;
140 141
    }
    int getTurns() const {
142
        return _param1;
143
    }
144 145 146
    // MAV_FRAME
    int getFrame() const {
        return _frame;
147
    }
148 149 150
    // MAV_CMD
    int getAction() const {
        return _action;
151 152
    }
    const QString& getName() const {
153
        return _name;
154
    }
155
    const QString& getDescription() const {
156
        return _description;
157
    }
158

lm's avatar
lm committed
159 160
    /** @brief Returns true if x, y, z contain reasonable navigation data */
    bool isNavigationType();
161

162 163 164
    /** @brief Get the time this waypoint was reached */
    quint64 getReachedTime() const { return _reachedTime; }

165 166
    void save(QTextStream &saveStream);
    bool load(QTextStream &loadStream);
167
    
168
    bool hasCoordinate(void);
169
    QGeoCoordinate coordinate(void);
170 171
    
    QString commandName(void);
172

173 174 175 176 177 178
    MavlinkQmlSingleton::Qml_MAV_CMD command(void) { return (MavlinkQmlSingleton::Qml_MAV_CMD)getAction(); };
    void setCommand(MavlinkQmlSingleton::Qml_MAV_CMD command) { setAction(command); }
    
    QStringList valueLabels(void);
    QStringList valueStrings(void);
    
179
protected:
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    quint16 _id;
    double  _x;
    double  _y;
    double  _z;
    double  _yaw;
    int     _frame;
    int     _action;
    bool    _autocontinue;
    bool    _current;
    double  _orbit;
    double  _param1;
    double  _param2;
    int     _turns;
    QString _name;
    QString _description;
    quint64 _reachedTime;

public:
    void setId          (quint16 _id);
    void setX           (double _x);
    void setY           (double _y);
    void setZ           (double _z);
    void setLatitude    (double lat);
    void setLongitude   (double lon);
    void setAltitude    (double alt);
lm's avatar
lm committed
205
    /** @brief Yaw angle in COMPASS DEGREES: 0-360 */
206
    void setYaw         (int _yaw);
lm's avatar
lm committed
207
    /** @brief Yaw angle in COMPASS DEGREES: 0-360 */
208
    void setYaw         (double _yaw);
209
    /** @brief Set the waypoint action */
210 211
    void setAction      (int _action);
    void setFrame       (int _frame);
pixhawk's avatar
pixhawk committed
212
    void setAutocontinue(bool autoContinue);
213 214 215 216 217 218 219 220 221
    void setCurrent     (bool _current);
    void setLoiterOrbit (double _orbit);
    void setParam1      (double _param1);
    void setParam2      (double _param2);
    void setParam3      (double param3);
    void setParam4      (double param4);
    void setParam5      (double param5);
    void setParam6      (double param6);
    void setParam7      (double param7);
222
    void setAcceptanceRadius(double radius);
223 224
    void setHoldTime    (int holdTime);
    void setHoldTime    (double holdTime);
225
    /** @brief Number of turns for loiter waypoints */
226
    void setTurns       (int _turns);
lm's avatar
lm committed
227
    /** @brief Set waypoint as reached */
228
    void setReached     () { _reachedTime = QGC::groundTimeMilliseconds(); }
lm's avatar
lm committed
229
    /** @brief Wether this waypoint has been reached yet */
230 231
    bool isReached      () { return (_reachedTime > 0); }

232 233 234
    void setChanged() {
        emit changed(this);
    }
235 236 237

signals:
    /** @brief Announces a change to the waypoint data */
238
    void changed(MissionItem* wp);
239 240 241 242

    void latitudeChanged    ();
    void longitudeChanged   ();
    void altitudeChanged    ();
243
    void hasCoordinateChanged(bool hasCoordinate);
244
    void coordinateChanged(void);
245 246 247 248 249 250 251
    void commandNameChanged(QString type);
    void commandChanged(MavlinkQmlSingleton::Qml_MAV_CMD command);
    void valueLabelsChanged(QStringList valueLabels);
    void valueStringsChanged(QStringList valueStrings);
    
private:
    QString _oneDecimalString(double value);
pixhawk's avatar
pixhawk committed
252 253
};

254
QML_DECLARE_TYPE(MissionItem)
255

256
#endif