FixedWingLandingComplexItem.h 10.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#ifndef FixedWingLandingComplexItem_H
#define FixedWingLandingComplexItem_H

#include "ComplexMissionItem.h"
#include "MissionItem.h"
#include "Fact.h"
#include "QGCLoggingCategory.h"

Q_DECLARE_LOGGING_CATEGORY(FixedWingLandingComplexItemLog)

20 21
class FWLandingPatternTest;

22 23 24 25 26
class FixedWingLandingComplexItem : public ComplexMissionItem
{
    Q_OBJECT

public:
27
    FixedWingLandingComplexItem(Vehicle* vehicle, bool flyView, QObject* parent);
28

29 30 31 32
    Q_PROPERTY(Fact*            loiterAltitude          READ    loiterAltitude                                          CONSTANT)
    Q_PROPERTY(Fact*            loiterRadius            READ    loiterRadius                                            CONSTANT)
    Q_PROPERTY(Fact*            landingAltitude         READ    landingAltitude                                         CONSTANT)
    Q_PROPERTY(Fact*            landingHeading          READ    landingHeading                                          CONSTANT)
33
    Q_PROPERTY(Fact*            valueSetIsDistance      READ    valueSetIsDistance                                      CONSTANT)
34 35 36 37
    Q_PROPERTY(Fact*            landingDistance         READ    landingDistance                                         CONSTANT)
    Q_PROPERTY(Fact*            glideSlope              READ    glideSlope                                              CONSTANT)
    Q_PROPERTY(bool             loiterClockwise         MEMBER  _loiterClockwise                                        NOTIFY loiterClockwiseChanged)
    Q_PROPERTY(bool             altitudesAreRelative    MEMBER  _altitudesAreRelative                                   NOTIFY altitudesAreRelativeChanged)
38 39
    Q_PROPERTY(Fact*            stopTakingPhotos        READ    stopTakingPhotos                                        CONSTANT)
    Q_PROPERTY(Fact*            stopTakingVideo         READ    stopTakingVideo                                         CONSTANT)
40 41 42 43
    Q_PROPERTY(QGeoCoordinate   loiterCoordinate        READ    loiterCoordinate            WRITE setLoiterCoordinate   NOTIFY loiterCoordinateChanged)
    Q_PROPERTY(QGeoCoordinate   loiterTangentCoordinate READ    loiterTangentCoordinate                                 NOTIFY loiterTangentCoordinateChanged)
    Q_PROPERTY(QGeoCoordinate   landingCoordinate       READ    landingCoordinate           WRITE setLandingCoordinate  NOTIFY landingCoordinateChanged)
    Q_PROPERTY(bool             landingCoordSet         MEMBER _landingCoordSet                                         NOTIFY landingCoordSetChanged)
44 45 46 47 48 49

    Fact*           loiterAltitude          (void) { return &_loiterAltitudeFact; }
    Fact*           loiterRadius            (void) { return &_loiterRadiusFact; }
    Fact*           landingAltitude         (void) { return &_landingAltitudeFact; }
    Fact*           landingDistance         (void) { return &_landingDistanceFact; }
    Fact*           landingHeading          (void) { return &_landingHeadingFact; }
50
    Fact*           glideSlope              (void) { return &_glideSlopeFact; }
51 52
    Fact*           stopTakingPhotos        (void) { return &_stopTakingPhotosFact; }
    Fact*           stopTakingVideo         (void) { return &_stopTakingVideoFact; }
53
    Fact*           valueSetIsDistance      (void) { return &_valueSetIsDistanceFact; }
54 55 56 57 58 59
    QGeoCoordinate  landingCoordinate       (void) const { return _landingCoordinate; }
    QGeoCoordinate  loiterCoordinate        (void) const { return _loiterCoordinate; }
    QGeoCoordinate  loiterTangentCoordinate (void) const { return _loiterTangentCoordinate; }

    void setLandingCoordinate       (const QGeoCoordinate& coordinate);
    void setLoiterCoordinate        (const QGeoCoordinate& coordinate);
60

61
    /// Scans the loaded items for a landing pattern complex item
62
    static bool scanForItem(QmlObjectListModel* visualItems, bool flyView, Vehicle* vehicle);
63

64 65 66 67
    static MissionItem* createDoLandStartItem   (int seqNum, QObject* parent);
    static MissionItem* createLoiterToAltItem   (int seqNum, bool altRel, double loiterRaidus, double lat, double lon, double alt, QObject* parent);
    static MissionItem* createLandItem          (int seqNum, bool altRel, double lat, double lon, double alt, QObject* parent);

68 69 70 71 72 73
    // Overrides from ComplexMissionItem

    double              complexDistance     (void) const final;
    int                 lastSequenceNumber  (void) const final;
    bool                load                (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) final;
    double              greatestDistanceTo  (const QGeoCoordinate &other) const final;
74
    QString             mapVisualQML        (void) const final { return QStringLiteral("FWLandingPatternMapVisual.qml"); }
75 76 77 78 79 80 81

    // Overrides from VisualMissionItem

    bool            dirty                   (void) const final { return _dirty; }
    bool            isSimpleItem            (void) const final { return false; }
    bool            isStandaloneCoordinate  (void) const final { return false; }
    bool            specifiesCoordinate     (void) const final;
82
    bool            specifiesAltitudeOnly   (void) const final { return false; }
83 84 85
    QString         commandDescription      (void) const final { return "Landing Pattern"; }
    QString         commandName             (void) const final { return "Landing Pattern"; }
    QString         abbreviation            (void) const final { return "L"; }
86 87
    QGeoCoordinate  coordinate              (void) const final { return _loiterCoordinate; }
    QGeoCoordinate  exitCoordinate          (void) const final { return _landingCoordinate; }
88
    int             sequenceNumber          (void) const final { return _sequenceNumber; }
DonLakeFlyer's avatar
DonLakeFlyer committed
89 90
    double          specifiedFlightSpeed    (void) final { return std::numeric_limits<double>::quiet_NaN(); }
    double          specifiedGimbalYaw      (void) final { return std::numeric_limits<double>::quiet_NaN(); }
91
    double          specifiedGimbalPitch    (void) final { return std::numeric_limits<double>::quiet_NaN(); }
92
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
93
    void            applyNewAltitude        (double newAltitude) final;
94
    double          additionalTimeDelay     (void) const final { return 0; }
95

96 97
    bool coordinateHasRelativeAltitude      (void) const final { return _altitudesAreRelative; }
    bool exitCoordinateHasRelativeAltitude  (void) const final { return _altitudesAreRelative; }
98
    bool exitCoordinateSameAsEntry          (void) const final { return false; }
99 100

    void setDirty           (bool dirty) final;
101
    void setCoordinate      (const QGeoCoordinate& coordinate) final { setLoiterCoordinate(coordinate); }
102
    void setSequenceNumber  (int sequenceNumber) final;
103
    void save               (QJsonArray&  missionItems) final;
104 105 106

    static const char* jsonComplexItemTypeValue;

107
    static const char* settingsGroup;
108 109 110 111 112
    static const char* loiterToLandDistanceName;
    static const char* loiterAltitudeName;
    static const char* loiterRadiusName;
    static const char* landingHeadingName;
    static const char* landingAltitudeName;
113
    static const char* glideSlopeName;
114 115
    static const char* stopTakingPhotosName;
    static const char* stopTakingVideoName;
116
    static const char* valueSetIsDistanceName;
117

118
signals:
119
    void loiterCoordinateChanged        (QGeoCoordinate coordinate);
120
    void loiterTangentCoordinateChanged (QGeoCoordinate coordinate);
121 122 123
    void landingCoordinateChanged       (QGeoCoordinate coordinate);
    void landingCoordSetChanged         (bool landingCoordSet);
    void loiterClockwiseChanged         (bool loiterClockwise);
124 125
    void altitudesAreRelativeChanged    (bool altitudesAreRelative);
    void valueSetIsDistanceChanged      (bool valueSetIsDistance);
126 127

private slots:
128 129 130 131 132 133 134 135 136
    void    _recalcFromHeadingAndDistanceChange     (void);
    void    _recalcFromCoordinateChange             (void);
    void    _recalcFromRadiusChange                 (void);
    void    _updateLoiterCoodinateAltitudeFromFact  (void);
    void    _updateLandingCoodinateAltitudeFromFact (void);
    double  _mathematicAngleToHeading               (double angle);
    double  _headingToMathematicAngle               (double heading);
    void    _setDirty                               (void);
    void    _glideSlopeChanged                      (void);
137
    void    _signalLastSequenceNumberChanged        (void);
138 139

private:
140 141
    QPointF _rotatePoint    (const QPointF& point, const QPointF& origin, double angle);
    void    _calcGlideSlope (void);
142 143 144

    int             _sequenceNumber;
    bool            _dirty;
145
    QGeoCoordinate  _loiterCoordinate;
146
    QGeoCoordinate  _loiterTangentCoordinate;
147 148 149
    QGeoCoordinate  _landingCoordinate;
    bool            _landingCoordSet;
    bool            _ignoreRecalcSignals;
150

151 152
    QMap<QString, FactMetaData*> _metaDataMap;

153
    Fact            _landingDistanceFact;
154 155 156
    Fact            _loiterAltitudeFact;
    Fact            _loiterRadiusFact;
    Fact            _landingHeadingFact;
157
    Fact            _landingAltitudeFact;
158
    Fact            _glideSlopeFact;
159 160
    Fact            _stopTakingPhotosFact;
    Fact            _stopTakingVideoFact;
161
    Fact            _valueSetIsDistanceFact;
162

163
    bool            _loiterClockwise;
164
    bool            _altitudesAreRelative;
165

166 167 168 169
    static const char* _jsonLoiterCoordinateKey;
    static const char* _jsonLoiterRadiusKey;
    static const char* _jsonLoiterClockwiseKey;
    static const char* _jsonLandingCoordinateKey;
170 171
    static const char* _jsonValueSetIsDistanceKey;
    static const char* _jsonAltitudesAreRelativeKey;
172 173
    static const char* _jsonStopTakingPhotosKey;
    static const char* _jsonStopTakingVideoKey;
174 175

    // Only in older file formats
176
    static const char* _jsonLandingAltitudeRelativeKey;
177
    static const char* _jsonLoiterAltitudeRelativeKey;
178
    static const char* _jsonFallRateKey;
179 180

    friend FWLandingPatternTest;
181 182 183
};

#endif