Skip to content

Commit

Permalink
Merge pull request #1299 from ArnoTlse/Safehome_to_EPROM
Browse files Browse the repository at this point in the history
[Mission Planner] Elevation Profile & Home
  • Loading branch information
DzikuVx authored Aug 13, 2021
2 parents fb2e438 + afd0c02 commit 32bd3fa
Show file tree
Hide file tree
Showing 14 changed files with 9,523 additions and 58 deletions.
9 changes: 9 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3452,6 +3452,12 @@
"missionDefaultSettingsHead": {
"message": "Default settings"
},
"missionDefaultElevationHead": {
"message": "Elevation Profile"
},
"missionHomeHead": {
"message": "Take Off Home"
},
"missionSafehomeHead": {
"message": "Safe Home manager"
},
Expand Down Expand Up @@ -3977,6 +3983,9 @@
"SafehomeLat": {
"message": "Lat"
},
"SafehomeAlt": {
"message": "Elev"
},
"WaypointOptionSelected": {
"message": "+"
},
Expand Down
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ sources.js = [
'./js/safehome.js',
'./js/waypointCollection.js',
'./js/waypoint.js',
'./node_modules/openlayers/dist/ol.js'
'./node_modules/openlayers/dist/ol.js',
'./js/libraries/plotly-latest.min.js'
];

sources.receiverCss = [
Expand Down
Binary file added images/icons/cf_icon_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions images/icons/cf_icon_arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions images/icons/cf_icon_elevation_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icons/cf_icon_home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions js/libraries/plotly-latest.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions js/waypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM
self.setAttachedNumber = function (data) {
attachedNumber = data;
};

self.getElevation = async function (globalSettings) {
let elevation;
if (globalSettings.mapProviderType == 'bing') {
const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/List?points='+self.getLatMap()+','+self.getLonMap()+'&heights=ellipsoid&key='+globalSettings.mapApiKey);
const myJson = await response.json();
elevation = myJson.resourceSets[0].resources[0].elevations[0];
}
else {
elevation = "NA";
}
return elevation;
}

return self;
};
65 changes: 57 additions & 8 deletions js/waypointCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ let WaypointCollection = function () {
lJumptTargetAttached.push(element.getNumber());
}
});
console.log("lJumptTargetAttached ", lJumptTargetAttached);
return (lJumptTargetAttached.length != 0 && lJumptTargetAttached != 'undefined')
}

Expand All @@ -332,22 +331,32 @@ let WaypointCollection = function () {
return poiList;
}

self.getDistance = function() {
let point2measure = []
let lengthLine = []
self.getPoint2Measure = function(reverse=false) {
let point2measure = [];
let altPoint2measure = [];
let namePoint2measure = [];
let refPoint2measure = [];
let jumpDict = {};
let nStart = 0;
let nLoop = 0;
let n = 0 ;
let startCount = true;
while (startCount && (nLoop!=-1)) {
while (startCount) {
if (nStart > data[data.length -1].getNumber() ) {
startCount = false;
break;
}

if ([MWNP.WPTYPE.WAYPOINT,MWNP.WPTYPE.POSHOLD_TIME,MWNP.WPTYPE.LAND].includes(self.getWaypoint(nStart).getAction())) {
point2measure.push(ol.proj.fromLonLat([self.getWaypoint(nStart).getLonMap(), self.getWaypoint(nStart).getLatMap()]));
if (reverse) {
point2measure.push([self.getWaypoint(nStart).getLatMap(), self.getWaypoint(nStart).getLonMap()]);
}
else {
point2measure.push(ol.proj.fromLonLat([self.getWaypoint(nStart).getLonMap(), self.getWaypoint(nStart).getLatMap()]));
}
altPoint2measure.push(self.getWaypoint(nStart).getAlt());
namePoint2measure.push(self.getWaypoint(nStart).getLayerNumber()+1);
refPoint2measure.push(self.getWaypoint(nStart).getP3());
nStart++;
}
else if (self.getWaypoint(nStart).getAction() == MWNP.WPTYPE.JUMP) {
Expand All @@ -356,6 +365,7 @@ let WaypointCollection = function () {
}
if (Object.keys(jumpDict).includes(String(self.getWaypoint(nStart).getNumber())) ) {
if (jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] == -1) {
jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] = 1;
nLoop = -1;
}
if ( (jumpDict[self.getWaypoint(nStart).getNumber()]["n"]>=jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] || jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] ==0) ) {
Expand All @@ -368,13 +378,19 @@ let WaypointCollection = function () {
nStart = nStartTemp;
}
}

}
else {
nStart++;
}
}
if (nLoop == -1) {

return [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure];
}

self.getDistance = function(display) {
let lengthLine = [];
const [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure] = self.getPoint2Measure();
if (nLoop == -1 && display) {
return [-1];
}
else {
Expand All @@ -392,6 +408,39 @@ let WaypointCollection = function () {
return lengthLine.map(cumulativeSum);
}
}

self.getElevation = async function(globalSettings) {
const [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure] = self.getPoint2Measure(true);
let lengthMission = self.getDistance(true);
let totalMissionDistance = lengthMission[lengthMission.length -1].toFixed(1);
let samples;
if (point2measure.length <= 2){
samples = 1;
}
else if (Math.trunc(totalMissionDistance/30) <= 1024 && point2measure.length > 2){
samples = Math.trunc(totalMissionDistance/30);
}
else {
samples = 1024;
}
if (globalSettings.mapProviderType == 'bing') {
if (point2measure.length >1) {
const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/Polyline?points='+point2measure+'&heights=ellipsoid&samples='+String(samples+1)+'&key='+globalSettings.mapApiKey);
const myJson = await response.json();
elevation = myJson.resourceSets[0].resources[0].elevations;
}
else {
const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/List?points='+point2measure+'&heights=ellipsoid&key='+globalSettings.mapApiKey);
const myJson = await response.json();
elevation = myJson.resourceSets[0].resources[0].elevations;
}
}
else {
elevation = "NA";
}
//console.log("elevation ", elevation);
return [lengthMission, totalMissionDistance, samples, elevation, altPoint2measure, namePoint2measure, refPoint2measure];
}

return self;
};
Loading

0 comments on commit 32bd3fa

Please sign in to comment.