diff --git a/ToDo.txt b/ToDo.txt index c6970d1217f7762d669bafd2777c315cfb6e452b..826c69f1dd444b493478e2255c5ab93166a21ac1 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 3e9fd9195e576c8fa0457d073531c75203b1ccc4..839c216b6a599ab671bf44f63de1691f223472b3 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 014bbba13c3023005c61c32e370e75d7e1aaacb9..b4968b9edc20e0ec30a557a53a65c942bf5f9156 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 1dd53592654faa8ec3ab65cf9e7b434102bc4ab7..40e7caee67cc18901ef0fc37914bb45a33842ad1 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 a0ab837bffd8715b396827ec7e014ce231034f86..902ce28e1e62090ce83b400e06a41823a1b0b99c 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 63dceed27f48a06b4bada0ad954383e713d634dd..d1f96e3a2b22a7abfba3ac935c948f7862a38f33 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: {