MissionItem.h 4.9 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10 11 12
#ifndef MissionItem_H
#define MissionItem_H

13 14
#include <QGeoCoordinate>
#include <QJsonObject>
15 16 17
#include <QObject>
#include <QString>
#include <QTextStream>
18
#include <QtQml>
19 20

#include "Fact.h"
21
#include "QGC.h"
22
#include "QGCLoggingCategory.h"
23
#include "QGCMAVLink.h"
24 25
#include "QmlObjectListModel.h"

26
class SurveyComplexItem;
27 28 29
class SimpleMissionItem;
class MissionController;
#ifdef UNITTEST_BUILD
30
class MissionItemTest;
31 32 33
#endif

// Represents a Mavlink mission command.
34 35 36
class MissionItem : public QObject {
  Q_OBJECT

37
public:
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  MissionItem(QObject *parent = nullptr);

  MissionItem(int sequenceNumber, MAV_CMD command, MAV_FRAME frame,
              double param1, double param2, double param3, double param4,
              double param5, double param6, double param7, bool autoContinue,
              bool isCurrentItem, QObject *parent = nullptr);

  MissionItem(const MissionItem &other, QObject *parent = nullptr);

  ~MissionItem();

  const MissionItem &operator=(const MissionItem &other);

  MAV_CMD command(void) const {
    return (MAV_CMD)_commandFact.rawValue().toInt();
  }
  bool isCurrentItem(void) const { return _isCurrentItem; }
  int sequenceNumber(void) const { return _sequenceNumber; }
  MAV_FRAME frame(void) const {
    return (MAV_FRAME)_frameFact.rawValue().toInt();
  }
  bool autoContinue(void) const {
    return _autoContinueFact.rawValue().toBool();
  }
  double param1(void) const { return _param1Fact.rawValue().toDouble(); }
  double param2(void) const { return _param2Fact.rawValue().toDouble(); }
  double param3(void) const { return _param3Fact.rawValue().toDouble(); }
  double param4(void) const { return _param4Fact.rawValue().toDouble(); }
  double param5(void) const { return _param5Fact.rawValue().toDouble(); }
  double param6(void) const { return _param6Fact.rawValue().toDouble(); }
  double param7(void) const { return _param7Fact.rawValue().toDouble(); }
  QGeoCoordinate coordinate(void) const;
  int doJumpId(void) const { return _doJumpId; }

  /// @return Flight speed change value if this item supports it. If not it
  /// returns NaN.
  double specifiedFlightSpeed(void) const;

  /// @return Flight gimbal yaw change value if this item supports it. If not it
  /// returns NaN.
  double specifiedGimbalYaw(void) const;

  /// @return Flight gimbal pitch change value if this item supports it. If not
  /// it returns NaN.
  double specifiedGimbalPitch(void) const;

  void setCommand(MAV_CMD command);
  void setSequenceNumber(int sequenceNumber);
  void setIsCurrentItem(bool isCurrentItem);
  void setFrame(MAV_FRAME frame);
  void setAutoContinue(bool autoContinue);
  void setParam1(double param1);
  void setParam2(double param2);
  void setParam3(double param3);
  void setParam4(double param4);
  void setParam5(double param5);
  void setParam6(double param6);
  void setParam7(double param7);

  void save(QJsonObject &json) const;
  bool load(QTextStream &loadStream);
  bool load(const QJsonObject &json, int sequenceNumber, QString &errorString);

  bool relativeAltitude(void) const {
    return frame() == MAV_FRAME_GLOBAL_RELATIVE_ALT;
  }
Don Gagne's avatar
Don Gagne committed
104

105
signals:
106 107 108 109 110
  void isCurrentItemChanged(bool isCurrentItem);
  void sequenceNumberChanged(int sequenceNumber);
  void specifiedFlightSpeedChanged(double flightSpeed);
  void specifiedGimbalYawChanged(double gimbalYaw);
  void specifiedGimbalPitchChanged(double gimbalPitch);
111 112

private slots:
113 114 115
  void _param1Changed(QVariant value);
  void _param2Changed(QVariant value);
  void _param3Changed(QVariant value);
DonLakeFlyer's avatar
DonLakeFlyer committed
116

117
private:
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
  bool _convertJsonV1ToV2(const QJsonObject &json, QJsonObject &v2Json,
                          QString &errorString);
  bool _convertJsonV2ToV3(QJsonObject &json, QString &errorString);

  Fact _autoContinueFact;
  Fact _commandFact;
  Fact _frameFact;
  Fact _param1Fact;
  Fact _param2Fact;
  Fact _param3Fact;
  Fact _param4Fact;
  Fact _param5Fact;
  Fact _param6Fact;
  Fact _param7Fact;

  int _sequenceNumber;
  int _doJumpId;
  bool _isCurrentItem;

  // Keys for Json save
  static const char *_jsonFrameKey;
  static const char *_jsonCommandKey;
  static const char *_jsonAutoContinueKey;
  static const char *_jsonParamsKey;
  static const char *_jsonDoJumpIdKey;

  // Deprecated V2 format keys
  static const char *_jsonCoordinateKey;

  // Deprecated V1 format keys
  static const char *_jsonParam1Key;
  static const char *_jsonParam2Key;
  static const char *_jsonParam3Key;
  static const char *_jsonParam4Key;

  friend class SurveyComplexItem;
  friend class RouteComplexItem;
  friend class SimpleMissionItem;
  friend class MissionController;
157
#ifdef UNITTEST_BUILD
158
  friend class MissionItemTest;
159
#endif
160 161 162
};

#endif