From 8cf21ae71f0a39bde8e73bc5869866b4e54df220 Mon Sep 17 00:00:00 2001 From: Valentin Platzgummer Date: Mon, 2 Sep 2019 11:24:04 +0200 Subject: [PATCH] survey works now --- ToDo.txt | 4 +- src/Wima/CircularSurveyComplexItem.cc | 15 +++++++ src/Wima/CircularSurveyComplexItem.h | 8 ++++ src/Wima/OptimisationTools.h | 7 +++ src/Wima/WimaPlaner.cc | 54 +++++++++++++++++++++-- src/WimaView/SphericalSurveyMapVisual.qml | 7 ++- 6 files changed, 87 insertions(+), 8 deletions(-) diff --git a/ToDo.txt b/ToDo.txt index c6970d121..826c69f1d 100644 --- a/ToDo.txt +++ b/ToDo.txt @@ -1,4 +1,4 @@ optimize circular survey -remove Reference artefacts -solve Dijkstra issue (path not found, or not minimal) +profile survey +add dijkstra to flight view diff --git a/src/Wima/CircularSurveyComplexItem.cc b/src/Wima/CircularSurveyComplexItem.cc index 3e9fd9195..839c216b6 100644 --- a/src/Wima/CircularSurveyComplexItem.cc +++ b/src/Wima/CircularSurveyComplexItem.cc @@ -11,6 +11,7 @@ CircularSurveyComplexItem::CircularSurveyComplexItem(Vehicle *vehicle, bool flyV , _metaDataMap (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/CircularSurvey.SettingsGroup.json"), this)) , _deltaR (settingsGroup, _metaDataMap[deltaRName]) , _deltaAlpha (settingsGroup, _metaDataMap[deltaAlphaName]) + , _autoGenerated (false) { _editorQml = "qrc:/qml/CircularSurveyItemEditor.qml"; @@ -37,6 +38,15 @@ void CircularSurveyComplexItem::setRefPoint(const QGeoCoordinate &refPt) } } +void CircularSurveyComplexItem::setAutoGenerated(bool autoGen) +{ + if (autoGen != _autoGenerated) { + _autoGenerated = autoGen; + + emit autoGeneratedChanged(); + } +} + QGeoCoordinate CircularSurveyComplexItem::refPoint() const { return _referencePoint; @@ -52,6 +62,11 @@ Fact *CircularSurveyComplexItem::deltaAlpha() return &_deltaAlpha; } +bool CircularSurveyComplexItem::autoGenerated() +{ + return _autoGenerated; +} + bool CircularSurveyComplexItem::load(const QJsonObject &complexObject, int sequenceNumber, QString &errorString) { return false; diff --git a/src/Wima/CircularSurveyComplexItem.h b/src/Wima/CircularSurveyComplexItem.h index 014bbba13..b4968b9ed 100644 --- a/src/Wima/CircularSurveyComplexItem.h +++ b/src/Wima/CircularSurveyComplexItem.h @@ -20,14 +20,19 @@ public: Q_PROPERTY(QGeoCoordinate refPoint READ refPoint WRITE setRefPoint NOTIFY refPointChanged) Q_PROPERTY(Fact* deltaR READ deltaR CONSTANT) Q_PROPERTY(Fact* deltaAlpha READ deltaAlpha CONSTANT) + Q_PROPERTY(bool autoGenerated READ autoGenerated NOTIFY autoGeneratedChanged) // Property setters void setRefPoint(const QGeoCoordinate &refPt); + // Set this to true if survey was automatically generated, prevents initialisation from gui. + void setAutoGenerated(bool autoGen); // Property getters QGeoCoordinate refPoint() const; Fact *deltaR(); Fact *deltaAlpha(); + // Is true if survey was automatically generated, prevents initialisation from gui. + bool autoGenerated(); // Overrides from ComplexMissionItem bool load (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) final; @@ -53,6 +58,7 @@ public: signals: void refPointChanged(); + void autoGeneratedChanged(); private slots: // Overrides from TransectStyleComplexItem @@ -72,6 +78,8 @@ private: SettingsFact _deltaAlpha; QTimer _updateTimer; + + bool _autoGenerated; // set to true if survey was automatically generated, prevents initialisation from gui }; diff --git a/src/Wima/OptimisationTools.h b/src/Wima/OptimisationTools.h index 1dd535926..40e7caee6 100644 --- a/src/Wima/OptimisationTools.h +++ b/src/Wima/OptimisationTools.h @@ -46,6 +46,10 @@ namespace OptimisationTools { workingSet.append(&nodeList[i]); } +// double d1 = distanceDij(elements[0], elements[1]); +// double d2 = distanceDij(elements[0], elements[5]); +// double d3 = distanceDij(elements[5], elements[1]); + nodeList[startIndex].distance = 0; // Dijkstra Algorithm @@ -67,6 +71,9 @@ namespace OptimisationTools { Node* u = workingSet.takeAt(minDistIndex); + if (u->element == elements[endIndex]) // shortest path found + break; + //update distance for (int i = 0; i < workingSet.size(); i++) { Node* v = workingSet[i]; diff --git a/src/Wima/WimaPlaner.cc b/src/Wima/WimaPlaner.cc index a0ab837bf..902ce28e1 100644 --- a/src/Wima/WimaPlaner.cc +++ b/src/Wima/WimaPlaner.cc @@ -215,9 +215,30 @@ bool WimaPlaner::updateMission() _visualItems.append(&_joinedArea); #endif + // extract old survey data + QmlObjectListModel* missionItems = _missionController->visualItems(); + CircularSurveyComplexItem* OldSurveyPt = nullptr; + + QGeoCoordinate oldSurveyRef; + double oldSurveyDeltaR = 0; + double oldSurveyDeltaAlpha = 0; + bool oldSurveyExists = false; + + for (int i = 0; i < _missionController->visualItems()->count(); i++) { + OldSurveyPt = qobject_cast(missionItems->get(i)); + if ( OldSurveyPt != nullptr) { + oldSurveyRef = OldSurveyPt->refPoint(); + oldSurveyDeltaR = OldSurveyPt->deltaR()->rawValue().toDouble(); + oldSurveyDeltaAlpha = OldSurveyPt->deltaAlpha()->rawValue().toDouble(); + oldSurveyExists = true; + break; + } + + } + // reset visual items _missionController->removeAll(); - QmlObjectListModel* missionItems = _missionController->visualItems(); + missionItems = _missionController->visualItems(); // set home position to serArea center MissionSettingsItem* settingsItem= qobject_cast(missionItems->get(0)); if (settingsItem == nullptr){ @@ -248,21 +269,36 @@ bool WimaPlaner::updateMission() // create survey item, will be extened with more()-> mission types in the future _missionController->insertComplexMissionItem(_missionController->circularSurveyComplexItemName(), _measurementArea.center(), missionItems->count()); CircularSurveyComplexItem* survey = qobject_cast(missionItems->get(missionItems->count()-1)); + if (survey == nullptr){ qWarning("WimaPlaner::updateMission(): survey == nullptr"); return false; } else { + if ( oldSurveyExists ) { + survey->setRefPoint(oldSurveyRef); + survey->deltaR()->setRawValue(oldSurveyDeltaR); + survey->deltaAlpha()->setRawValue(oldSurveyDeltaAlpha); + } else { + survey->setRefPoint(_measurementArea.center()); + } + + survey->setAutoGenerated(true); // prevents reinitialisation from gui survey->surveyAreaPolygon()->clear(); survey->surveyAreaPolygon()->appendVertices(_measurementArea.coordinateList()); + } + + + + // calculate path from take off to opArea if (survey->visualTransectPoints().size() == 0) { qWarning("WimaPlaner::updateMission(): survey no points."); return false; } QGeoCoordinate start = _serviceArea.center(); - QGeoCoordinate end = survey->visualTransectPoints().first().value(); + QGeoCoordinate end = survey->coordinate(); if (!_visualItems.contains(&_joinedArea)) _visualItems.append(&_joinedArea); @@ -271,19 +307,29 @@ bool WimaPlaner::updateMission() qgcApp()->showMessage( QString(tr("Not able to calculate the path from takeoff position to measurement area.")).toLocal8Bit().data()); return false; } +// path.clear(); +// path.append(end); +// path.append(start); +// path.append(end); +// path.append(end); for (int i = 1; i < path.count()-1; i++) { sequenceNumber = _missionController->insertSimpleMissionItem(path.value(i), missionItems->count()-1); _missionController->setCurrentPlanViewIndex(sequenceNumber, true); } // calculate return path - start = survey->visualTransectPoints().last().value(); + start = survey->exitCoordinate(); end = _serviceArea.center(); path.clear(); if ( !calcShortestPath(start, end, path)) { qgcApp()->showMessage(QString(tr("Not able to calculate the path from measurement area to landing position.")).toLocal8Bit().data()); return false; } +// path.clear(); +// path.append(end); +// path.append(start); +// path.append(end); +// path.append(end); for (int i = 1; i < path.count()-1; i++) { sequenceNumber = _missionController->insertSimpleMissionItem(path.value(i), missionItems->count()); _missionController->setCurrentPlanViewIndex(sequenceNumber, true); @@ -583,7 +629,7 @@ bool WimaPlaner::calcShortestPath(const QGeoCoordinate &start, const QGeoCoordin /*start point*/ QPointF(0,0), /*destination*/ toCartesian2D(destination, start), /*shortest path*/ path2D); - path.append(toGeo(path2D, /*origin*/start)); + path.append(toGeo(path2D, /*origin*/ start)); return retVal; } diff --git a/src/WimaView/SphericalSurveyMapVisual.qml b/src/WimaView/SphericalSurveyMapVisual.qml index 63dceed27..d1f96e3a2 100644 --- a/src/WimaView/SphericalSurveyMapVisual.qml +++ b/src/WimaView/SphericalSurveyMapVisual.qml @@ -90,9 +90,12 @@ Item { } Component.onCompleted: { - _addInitialPolygon() + if ( !_missionItem.autoGenerated ) { + _addInitialPolygon() + _setRefPoint() + } _addVisualElements() - _setRefPoint() + } Component.onDestruction: { -- 2.22.0