FixedWingLandingComplexItem.h 7.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/****************************************************************************
 *
 *   (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)

class FixedWingLandingComplexItem : public ComplexMissionItem
{
    Q_OBJECT

public:
25
    FixedWingLandingComplexItem(Vehicle* vehicle, QObject* parent = NULL);
26

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    Q_PROPERTY(Fact*            loiterAltitude          READ    loiterAltitude                                                  CONSTANT)
    Q_PROPERTY(Fact*            loiterRadius            READ    loiterRadius                                                    CONSTANT)
    Q_PROPERTY(Fact*            landingAltitude         READ    landingAltitude                                                 CONSTANT)
    Q_PROPERTY(Fact*            landingDistance         READ    landingDistance                                                 CONSTANT)
    Q_PROPERTY(Fact*            landingHeading          READ    landingHeading                                                  CONSTANT)
    Q_PROPERTY(bool             loiterClockwise         MEMBER  _loiterClockwise                                                NOTIFY loiterClockwiseChanged)
    Q_PROPERTY(bool             loiterAltitudeRelative  MEMBER  _loiterAltitudeRelative                                         NOTIFY loiterAltitudeRelativeChanged)
    Q_PROPERTY(bool             landingAltitudeRelative MEMBER  _landingAltitudeRelative                                        NOTIFY landingAltitudeRelativeChanged)
    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)

    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; }
    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);
51 52 53 54 55 56 57 58

    // 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;
    void                setCruiseSpeed      (double cruiseSpeed) final;
59
    QString             mapVisualQML        (void) const final { return QStringLiteral("FWLandingPatternMapVisual.qml"); }
60 61 62 63 64 65 66 67 68 69

    // 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;
    QString         commandDescription      (void) const final { return "Landing Pattern"; }
    QString         commandName             (void) const final { return "Landing Pattern"; }
    QString         abbreviation            (void) const final { return "L"; }
70 71
    QGeoCoordinate  coordinate              (void) const final { return _loiterCoordinate; }
    QGeoCoordinate  exitCoordinate          (void) const final { return _landingCoordinate; }
72 73
    int             sequenceNumber          (void) const final { return _sequenceNumber; }
    double          flightSpeed             (void) final { return std::numeric_limits<double>::quiet_NaN(); }
74
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
75 76 77 78 79 80

    bool coordinateHasRelativeAltitude      (void) const final { return true; }
    bool exitCoordinateHasRelativeAltitude  (void) const final { return true; }
    bool exitCoordinateSameAsEntry          (void) const final { return true; }

    void setDirty           (bool dirty) final;
81
    void setCoordinate      (const QGeoCoordinate& coordinate) final { setLoiterCoordinate(coordinate); }
82
    void setSequenceNumber  (int sequenceNumber) final;
83
    void save               (QJsonArray&  missionItems) final;
84 85 86 87

    static const char* jsonComplexItemTypeValue;

signals:
88
    void loiterCoordinateChanged        (QGeoCoordinate coordinate);
89
    void loiterTangentCoordinateChanged (QGeoCoordinate coordinate);
90 91 92 93 94
    void landingCoordinateChanged       (QGeoCoordinate coordinate);
    void landingCoordSetChanged         (bool landingCoordSet);
    void loiterClockwiseChanged         (bool loiterClockwise);
    void loiterAltitudeRelativeChanged  (bool loiterAltitudeRelative);
    void landingAltitudeRelativeChanged (bool loiterAltitudeRelative);
95 96

private slots:
97 98 99
    void _recalcFromHeadingAndDistanceChange(void);
    void _recalcFromCoordinateChange(void);
    void _recalcFromRadiusChange(void);
100 101
    void _updateLoiterCoodinateAltitudeFromFact(void);
    void _updateLandingCoodinateAltitudeFromFact(void);
102 103
    double _mathematicAngleToHeading(double angle);
    double _headingToMathematicAngle(double heading);
104
    void _setDirty(void);
105 106

private:
107
    QPointF _rotatePoint(const QPointF& point, const QPointF& origin, double angle);
108 109 110

    int             _sequenceNumber;
    bool            _dirty;
111
    QGeoCoordinate  _loiterCoordinate;
112
    QGeoCoordinate  _loiterTangentCoordinate;
113 114 115
    QGeoCoordinate  _landingCoordinate;
    bool            _landingCoordSet;
    bool            _ignoreRecalcSignals;
116

117
    Fact            _landingDistanceFact;
118 119 120
    Fact            _loiterAltitudeFact;
    Fact            _loiterRadiusFact;
    Fact            _landingHeadingFact;
121
    Fact            _landingAltitudeFact;
122

123 124 125
    bool            _loiterClockwise;
    bool            _loiterAltitudeRelative;
    bool            _landingAltitudeRelative;
126

127
    static QMap<QString, FactMetaData*> _metaDataMap;
128 129 130 131 132

    static const char* _loiterToLandDistanceName;
    static const char* _loiterAltitudeName;
    static const char* _loiterRadiusName;
    static const char* _landingHeadingName;
133
    static const char* _landingAltitudeName;
134 135 136 137 138 139 140

    static const char* _jsonLoiterCoordinateKey;
    static const char* _jsonLoiterRadiusKey;
    static const char* _jsonLoiterClockwiseKey;
    static const char* _jsonLoiterAltitudeRelativeKey;
    static const char* _jsonLandingCoordinateKey;
    static const char* _jsonLandingAltitudeRelativeKey;
141 142 143
};

#endif