FixedWingLandingComplexItem.h 7.81 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
 *
 * 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

13
#include "LandingComplexItem.h"
14 15 16 17 18 19
#include "MissionItem.h"
#include "Fact.h"
#include "QGCLoggingCategory.h"

Q_DECLARE_LOGGING_CATEGORY(FixedWingLandingComplexItemLog)

20
class FWLandingPatternTest;
21
class PlanMasterController;
22

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

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

30 31
    Q_PROPERTY(Fact*            valueSetIsDistance      READ    valueSetIsDistance                                          CONSTANT)
    Q_PROPERTY(Fact*            glideSlope              READ    glideSlope                                                  CONSTANT)
32 33

    Q_INVOKABLE void moveLandingPosition(const QGeoCoordinate& coordinate); // Maintains the current landing distance and heading
34

35 36 37 38 39 40 41
    Fact*           loiterAltitude          (void) final { return &_loiterAltitudeFact; }
    Fact*           loiterRadius            (void) final { return &_loiterRadiusFact; }
    Fact*           landingAltitude         (void) final { return &_landingAltitudeFact; }
    Fact*           landingDistance         (void) final { return &_landingDistanceFact; }
    Fact*           landingHeading          (void) final { return &_landingHeadingFact; }
    Fact*           stopTakingPhotos        (void) final { return &_stopTakingPhotosFact; }
    Fact*           stopTakingVideo         (void) final { return &_stopTakingVideoFact; }
42
    Fact*           glideSlope              (void) { return &_glideSlopeFact; }
43
    Fact*           valueSetIsDistance      (void) { return &_valueSetIsDistanceFact; }
44

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

48 49 50 51
    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);

52
    // Overrides from ComplexMissionItem
53 54 55 56 57
    QString patternName         (void) const final { return name; }
    int     lastSequenceNumber  (void) const final;
    bool    load                (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) final;
    double  greatestDistanceTo  (const QGeoCoordinate &other) const final;
    QString mapVisualQML        (void) const final { return QStringLiteral("FWLandingPatternMapVisual.qml"); }
58 59

    // Overrides from VisualMissionItem
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    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;
    bool                specifiesAltitudeOnly       (void) const final { return false; }
    QString             commandDescription          (void) const final { return "Landing Pattern"; }
    QString             commandName                 (void) const final { return "Landing Pattern"; }
    QString             abbreviation                (void) const final { return "L"; }
    QGeoCoordinate      coordinate                  (void) const final { return _loiterCoordinate; }
    QGeoCoordinate      exitCoordinate              (void) const final { return _landingCoordinate; }
    int                 sequenceNumber              (void) const final { return _sequenceNumber; }
    double              specifiedFlightSpeed        (void) final { return std::numeric_limits<double>::quiet_NaN(); }
    double              specifiedGimbalYaw          (void) final { return std::numeric_limits<double>::quiet_NaN(); }
    double              specifiedGimbalPitch        (void) final { return std::numeric_limits<double>::quiet_NaN(); }
    void                appendMissionItems          (QList<MissionItem*>& items, QObject* missionItemParent) final;
    void                applyNewAltitude            (double newAltitude) final;
    double              additionalTimeDelay         (void) const final { return 0; }
    ReadyForSaveState   readyForSaveState           (void) const final;
    bool                exitCoordinateSameAsEntry   (void) const final { return false; }
    void                setDirty                    (bool dirty) final;
    void                setCoordinate               (const QGeoCoordinate& coordinate) final { setLoiterCoordinate(coordinate); }
    void                setSequenceNumber           (int sequenceNumber) final;
    void                save                        (QJsonArray&  missionItems) final;
    double              amslEntryAlt                (void) const final;
    double              amslExitAlt                 (void) const final;
    double              minAMSLAltitude             (void) const final { return amslExitAlt(); }
    double              maxAMSLAltitude             (void) const final { return amslEntryAlt(); }

    static const QString name;
89 90 91

    static const char* jsonComplexItemTypeValue;

92
    static const char* settingsGroup;
93 94 95 96 97
    static const char* loiterToLandDistanceName;
    static const char* loiterAltitudeName;
    static const char* loiterRadiusName;
    static const char* landingHeadingName;
    static const char* landingAltitudeName;
98
    static const char* glideSlopeName;
99 100
    static const char* stopTakingPhotosName;
    static const char* stopTakingVideoName;
101
    static const char* valueSetIsDistanceName;
102

103
signals:
104
    void valueSetIsDistanceChanged      (bool valueSetIsDistance);
105 106

private slots:
107 108 109 110 111 112 113 114 115 116
    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);
    void    _signalLastSequenceNumberChanged            (void);
117 118

private:
119
    void    _calcGlideSlope                 (void);
120

121 122
    QMap<QString, FactMetaData*> _metaDataMap;

123
    Fact            _landingDistanceFact;
124 125 126
    Fact            _loiterAltitudeFact;
    Fact            _loiterRadiusFact;
    Fact            _landingHeadingFact;
127
    Fact            _landingAltitudeFact;
128
    Fact            _glideSlopeFact;
129 130
    Fact            _stopTakingPhotosFact;
    Fact            _stopTakingVideoFact;
131
    Fact            _valueSetIsDistanceFact;
132

133 134 135 136
    static const char* _jsonLoiterCoordinateKey;
    static const char* _jsonLoiterRadiusKey;
    static const char* _jsonLoiterClockwiseKey;
    static const char* _jsonLandingCoordinateKey;
137 138
    static const char* _jsonValueSetIsDistanceKey;
    static const char* _jsonAltitudesAreRelativeKey;
139 140
    static const char* _jsonStopTakingPhotosKey;
    static const char* _jsonStopTakingVideoKey;
141 142

    // Only in older file formats
143
    static const char* _jsonLandingAltitudeRelativeKey;
144
    static const char* _jsonLoiterAltitudeRelativeKey;
145
    static const char* _jsonFallRateKey;
146 147

    friend FWLandingPatternTest;
148 149 150
};

#endif