From 3b3b49d9166998a28e61fa23ce6e099c8f1460cd Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sun, 28 Feb 2016 14:38:42 -0800 Subject: [PATCH] AMSL altitude support --- src/MissionEditor/MissionEditor.qml | 10 +-- src/MissionEditor/SurveyItemEditor.qml | 11 +++- src/MissionManager/ComplexMissionItem.cc | 82 +++++++++++------------- src/MissionManager/ComplexMissionItem.h | 40 +++++++----- 4 files changed, 73 insertions(+), 70 deletions(-) diff --git a/src/MissionEditor/MissionEditor.qml b/src/MissionEditor/MissionEditor.qml index c6b79ffec..b7650d477 100644 --- a/src/MissionEditor/MissionEditor.qml +++ b/src/MissionEditor/MissionEditor.qml @@ -367,14 +367,8 @@ QGCView { // Add the complex mission item polygon to the map MapItemView { - model: controller.complexVisualItems - delegate: polygonItemComponent - } - - Component { - id: polygonItemComponent - - MapPolygon { + model: controller.complexVisualItems + delegate: MapPolygon { color: 'green' path: object.polygonPath opacity: 0.5 diff --git a/src/MissionEditor/SurveyItemEditor.qml b/src/MissionEditor/SurveyItemEditor.qml index 39c629f06..169978620 100644 --- a/src/MissionEditor/SurveyItemEditor.qml +++ b/src/MissionEditor/SurveyItemEditor.qml @@ -71,12 +71,19 @@ Rectangle { } } + QGCCheckBox { + anchors.left: parent.left + text: "Relative altitude" + checked: missionItem.gridAltitudeRelative + onClicked: missionItem.gridAltitudeRelative = checked + } + QGCCheckBox { id: cameraTrigger anchors.left: parent.left text: "Camera trigger:" checked: missionItem.cameraTrigger - onClicked: missionItem.cameraTrigger = !missionItem.cameraTrigger + onClicked: missionItem.cameraTrigger = checked } Item { @@ -102,7 +109,7 @@ Rectangle { } QGCButton { - text: _addPointsMode ? "Finished" : "Draw Polygon" + text: _addPointsMode ? "Finish Polygon" : "Draw Polygon" onClicked: { if (_addPointsMode) { _addPointsMode = false diff --git a/src/MissionManager/ComplexMissionItem.cc b/src/MissionManager/ComplexMissionItem.cc index 8e04ac673..e403d9c00 100644 --- a/src/MissionManager/ComplexMissionItem.cc +++ b/src/MissionManager/ComplexMissionItem.cc @@ -27,14 +27,17 @@ This file is part of the QGROUNDCONTROL project #include -const char* ComplexMissionItem::_jsonVersionKey = "version"; -const char* ComplexMissionItem::_jsonTypeKey = "type"; -const char* ComplexMissionItem::_jsonPolygonKey = "polygon"; -const char* ComplexMissionItem::_jsonIdKey = "id"; -const char* ComplexMissionItem::_jsonGridAltitudeKey = "gridAltitude"; -const char* ComplexMissionItem::_jsonGridAngleKey = "gridAngle"; -const char* ComplexMissionItem::_jsonGridSpacingKey = "gridSpacing"; -const char* ComplexMissionItem::_jsonCameraTriggerKey = "cameraTrigger"; +QGC_LOGGING_CATEGORY(ComplexMissionItemLog, "ComplexMissionItemLog") + +const char* ComplexMissionItem::_jsonVersionKey = "version"; +const char* ComplexMissionItem::_jsonTypeKey = "type"; +const char* ComplexMissionItem::_jsonPolygonKey = "polygon"; +const char* ComplexMissionItem::_jsonIdKey = "id"; +const char* ComplexMissionItem::_jsonGridAltitudeKey = "gridAltitude"; +const char* ComplexMissionItem::_jsonGridAltitudeRelativeKey = "gridAltitudeRelative"; +const char* ComplexMissionItem::_jsonGridAngleKey = "gridAngle"; +const char* ComplexMissionItem::_jsonGridSpacingKey = "gridSpacing"; +const char* ComplexMissionItem::_jsonCameraTriggerKey = "cameraTrigger"; const char* ComplexMissionItem::_jsonCameraTriggerDistanceKey = "cameraTriggerDistance"; const char* ComplexMissionItem::_complexType = "survey"; @@ -44,6 +47,7 @@ ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, QObject* parent) , _sequenceNumber(0) , _dirty(false) , _cameraTrigger(false) + , _gridAltitudeRelative(true) , _gridAltitudeFact (0, "Altitude:", FactMetaData::valueTypeDouble) , _gridAngleFact (0, "Grid angle:", FactMetaData::valueTypeDouble) , _gridSpacingFact (0, "Grid spacing:", FactMetaData::valueTypeDouble) @@ -58,18 +62,6 @@ ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, QObject* parent) connect(this, &ComplexMissionItem::cameraTriggerChanged, this, &ComplexMissionItem::_signalLastSequenceNumberChanged); } -ComplexMissionItem::ComplexMissionItem(const ComplexMissionItem& other, QObject* parent) - : VisualMissionItem(other, parent) - , _sequenceNumber(other.sequenceNumber()) - , _dirty(false) - , _cameraTrigger(other._cameraTrigger) -{ - _gridAltitudeFact.setRawValue(other._gridAltitudeFact.rawValue()); - _gridAngleFact.setRawValue(other._gridAngleFact.rawValue()); - _gridSpacingFact.setRawValue(other._gridSpacingFact.rawValue()); - _cameraTriggerDistanceFact.setRawValue(other._cameraTriggerDistanceFact.rawValue()); -} - void ComplexMissionItem::clearPolygon(void) { // Bug workaround, see below @@ -139,13 +131,14 @@ void ComplexMissionItem::setDirty(bool dirty) void ComplexMissionItem::save(QJsonObject& saveObject) const { - saveObject[_jsonVersionKey] = 1; - saveObject[_jsonTypeKey] = _complexType; - saveObject[_jsonIdKey] = sequenceNumber(); - saveObject[_jsonGridAltitudeKey] = _gridAltitudeFact.rawValue().toDouble(); - saveObject[_jsonGridAngleKey] = _gridAngleFact.rawValue().toDouble(); - saveObject[_jsonGridSpacingKey] = _gridSpacingFact.rawValue().toDouble(); - saveObject[_jsonCameraTriggerKey] = _cameraTrigger; + saveObject[_jsonVersionKey] = 1; + saveObject[_jsonTypeKey] = _complexType; + saveObject[_jsonIdKey] = sequenceNumber(); + saveObject[_jsonGridAltitudeKey] = _gridAltitudeFact.rawValue().toDouble(); + saveObject[_jsonGridAltitudeRelativeKey] = _gridAltitudeRelative; + saveObject[_jsonGridAngleKey] = _gridAngleFact.rawValue().toDouble(); + saveObject[_jsonGridSpacingKey] = _gridSpacingFact.rawValue().toDouble(); + saveObject[_jsonCameraTriggerKey] = _cameraTrigger; saveObject[_jsonCameraTriggerDistanceKey] = _cameraTriggerDistanceFact.rawValue().toDouble(); // Polygon shape @@ -186,7 +179,7 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt // Validate requires keys QStringList requiredKeys; requiredKeys << _jsonVersionKey << _jsonTypeKey << _jsonIdKey << _jsonPolygonKey << _jsonGridAltitudeKey << _jsonGridAngleKey << _jsonGridSpacingKey << - _jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey; + _jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey << _jsonGridAltitudeRelativeKey; if (!JsonHelper::validateRequiredKeys(complexObject, requiredKeys, errorString)) { _clear(); return false; @@ -196,9 +189,9 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt QStringList keyList; QList typeList; keyList << _jsonVersionKey << _jsonTypeKey << _jsonIdKey << _jsonPolygonKey << _jsonGridAltitudeKey << _jsonGridAngleKey << _jsonGridSpacingKey << - _jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey; + _jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey << _jsonGridAltitudeRelativeKey; typeList << QJsonValue::Double << QJsonValue::String << QJsonValue::Double << QJsonValue::Array << QJsonValue::Double << QJsonValue::Double<< QJsonValue::Double << - QJsonValue::Bool << QJsonValue::Double; + QJsonValue::Bool << QJsonValue::Double << QJsonValue::Bool; if (!JsonHelper::validateKeyTypes(complexObject, keyList, typeList, errorString)) { _clear(); return false; @@ -218,11 +211,14 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt } setSequenceNumber(complexObject[_jsonIdKey].toInt()); - _cameraTrigger = complexObject[_jsonCameraTriggerKey].toBool(); - _gridAltitudeFact.setRawValue (complexObject[_jsonGridAltitudeKey].toDouble()); - _gridAngleFact.setRawValue (complexObject[_jsonGridAngleKey].toDouble()); - _gridSpacingFact.setRawValue (complexObject[_jsonGridSpacingKey].toDouble()); - _cameraTriggerDistanceFact.setRawValue(complexObject[_jsonCameraTriggerDistanceKey].toDouble()); + + _cameraTrigger = complexObject[_jsonCameraTriggerKey].toBool(); + _gridAltitudeRelative = complexObject[_jsonGridAltitudeRelativeKey].toBool(); + + _gridAltitudeFact.setRawValue (complexObject[_jsonGridAltitudeKey].toDouble()); + _gridAngleFact.setRawValue (complexObject[_jsonGridAngleKey].toDouble()); + _gridSpacingFact.setRawValue (complexObject[_jsonGridSpacingKey].toDouble()); + _cameraTriggerDistanceFact.setRawValue (complexObject[_jsonCameraTriggerDistanceKey].toDouble()); // Polygon shape QJsonArray polygonArray(complexObject[_jsonPolygonKey].toArray()); @@ -280,13 +276,13 @@ void ComplexMissionItem::_generateGrid(void) QList gridPoints; // Convert polygon to Qt coordinate system (y positive is down) - qDebug() << "Convert polygon"; + qCDebug(ComplexMissionItemLog) << "Convert polygon"; QGeoCoordinate tangentOrigin = _polygonPath[0].value(); for (int i=0; i<_polygonPath.count(); i++) { double y, x, down; convertGeoToNed(_polygonPath[i].value(), tangentOrigin, &y, &x, &down); polygonPoints += QPointF(x, -y); - qDebug() << _polygonPath[i].value() << polygonPoints.last().x() << polygonPoints.last().y(); + qCDebug(ComplexMissionItemLog) << _polygonPath[i].value() << polygonPoints.last().x() << polygonPoints.last().y(); } // Generate grid @@ -413,16 +409,16 @@ void ComplexMissionItem::_gridGenerator(const QList& polygonPoints, QL // Convert polygon to bounding rect - qDebug() << "Polygon"; + qCDebug(ComplexMissionItemLog) << "Polygon"; QPolygonF polygon; for (int i=0; i& polygonPoints, QL boundPolygon << _rotatePoint(smallBoundRect.bottomLeft(), center, gridAngle); boundPolygon << boundPolygon[0]; QRectF largeBoundRect = boundPolygon.boundingRect(); - qDebug() << "Rotated bounding rect" << largeBoundRect.topLeft().x() << largeBoundRect.topLeft().y() << largeBoundRect.bottomRight().x() << largeBoundRect.bottomRight().y(); + qCDebug(ComplexMissionItemLog) << "Rotated bounding rect" << largeBoundRect.topLeft().x() << largeBoundRect.topLeft().y() << largeBoundRect.bottomRight().x() << largeBoundRect.bottomRight().y(); // Create set of rotated parallel lines within the expanded bounding rect. Make the lines larger than the // bounding box to guarantee intersection. @@ -444,7 +440,7 @@ void ComplexMissionItem::_gridGenerator(const QList& polygonPoints, QL float yBottom = largeBoundRect.bottomRight().y() + 100.0; lineList += QLineF(_rotatePoint(QPointF(x, yTop), center, gridAngle), _rotatePoint(QPointF(x, yBottom), center, gridAngle)); - qDebug() << "line" << lineList.last().x1() << lineList.last().y1() << lineList.last().x2() << lineList.last().y2(); + qCDebug(ComplexMissionItemLog) << "line" << lineList.last().x1() << lineList.last().y1() << lineList.last().x2() << lineList.last().y2(); x += gridSpacing; } @@ -477,7 +473,7 @@ QmlObjectListModel* ComplexMissionItem::getMissionItems(void) const MissionItem* item = new MissionItem(seqNum++, // sequence number MAV_CMD_NAV_WAYPOINT, // MAV_CMD - MAV_FRAME_GLOBAL_RELATIVE_ALT, // MAV_FRAME + _gridAltitudeRelative ? MAV_FRAME_GLOBAL_RELATIVE_ALT : MAV_FRAME_GLOBAL, // MAV_FRAME 0.0, 0.0, 0.0, 0.0, // param 1-4 coord.latitude(), coord.longitude(), diff --git a/src/MissionManager/ComplexMissionItem.h b/src/MissionManager/ComplexMissionItem.h index 249ccb57c..7b8773051 100644 --- a/src/MissionManager/ComplexMissionItem.h +++ b/src/MissionManager/ComplexMissionItem.h @@ -27,6 +27,9 @@ #include "VisualMissionItem.h" #include "MissionItem.h" #include "Fact.h" +#include "QGCLoggingCategory.h" + +Q_DECLARE_LOGGING_CATEGORY(ComplexMissionItemLog) class ComplexMissionItem : public VisualMissionItem { @@ -34,16 +37,16 @@ class ComplexMissionItem : public VisualMissionItem public: ComplexMissionItem(Vehicle* vehicle, QObject* parent = NULL); - ComplexMissionItem(const ComplexMissionItem& other, QObject* parent = NULL); - Q_PROPERTY(Fact* gridAltitude READ gridAltitude CONSTANT) - Q_PROPERTY(Fact* gridAngle READ gridAngle CONSTANT) - Q_PROPERTY(Fact* gridSpacing READ gridSpacing CONSTANT) - Q_PROPERTY(bool cameraTrigger MEMBER _cameraTrigger NOTIFY cameraTriggerChanged) - Q_PROPERTY(Fact* cameraTriggerDistance READ cameraTriggerDistance CONSTANT) - Q_PROPERTY(QVariantList polygonPath READ polygonPath NOTIFY polygonPathChanged) - Q_PROPERTY(int lastSequenceNumber READ lastSequenceNumber NOTIFY lastSequenceNumberChanged) - Q_PROPERTY(QVariantList gridPoints READ gridPoints NOTIFY gridPointsChanged) + Q_PROPERTY(Fact* gridAltitude READ gridAltitude CONSTANT) + Q_PROPERTY(bool gridAltitudeRelative MEMBER _gridAltitudeRelative NOTIFY gridAltitudeRelativeChanged) + Q_PROPERTY(Fact* gridAngle READ gridAngle CONSTANT) + Q_PROPERTY(Fact* gridSpacing READ gridSpacing CONSTANT) + Q_PROPERTY(bool cameraTrigger MEMBER _cameraTrigger NOTIFY cameraTriggerChanged) + Q_PROPERTY(Fact* cameraTriggerDistance READ cameraTriggerDistance CONSTANT) + Q_PROPERTY(QVariantList polygonPath READ polygonPath NOTIFY polygonPathChanged) + Q_PROPERTY(int lastSequenceNumber READ lastSequenceNumber NOTIFY lastSequenceNumberChanged) + Q_PROPERTY(QVariantList gridPoints READ gridPoints NOTIFY gridPointsChanged) Q_INVOKABLE void clearPolygon(void); Q_INVOKABLE void addPolygonCoordinate(const QGeoCoordinate coordinate); @@ -81,8 +84,8 @@ public: QGeoCoordinate exitCoordinate (void) const final { return _exitCoordinate; } int sequenceNumber (void) const final { return _sequenceNumber; } - bool coordinateHasRelativeAltitude (void) const final { return true; } - bool exitCoordinateHasRelativeAltitude (void) const final { return true; } + bool coordinateHasRelativeAltitude (void) const final { return _gridAltitudeRelative; } + bool exitCoordinateHasRelativeAltitude (void) const final { return _gridAltitudeRelative; } bool exitCoordinateSameAsEntry (void) const final { return false; } void setDirty (bool dirty) final; @@ -91,12 +94,13 @@ public: void save (QJsonObject& saveObject) const final; signals: - void polygonPathChanged(void); - void lastSequenceNumberChanged(int lastSequenceNumber); - void altitudeChanged(double altitude); - void gridAngleChanged(double gridAngle); - void gridPointsChanged(void); - void cameraTriggerChanged(bool cameraTrigger); + void polygonPathChanged (void); + void lastSequenceNumberChanged (int lastSequenceNumber); + void altitudeChanged (double altitude); + void gridAngleChanged (double gridAngle); + void gridPointsChanged (void); + void cameraTriggerChanged (bool cameraTrigger); + void gridAltitudeRelativeChanged (bool gridAltitudeRelative); private slots: void _signalLastSequenceNumberChanged(void); @@ -120,6 +124,7 @@ private: double _altitude; double _gridAngle; bool _cameraTrigger; + bool _gridAltitudeRelative; Fact _gridAltitudeFact; Fact _gridAngleFact; @@ -131,6 +136,7 @@ private: static const char* _jsonPolygonKey; static const char* _jsonIdKey; static const char* _jsonGridAltitudeKey; + static const char* _jsonGridAltitudeRelativeKey; static const char* _jsonGridAngleKey; static const char* _jsonGridSpacingKey; static const char* _jsonCameraTriggerKey; -- 2.22.0