FixedWingLandingComplexItem.h 10.7 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * 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
class FWLandingPatternTest;
21
class PlanMasterController;
22

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

public:
28
    FixedWingLandingComplexItem(PlanMasterController* masterController, bool flyView, QObject* parent);
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    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)
    Q_PROPERTY(Fact*            valueSetIsDistance      READ    valueSetIsDistance                                          CONSTANT)
    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)
    Q_PROPERTY(Fact*            stopTakingPhotos        READ    stopTakingPhotos                                            CONSTANT)
    Q_PROPERTY(Fact*            stopTakingVideo         READ    stopTakingVideo                                             CONSTANT)
    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)
    Q_PROPERTY(bool             loiterDragAngleOnly     READ    loiterDragAngleOnly         WRITE setLoiterDragAngleOnly    NOTIFY loiterDragAngleOnlyChanged)
46 47 48 49 50 51

    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; }
52
    Fact*           glideSlope              (void) { return &_glideSlopeFact; }
53 54
    Fact*           stopTakingPhotos        (void) { return &_stopTakingPhotosFact; }
    Fact*           stopTakingVideo         (void) { return &_stopTakingVideoFact; }
55
    Fact*           valueSetIsDistance      (void) { return &_valueSetIsDistanceFact; }
56 57 58
    QGeoCoordinate  landingCoordinate       (void) const { return _landingCoordinate; }
    QGeoCoordinate  loiterCoordinate        (void) const { return _loiterCoordinate; }
    QGeoCoordinate  loiterTangentCoordinate (void) const { return _loiterTangentCoordinate; }
59
    bool            loiterDragAngleOnly     (void) const { return _loiterDragAngleOnly; }
60 61 62

    void setLandingCoordinate       (const QGeoCoordinate& coordinate);
    void setLoiterCoordinate        (const QGeoCoordinate& coordinate);
63
    void setLoiterDragAngleOnly     (bool loiterDragAngleOnly);
64

65
    /// Scans the loaded items for a landing pattern complex item
66
    static bool scanForItem(QmlObjectListModel* visualItems, bool flyView, PlanMasterController* masterController);
67

68 69 70 71
    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);

72 73 74 75 76
    // 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;
77
    QString             mapVisualQML        (void) const final { return QStringLiteral("FWLandingPatternMapVisual.qml"); }
78 79 80 81 82 83

    // 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;
84
    bool            specifiesAltitudeOnly   (void) const final { return false; }
85 86 87
    QString         commandDescription      (void) const final { return "Landing Pattern"; }
    QString         commandName             (void) const final { return "Landing Pattern"; }
    QString         abbreviation            (void) const final { return "L"; }
88 89
    QGeoCoordinate  coordinate              (void) const final { return _loiterCoordinate; }
    QGeoCoordinate  exitCoordinate          (void) const final { return _landingCoordinate; }
90
    int             sequenceNumber          (void) const final { return _sequenceNumber; }
DonLakeFlyer's avatar
DonLakeFlyer committed
91 92
    double          specifiedFlightSpeed    (void) final { return std::numeric_limits<double>::quiet_NaN(); }
    double          specifiedGimbalYaw      (void) final { return std::numeric_limits<double>::quiet_NaN(); }
93
    double          specifiedGimbalPitch    (void) final { return std::numeric_limits<double>::quiet_NaN(); }
94
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
95
    void            applyNewAltitude        (double newAltitude) final;
96
    double          additionalTimeDelay     (void) const final { return 0; }
DonLakeFlyer's avatar
DonLakeFlyer committed
97
    ReadyForSaveState readyForSaveState     (void) const final;
98

99 100
    bool coordinateHasRelativeAltitude      (void) const final { return _altitudesAreRelative; }
    bool exitCoordinateHasRelativeAltitude  (void) const final { return _altitudesAreRelative; }
101
    bool exitCoordinateSameAsEntry          (void) const final { return false; }
102 103

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

    static const char* jsonComplexItemTypeValue;

110
    static const char* settingsGroup;
111 112 113 114 115
    static const char* loiterToLandDistanceName;
    static const char* loiterAltitudeName;
    static const char* loiterRadiusName;
    static const char* landingHeadingName;
    static const char* landingAltitudeName;
116
    static const char* glideSlopeName;
117 118
    static const char* stopTakingPhotosName;
    static const char* stopTakingVideoName;
119
    static const char* valueSetIsDistanceName;
120

121
signals:
122
    void loiterCoordinateChanged        (QGeoCoordinate coordinate);
123
    void loiterTangentCoordinateChanged (QGeoCoordinate coordinate);
124 125 126
    void landingCoordinateChanged       (QGeoCoordinate coordinate);
    void landingCoordSetChanged         (bool landingCoordSet);
    void loiterClockwiseChanged         (bool loiterClockwise);
127 128
    void altitudesAreRelativeChanged    (bool altitudesAreRelative);
    void valueSetIsDistanceChanged      (bool valueSetIsDistance);
129
    void loiterDragAngleOnlyChanged     (bool loiterDragAngleOnly);
130 131

private slots:
132 133 134 135 136 137 138 139 140
    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);
141
    void    _signalLastSequenceNumberChanged        (void);
142 143

private:
144 145
    QPointF _rotatePoint    (const QPointF& point, const QPointF& origin, double angle);
    void    _calcGlideSlope (void);
146 147 148

    int             _sequenceNumber;
    bool            _dirty;
149
    QGeoCoordinate  _loiterCoordinate;
150
    QGeoCoordinate  _loiterTangentCoordinate;
151 152 153
    QGeoCoordinate  _landingCoordinate;
    bool            _landingCoordSet;
    bool            _ignoreRecalcSignals;
154
    bool            _loiterDragAngleOnly;
155

156 157
    QMap<QString, FactMetaData*> _metaDataMap;

158
    Fact            _landingDistanceFact;
159 160 161
    Fact            _loiterAltitudeFact;
    Fact            _loiterRadiusFact;
    Fact            _landingHeadingFact;
162
    Fact            _landingAltitudeFact;
163
    Fact            _glideSlopeFact;
164 165
    Fact            _stopTakingPhotosFact;
    Fact            _stopTakingVideoFact;
166
    Fact            _valueSetIsDistanceFact;
167

168
    bool            _loiterClockwise;
169
    bool            _altitudesAreRelative;
170

171 172 173 174
    static const char* _jsonLoiterCoordinateKey;
    static const char* _jsonLoiterRadiusKey;
    static const char* _jsonLoiterClockwiseKey;
    static const char* _jsonLandingCoordinateKey;
175 176
    static const char* _jsonValueSetIsDistanceKey;
    static const char* _jsonAltitudesAreRelativeKey;
177 178
    static const char* _jsonStopTakingPhotosKey;
    static const char* _jsonStopTakingVideoKey;
179 180

    // Only in older file formats
181
    static const char* _jsonLandingAltitudeRelativeKey;
182
    static const char* _jsonLoiterAltitudeRelativeKey;
183
    static const char* _jsonFallRateKey;
184 185

    friend FWLandingPatternTest;
186 187 188
};

#endif