SurveyComplexItem.h 16.8 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

10
#pragma once
11 12 13

#include "ComplexMissionItem.h"
#include "MissionItem.h"
14
#include "SettingsFact.h"
15
#include "QGCLoggingCategory.h"
16
#include "QGCMapPolygon.h"
17

18
Q_DECLARE_LOGGING_CATEGORY(SurveyComplexItemLog)
19

20
class SurveyComplexItem : public ComplexMissionItem
21 22 23 24
{
    Q_OBJECT

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

Don Gagne's avatar
Don Gagne committed
27
    Q_PROPERTY(Fact*                gridAltitude                READ gridAltitude                   CONSTANT)
28
    Q_PROPERTY(Fact*                gridAltitudeRelative        READ gridAltitudeRelative           CONSTANT)
Don Gagne's avatar
Don Gagne committed
29 30
    Q_PROPERTY(Fact*                gridAngle                   READ gridAngle                      CONSTANT)
    Q_PROPERTY(Fact*                gridSpacing                 READ gridSpacing                    CONSTANT)
DonLakeFlyer's avatar
DonLakeFlyer committed
31
    Q_PROPERTY(Fact*                gridEntryLocation           READ gridEntryLocation              CONSTANT)
Don Gagne's avatar
Don Gagne committed
32 33
    Q_PROPERTY(Fact*                turnaroundDist              READ turnaroundDist                 CONSTANT)
    Q_PROPERTY(Fact*                cameraTriggerDistance       READ cameraTriggerDistance          CONSTANT)
34 35
    Q_PROPERTY(Fact*                cameraTriggerInTurnaround   READ cameraTriggerInTurnaround      CONSTANT)
    Q_PROPERTY(Fact*                hoverAndCapture             READ hoverAndCapture                CONSTANT)
Don Gagne's avatar
Don Gagne committed
36 37 38 39 40 41 42 43
    Q_PROPERTY(Fact*                groundResolution            READ groundResolution               CONSTANT)
    Q_PROPERTY(Fact*                frontalOverlap              READ frontalOverlap                 CONSTANT)
    Q_PROPERTY(Fact*                sideOverlap                 READ sideOverlap                    CONSTANT)
    Q_PROPERTY(Fact*                cameraSensorWidth           READ cameraSensorWidth              CONSTANT)
    Q_PROPERTY(Fact*                cameraSensorHeight          READ cameraSensorHeight             CONSTANT)
    Q_PROPERTY(Fact*                cameraResolutionWidth       READ cameraResolutionWidth          CONSTANT)
    Q_PROPERTY(Fact*                cameraResolutionHeight      READ cameraResolutionHeight         CONSTANT)
    Q_PROPERTY(Fact*                cameraFocalLength           READ cameraFocalLength              CONSTANT)
44
    Q_PROPERTY(Fact*                cameraOrientationLandscape  READ cameraOrientationLandscape     CONSTANT)
45
    Q_PROPERTY(Fact*                fixedValueIsAltitude        READ fixedValueIsAltitude           CONSTANT)
46 47 48
    Q_PROPERTY(Fact*                manualGrid                  READ manualGrid                     CONSTANT)
    Q_PROPERTY(Fact*                camera                      READ camera                         CONSTANT)

49
    Q_PROPERTY(bool                 cameraOrientationFixed      MEMBER _cameraOrientationFixed      NOTIFY cameraOrientationFixedChanged)
DonLakeFlyer's avatar
DonLakeFlyer committed
50
    Q_PROPERTY(bool                 hoverAndCaptureAllowed      READ hoverAndCaptureAllowed         CONSTANT)
51
    Q_PROPERTY(bool                 refly90Degrees              READ refly90Degrees WRITE setRefly90Degrees NOTIFY refly90DegreesChanged)
52
    Q_PROPERTY(double               cameraMinTriggerInterval    MEMBER _cameraMinTriggerInterval    NOTIFY cameraMinTriggerIntervalChanged)
53

54
    Q_PROPERTY(double               timeBetweenShots            READ timeBetweenShots               NOTIFY timeBetweenShotsChanged)
Don Gagne's avatar
Don Gagne committed
55 56 57
    Q_PROPERTY(QVariantList         gridPoints                  READ gridPoints                     NOTIFY gridPointsChanged)
    Q_PROPERTY(int                  cameraShots                 READ cameraShots                    NOTIFY cameraShotsChanged)
    Q_PROPERTY(double               coveredArea                 READ coveredArea                    NOTIFY coveredAreaChanged)
58

59 60
    Q_PROPERTY(QGCMapPolygon*       mapPolygon                  READ mapPolygon                     CONSTANT)

61
    QVariantList gridPoints (void) { return _simpleGridPoints; }
62

63
    Fact* manualGrid                (void) { return &_manualGridFact; }
Don Gagne's avatar
Don Gagne committed
64
    Fact* gridAltitude              (void) { return &_gridAltitudeFact; }
65
    Fact* gridAltitudeRelative      (void) { return &_gridAltitudeRelativeFact; }
Don Gagne's avatar
Don Gagne committed
66 67
    Fact* gridAngle                 (void) { return &_gridAngleFact; }
    Fact* gridSpacing               (void) { return &_gridSpacingFact; }
DonLakeFlyer's avatar
DonLakeFlyer committed
68
    Fact* gridEntryLocation         (void) { return &_gridEntryLocationFact; }
Don Gagne's avatar
Don Gagne committed
69 70
    Fact* turnaroundDist            (void) { return &_turnaroundDistFact; }
    Fact* cameraTriggerDistance     (void) { return &_cameraTriggerDistanceFact; }
71 72
    Fact* cameraTriggerInTurnaround (void) { return &_cameraTriggerInTurnaroundFact; }
    Fact* hoverAndCapture           (void) { return &_hoverAndCaptureFact; }
Don Gagne's avatar
Don Gagne committed
73 74 75 76 77 78 79 80
    Fact* groundResolution          (void) { return &_groundResolutionFact; }
    Fact* frontalOverlap            (void) { return &_frontalOverlapFact; }
    Fact* sideOverlap               (void) { return &_sideOverlapFact; }
    Fact* cameraSensorWidth         (void) { return &_cameraSensorWidthFact; }
    Fact* cameraSensorHeight        (void) { return &_cameraSensorHeightFact; }
    Fact* cameraResolutionWidth     (void) { return &_cameraResolutionWidthFact; }
    Fact* cameraResolutionHeight    (void) { return &_cameraResolutionHeightFact; }
    Fact* cameraFocalLength         (void) { return &_cameraFocalLengthFact; }
81 82 83
    Fact* cameraOrientationLandscape(void) { return &_cameraOrientationLandscapeFact; }
    Fact* fixedValueIsAltitude      (void) { return &_fixedValueIsAltitudeFact; }
    Fact* camera                    (void) { return &_cameraFact; }
84

85 86 87 88 89 90
    int             cameraShots             (void) const;
    double          coveredArea             (void) const { return _coveredArea; }
    double          timeBetweenShots        (void) const;
    bool            hoverAndCaptureAllowed  (void) const;
    bool            refly90Degrees          (void) const { return _refly90Degrees; }
    QGCMapPolygon*  mapPolygon              (void) { return &_mapPolygon; }
91 92

    void setRefly90Degrees(bool refly90Degrees);
93 94 95 96

    // Overrides from ComplexMissionItem

    double              complexDistance     (void) const final { return _surveyDistance; }
97
    double              additionalTimeDelay (void) const final { return _additionalFlightDelaySeconds; }
98
    int                 lastSequenceNumber  (void) const final;
Don Gagne's avatar
Don Gagne committed
99
    bool                load                (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) final;
100
    double              greatestDistanceTo  (const QGeoCoordinate &other) const final;
101
    QString             mapVisualQML        (void) const final { return QStringLiteral("SurveyMapVisual.qml"); }
102

103 104 105 106 107 108
    // 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;
109
    bool            specifiesAltitudeOnly   (void) const final { return false; }
110 111 112 113 114 115
    QString         commandDescription      (void) const final { return "Survey"; }
    QString         commandName             (void) const final { return "Survey"; }
    QString         abbreviation            (void) const final { return "S"; }
    QGeoCoordinate  coordinate              (void) const final { return _coordinate; }
    QGeoCoordinate  exitCoordinate          (void) const final { return _exitCoordinate; }
    int             sequenceNumber          (void) const final { return _sequenceNumber; }
DonLakeFlyer's avatar
DonLakeFlyer committed
116 117
    double          specifiedFlightSpeed    (void) final { return std::numeric_limits<double>::quiet_NaN(); }
    double          specifiedGimbalYaw      (void) final { return std::numeric_limits<double>::quiet_NaN(); }
118
    double          specifiedGimbalPitch    (void) final { return std::numeric_limits<double>::quiet_NaN(); }
119
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
120
    void            setMissionFlightStatus  (MissionController::MissionFlightStatus_t& missionFlightStatus) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
121
    void            applyNewAltitude        (double newAltitude) final;
122

123 124
    bool coordinateHasRelativeAltitude      (void) const final { return _gridAltitudeRelativeFact.rawValue().toBool(); }
    bool exitCoordinateHasRelativeAltitude  (void) const final { return _gridAltitudeRelativeFact.rawValue().toBool(); }
125 126 127 128 129
    bool exitCoordinateSameAsEntry          (void) const final { return false; }

    void setDirty           (bool dirty) final;
    void setCoordinate      (const QGeoCoordinate& coordinate) final;
    void setSequenceNumber  (int sequenceNumber) final;
130
    void setTurnaroundDist  (double dist) { _turnaroundDistFact.setRawValue(dist); }
131
    void save               (QJsonArray&  missionItems) final;
132

133 134 135 136 137 138 139 140
    // Must match json spec for GridEntryLocation
    enum EntryLocation {
        EntryLocationTopLeft,
        EntryLocationTopRight,
        EntryLocationBottomLeft,
        EntryLocationBottomRight,
    };

Don Gagne's avatar
Don Gagne committed
141 142
    static const char* jsonComplexItemTypeValue;

143 144 145 146 147 148
    static const char* settingsGroup;
    static const char* manualGridName;
    static const char* gridAltitudeName;
    static const char* gridAltitudeRelativeName;
    static const char* gridAngleName;
    static const char* gridSpacingName;
DonLakeFlyer's avatar
DonLakeFlyer committed
149
    static const char* gridEntryLocationName;
150 151
    static const char* turnaroundDistName;
    static const char* cameraTriggerDistanceName;
152 153
    static const char* cameraTriggerInTurnaroundName;
    static const char* hoverAndCaptureName;
154 155 156 157 158 159 160 161 162 163 164 165 166
    static const char* groundResolutionName;
    static const char* frontalOverlapName;
    static const char* sideOverlapName;
    static const char* cameraSensorWidthName;
    static const char* cameraSensorHeightName;
    static const char* cameraResolutionWidthName;
    static const char* cameraResolutionHeightName;
    static const char* cameraFocalLengthName;
    static const char* cameraTriggerName;
    static const char* cameraOrientationLandscapeName;
    static const char* fixedValueIsAltitudeName;
    static const char* cameraName;

167
signals:
168 169 170 171 172 173 174 175 176
    void gridPointsChanged                  (void);
    void cameraShotsChanged                 (int cameraShots);
    void coveredAreaChanged                 (double coveredArea);
    void cameraValueChanged                 (void);
    void gridTypeChanged                    (QString gridType);
    void timeBetweenShotsChanged            (void);
    void cameraOrientationFixedChanged      (bool cameraOrientationFixed);
    void refly90DegreesChanged              (bool refly90Degrees);
    void cameraMinTriggerIntervalChanged    (double cameraMinTriggerInterval);
177 178

private slots:
179
    void _setDirty(void);
180 181
    void _polygonDirtyChanged(bool dirty);
    void _clearInternal(void);
182 183

private:
184 185 186
    enum CameraTriggerCode {
        CameraTriggerNone,
        CameraTriggerOn,
DonLakeFlyer's avatar
DonLakeFlyer committed
187 188
        CameraTriggerOff,
        CameraTriggerHoverAndCapture
189 190
    };

191 192
    void _setExitCoordinate(const QGeoCoordinate& coordinate);
    void _generateGrid(void);
193
    void _updateCoordinateAltitude(void);
194
    int _gridGenerator(const QList<QPointF>& polygonPoints, QList<QList<QPointF>>& transectSegments, bool refly);
195 196 197 198 199 200 201
    QPointF _rotatePoint(const QPointF& point, const QPointF& origin, double angle);
    void _intersectLinesWithRect(const QList<QLineF>& lineList, const QRectF& boundRect, QList<QLineF>& resultLines);
    void _intersectLinesWithPolygon(const QList<QLineF>& lineList, const QPolygonF& polygon, QList<QLineF>& resultLines);
    void _adjustLineDirection(const QList<QLineF>& lineList, QList<QLineF>& resultLines);
    void _setSurveyDistance(double surveyDistance);
    void _setCameraShots(int cameraShots);
    void _setCoveredArea(double coveredArea);
Don Gagne's avatar
Don Gagne committed
202
    void _cameraValueChanged(void);
203
    int _appendWaypointToMission(QList<MissionItem*>& items, int seqNum, QGeoCoordinate& coord, CameraTriggerCode cameraTrigger, QObject* missionItemParent);
DonLakeFlyer's avatar
DonLakeFlyer committed
204 205 206 207 208 209 210
    bool _nextTransectCoord(const QList<QGeoCoordinate>& transectPoints, int pointIndex, QGeoCoordinate& coord);
    double _triggerDistance(void) const;
    bool _triggerCamera(void) const;
    bool _imagesEverywhere(void) const;
    bool _hoverAndCaptureEnabled(void) const;
    bool _hasTurnaround(void) const;
    double _turnaroundDistance(void) const;
211 212
    void _convertTransectToGeo(const QList<QList<QPointF>>& transectSegmentsNED, const QGeoCoordinate& tangentOrigin, QList<QList<QGeoCoordinate>>& transectSegmentsGeo);
    bool _appendMissionItemsWorker(QList<MissionItem*>& items, QObject* missionItemParent, int& seqNum, bool hasRefly, bool buildRefly);
DonLakeFlyer's avatar
DonLakeFlyer committed
213
    void _optimizeTransectsForShortestDistance(const QGeoCoordinate& distanceCoord, QList<QList<QGeoCoordinate>>& transects);
214
    void _appendGridPointsFromTransects(QList<QList<QGeoCoordinate>>& rgTransectSegments);
215 216 217
    qreal _ccw(QPointF pt1, QPointF pt2, QPointF pt3);
    qreal _dp(QPointF pt1, QPointF pt2);
    void _swapPoints(QList<QPointF>& points, int index1, int index2);
DonLakeFlyer's avatar
DonLakeFlyer committed
218 219 220 221 222
    void _reverseTransectOrder(QList<QList<QGeoCoordinate>>& transects);
    void _reverseInternalTransectPoints(QList<QList<QGeoCoordinate>>& transects);
    void _adjustTransectsToEntryPointLocation(QList<QList<QGeoCoordinate>>& transects);
    bool _gridAngleIsNorthSouthTransects();
    double _clampGridAngle90(double gridAngle);
223
    int _calcMissionCommandCount(QList<QList<QGeoCoordinate>>& transectSegments);
224 225 226

    int                             _sequenceNumber;
    bool                            _dirty;
227
    QGCMapPolygon                   _mapPolygon;
228
    QVariantList                    _simpleGridPoints;      ///< Grid points for drawing simple grid visuals
DonLakeFlyer's avatar
DonLakeFlyer committed
229
    QList<QList<QGeoCoordinate>>    _transectSegments;      ///< Internal transect segments including grid exit, turnaround and internal camera points
230
    QList<QList<QGeoCoordinate>>    _reflyTransectSegments; ///< Refly segments
231 232 233
    QGeoCoordinate                  _coordinate;
    QGeoCoordinate                  _exitCoordinate;
    bool                            _cameraOrientationFixed;
DonLakeFlyer's avatar
DonLakeFlyer committed
234
    int                             _missionCommandCount;
235
    bool                            _refly90Degrees;
236
    double                          _additionalFlightDelaySeconds;
237
    double                          _cameraMinTriggerInterval;
Don Gagne's avatar
Don Gagne committed
238

239
    bool            _ignoreRecalc;
Don Gagne's avatar
Don Gagne committed
240 241 242
    double          _surveyDistance;
    int             _cameraShots;
    double          _coveredArea;
243 244
    double          _timeBetweenShots;
    double          _cruiseSpeed;
245

246 247 248 249 250 251 252
    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact    _manualGridFact;
    SettingsFact    _gridAltitudeFact;
    SettingsFact    _gridAltitudeRelativeFact;
    SettingsFact    _gridAngleFact;
    SettingsFact    _gridSpacingFact;
DonLakeFlyer's avatar
DonLakeFlyer committed
253
    SettingsFact    _gridEntryLocationFact;
254 255
    SettingsFact    _turnaroundDistFact;
    SettingsFact    _cameraTriggerDistanceFact;
256 257
    SettingsFact    _cameraTriggerInTurnaroundFact;
    SettingsFact    _hoverAndCaptureFact;
258 259 260 261 262 263 264 265 266 267 268
    SettingsFact    _groundResolutionFact;
    SettingsFact    _frontalOverlapFact;
    SettingsFact    _sideOverlapFact;
    SettingsFact    _cameraSensorWidthFact;
    SettingsFact    _cameraSensorHeightFact;
    SettingsFact    _cameraResolutionWidthFact;
    SettingsFact    _cameraResolutionHeightFact;
    SettingsFact    _cameraFocalLengthFact;
    SettingsFact    _cameraOrientationLandscapeFact;
    SettingsFact    _fixedValueIsAltitudeFact;
    SettingsFact    _cameraFact;
269

Don Gagne's avatar
Don Gagne committed
270
    static const char* _jsonGridObjectKey;
271 272 273 274
    static const char* _jsonGridAltitudeKey;
    static const char* _jsonGridAltitudeRelativeKey;
    static const char* _jsonGridAngleKey;
    static const char* _jsonGridSpacingKey;
DonLakeFlyer's avatar
DonLakeFlyer committed
275
    static const char* _jsonGridEntryLocationKey;
Andreas Bircher's avatar
Andreas Bircher committed
276
    static const char* _jsonTurnaroundDistKey;
277
    static const char* _jsonCameraTriggerDistanceKey;
278 279
    static const char* _jsonCameraTriggerInTurnaroundKey;
    static const char* _jsonHoverAndCaptureKey;
Don Gagne's avatar
Don Gagne committed
280 281 282 283 284 285 286 287
    static const char* _jsonGroundResolutionKey;
    static const char* _jsonFrontalOverlapKey;
    static const char* _jsonSideOverlapKey;
    static const char* _jsonCameraSensorWidthKey;
    static const char* _jsonCameraSensorHeightKey;
    static const char* _jsonCameraResolutionWidthKey;
    static const char* _jsonCameraResolutionHeightKey;
    static const char* _jsonCameraFocalLengthKey;
288
    static const char* _jsonCameraMinTriggerIntervalKey;
Don Gagne's avatar
Don Gagne committed
289 290 291 292 293
    static const char* _jsonManualGridKey;
    static const char* _jsonCameraObjectKey;
    static const char* _jsonCameraNameKey;
    static const char* _jsonCameraOrientationLandscapeKey;
    static const char* _jsonFixedValueIsAltitudeKey;
294
    static const char* _jsonRefly90DegreesKey;
295

DonLakeFlyer's avatar
DonLakeFlyer committed
296
    static const int _hoverAndCaptureDelaySeconds = 4;
297
};