MissionItem.h 9.89 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"
Don Gagne's avatar
Don Gagne committed
36 37
#include "QmlObjectListModel.h"
#include "Fact.h"
Don Gagne's avatar
Don Gagne committed
38 39 40
#include "QGCLoggingCategory.h"

Q_DECLARE_LOGGING_CATEGORY(MissionItemLog)
pixhawk's avatar
pixhawk committed
41

42
class MissionItem : public QObject
pixhawk's avatar
pixhawk committed
43 44
{
    Q_OBJECT
45
    
pixhawk's avatar
pixhawk committed
46
public:
Don Gagne's avatar
Don Gagne committed
47 48 49
    MissionItem(QObject         *parent = 0,
                int             sequenceNumber = 0,
                QGeoCoordinate  coordiante = QGeoCoordinate(),
Don Gagne's avatar
Don Gagne committed
50
                int             action = MAV_CMD_NAV_WAYPOINT,
Don Gagne's avatar
Don Gagne committed
51 52 53 54 55 56
                double          param1 = 0.0,
                double          param2 = 0.0,
                double          param3 = 0.0,
                double          param4 = 0.0,
                bool            autocontinue = true,
                bool            isCurrentItem = false,
Don Gagne's avatar
Don Gagne committed
57
                int             frame = MAV_FRAME_GLOBAL_RELATIVE_ALT);
58

Don Gagne's avatar
Don Gagne committed
59
    MissionItem(const MissionItem& other, QObject* parent = NULL);
60
    ~MissionItem();
pixhawk's avatar
pixhawk committed
61

62 63
    const MissionItem& operator=(const MissionItem& other);
    
Don Gagne's avatar
Don Gagne committed
64 65 66
    /// Returns true if the item has been modified since the last time dirty was false
    Q_PROPERTY(bool                 dirty               READ dirty                  WRITE setDirty          NOTIFY dirtyChanged)
    
Don Gagne's avatar
Don Gagne committed
67 68
    Q_PROPERTY(int                  sequenceNumber      READ sequenceNumber         WRITE setSequenceNumber NOTIFY sequenceNumberChanged)
    Q_PROPERTY(bool                 isCurrentItem       READ isCurrentItem          WRITE setIsCurrentItem  NOTIFY isCurrentItemChanged)
69
    Q_PROPERTY(bool                 specifiesCoordinate READ specifiesCoordinate                            NOTIFY commandChanged)
Don Gagne's avatar
Don Gagne committed
70 71 72 73 74 75 76
    Q_PROPERTY(QGeoCoordinate       coordinate          READ coordinate             WRITE setCoordinate     NOTIFY coordinateChanged)
    Q_PROPERTY(double               yaw                 READ yawDegrees             WRITE setYawDegrees     NOTIFY yawChanged)
    Q_PROPERTY(QStringList          commandNames        READ commandNames                                   CONSTANT)
    Q_PROPERTY(QString              commandName         READ commandName                                    NOTIFY commandChanged)
    Q_PROPERTY(QStringList          valueLabels         READ valueLabels                                    NOTIFY commandChanged)
    Q_PROPERTY(QStringList          valueStrings        READ valueStrings                                   NOTIFY valueStringsChanged)
    Q_PROPERTY(int                  commandByIndex      READ commandByIndex         WRITE setCommandByIndex NOTIFY commandChanged)
77 78
    Q_PROPERTY(QmlObjectListModel*  textFieldFacts      READ textFieldFacts                                 NOTIFY commandChanged)
    Q_PROPERTY(QmlObjectListModel*  checkboxFacts       READ checkboxFacts                                  NOTIFY commandChanged)
Don Gagne's avatar
Don Gagne committed
79
    Q_PROPERTY(MavlinkQmlSingleton::Qml_MAV_CMD command READ command                WRITE setCommand        NOTIFY commandChanged)
Don Gagne's avatar
Don Gagne committed
80 81 82 83 84 85 86 87
    
    // Property accesors
    
    int sequenceNumber(void) const { return _sequenceNumber; }
    void setSequenceNumber(int sequenceNumber);
    
    bool isCurrentItem(void) const { return _isCurrentItem; }
    void setIsCurrentItem(bool isCurrentItem);
88
    
Don Gagne's avatar
Don Gagne committed
89
    bool specifiesCoordinate(void) const;
90
    
91
    QGeoCoordinate coordinate(void) const;
Don Gagne's avatar
Don Gagne committed
92 93 94 95
    void setCoordinate(const QGeoCoordinate& coordinate);
    
    QStringList commandNames(void);
    QString commandName(void);
96

Don Gagne's avatar
Don Gagne committed
97 98 99
    int commandByIndex(void);
    void setCommandByIndex(int index);
    
Don Gagne's avatar
Don Gagne committed
100
    MavlinkQmlSingleton::Qml_MAV_CMD command(void) { return (MavlinkQmlSingleton::Qml_MAV_CMD)_command; };
Don Gagne's avatar
Don Gagne committed
101 102 103 104 105
    void setCommand(MavlinkQmlSingleton::Qml_MAV_CMD command) { setAction(command); }
    
    QStringList valueLabels(void);
    QStringList valueStrings(void);
    
106 107
    QmlObjectListModel* textFieldFacts(void);
    QmlObjectListModel* checkboxFacts(void);
Don Gagne's avatar
Don Gagne committed
108 109 110 111
    
    double yawDegrees(void) const;
    void setYawDegrees(double yaw);
    
Don Gagne's avatar
Don Gagne committed
112 113 114
    bool dirty(void) { return _dirty; }
    void setDirty(bool dirty);
    
Don Gagne's avatar
Don Gagne committed
115
    // C++ only methods
Don Gagne's avatar
Don Gagne committed
116 117 118
    
    /// Returns true if this item can be edited in the ui
    bool canEdit(void);
119

120 121 122
    double latitude(void)  const { return _latitudeFact->value().toDouble(); }
    double longitude(void) const { return _longitudeFact->value().toDouble(); }
    double altitude(void)  const { return _altitudeFact->value().toDouble(); }
Don Gagne's avatar
Don Gagne committed
123 124 125 126 127 128 129 130 131 132 133 134 135
    
    void setLatitude(double latitude);
    void setLongitude(double longitude);
    void setAltitude(double altitude);
    
    double x(void) const { return latitude(); }
    double y(void) const { return longitude(); }
    double z(void) const { return altitude(); }
    
    void setX(double x);
    void setY(double y);
    void setZ(double z);
    
Don Gagne's avatar
Don Gagne committed
136 137
    double yawRadians(void) const;
    void setYawRadians(double yaw);
Don Gagne's avatar
Don Gagne committed
138
    
Don Gagne's avatar
Don Gagne committed
139
    bool autoContinue() const {
140
        return _autocontinue;
141
    }
Don Gagne's avatar
Don Gagne committed
142 143
    double loiterOrbitRadius() const {
        return _loiterOrbitRadiusFact->value().toDouble();
144
    }
Don Gagne's avatar
Don Gagne committed
145 146
    double acceptanceRadius() const {
        return param2();
147
    }
Don Gagne's avatar
Don Gagne committed
148 149
    double holdTime() const {
        return param1();
150
    }
Don Gagne's avatar
Don Gagne committed
151
    double param1() const {
Don Gagne's avatar
Don Gagne committed
152
        return _param1Fact->value().toDouble();
153
    }
Don Gagne's avatar
Don Gagne committed
154
    double param2() const {
Don Gagne's avatar
Don Gagne committed
155
        return _param2Fact->value().toDouble();
156
    }
Don Gagne's avatar
Don Gagne committed
157
    double param3() const {
Don Gagne's avatar
Don Gagne committed
158
        return loiterOrbitRadius();
159
    }
Don Gagne's avatar
Don Gagne committed
160
    double param4() const {
Don Gagne's avatar
Don Gagne committed
161
        return yawRadians();
162
    }
Don Gagne's avatar
Don Gagne committed
163
    double param5() const {
Don Gagne's avatar
Don Gagne committed
164
        return latitude();
165
    }
Don Gagne's avatar
Don Gagne committed
166
    double param6() const {
Don Gagne's avatar
Don Gagne committed
167
        return longitude();
168
    }
Don Gagne's avatar
Don Gagne committed
169
    double param7() const {
Don Gagne's avatar
Don Gagne committed
170
        return altitude();
171
    }
172
    // MAV_FRAME
173 174
    int frame() const;
    
175
    // MAV_CMD
Don Gagne's avatar
Don Gagne committed
176 177
    int command() const {
        return _command;
178
    }
lm's avatar
lm committed
179 180
    /** @brief Returns true if x, y, z contain reasonable navigation data */
    bool isNavigationType();
181

182
    /** @brief Get the time this waypoint was reached */
Don Gagne's avatar
Don Gagne committed
183
    quint64 reachedTime() const { return _reachedTime; }
184

185 186
    void save(QTextStream &saveStream);
    bool load(QTextStream &loadStream);
187
    
Don Gagne's avatar
Don Gagne committed
188 189 190 191 192
signals:
    void sequenceNumberChanged(int sequenceNumber);
    void isCurrentItemChanged(bool isCurrentItem);
    void coordinateChanged(const QGeoCoordinate& coordinate);
    void yawChanged(double yaw);
Don Gagne's avatar
Don Gagne committed
193
    void dirtyChanged(bool dirty);
Don Gagne's avatar
Don Gagne committed
194 195 196

    /** @brief Announces a change to the waypoint data */
    void changed(MissionItem* wp);
197

198
    
Don Gagne's avatar
Don Gagne committed
199 200 201 202
    void commandNameChanged(QString type);
    void commandChanged(MavlinkQmlSingleton::Qml_MAV_CMD command);
    void valueLabelsChanged(QStringList valueLabels);
    void valueStringsChanged(QStringList valueStrings);
203
    
204
public:
205
    /** @brief Set the waypoint action */
206 207
    void setAction      (int _action);
    void setFrame       (int _frame);
pixhawk's avatar
pixhawk committed
208
    void setAutocontinue(bool autoContinue);
209
    void setCurrent     (bool _current);
Don Gagne's avatar
Don Gagne committed
210
    void setLoiterOrbitRadius (double radius);
211 212 213 214 215 216 217
    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);
218
    void setAcceptanceRadius(double radius);
219 220
    void setHoldTime    (int holdTime);
    void setHoldTime    (double holdTime);
lm's avatar
lm committed
221
    /** @brief Set waypoint as reached */
222
    void setReached     () { _reachedTime = QGC::groundTimeMilliseconds(); }
lm's avatar
lm committed
223
    /** @brief Wether this waypoint has been reached yet */
224 225
    bool isReached      () { return (_reachedTime > 0); }

226 227 228
    void setChanged() {
        emit changed(this);
    }
Don Gagne's avatar
Don Gagne committed
229 230 231
    
private slots:
    void _factValueChanged(QVariant value);
232

233 234
private:
    QString _oneDecimalString(double value);
Don Gagne's avatar
Don Gagne committed
235 236 237 238 239 240 241

private:
    typedef struct {
        MAV_CMD     command;
        const char* name;
    } MavCmd2Name_t;
    
Don Gagne's avatar
Don Gagne committed
242 243 244 245 246 247
    int                                 _sequenceNumber;
    int                                 _frame;
    MavlinkQmlSingleton::Qml_MAV_CMD    _command;
    bool                                _autocontinue;
    bool                                _isCurrentItem;
    quint64                             _reachedTime;
Don Gagne's avatar
Don Gagne committed
248
    
249 250 251
    Fact*           _latitudeFact;
    Fact*           _longitudeFact;
    Fact*           _altitudeFact;
Don Gagne's avatar
Don Gagne committed
252 253
    Fact*           _yawRadiansFact;
    Fact*           _loiterOrbitRadiusFact;
Don Gagne's avatar
Don Gagne committed
254 255
    Fact*           _param1Fact;
    Fact*           _param2Fact;
256
    Fact*           _altitudeRelativeToHomeFact;
Don Gagne's avatar
Don Gagne committed
257 258 259 260 261 262 263 264 265 266
    
    FactMetaData*   _pitchMetaData;
    FactMetaData*   _acceptanceRadiusMetaData;
    FactMetaData*   _holdTimeMetaData;
    FactMetaData*   _loiterTurnsMetaData;
    FactMetaData*   _loiterSecondsMetaData;
    FactMetaData*   _delaySecondsMetaData;
    FactMetaData*   _jumpSequenceMetaData;
    FactMetaData*   _jumpRepeatMetaData;
    
Don Gagne's avatar
Don Gagne committed
267 268
    bool _dirty;
    
Don Gagne's avatar
Don Gagne committed
269 270
    static const int            _cMavCmd2Name = 9;
    static const MavCmd2Name_t  _rgMavCmd2Name[_cMavCmd2Name];
pixhawk's avatar
pixhawk committed
271 272
};

273 274 275
QDebug operator<<(QDebug dbg, const MissionItem& missionItem);
QDebug operator<<(QDebug dbg, const MissionItem* missionItem);

276
#endif