Skip to content

Commit 97236d1

Browse files
demvladhaslinghuis
andauthored
The azimuth of Home point added as computed field (betaflight#774)
* added homes point azimuth computed field * added friendly name for homes point azimuth field * added default min max values for homes point azimuth field * homes point azimuth field is added to example graph * Comment is edited Co-authored-by: Mark Haslinghuis <[email protected]> --------- Co-authored-by: Mark Haslinghuis <[email protected]>
1 parent 62978cc commit 97236d1

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/flightlog.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
* Window based smoothing of fields is offered.
3131
*/
3232
export function FlightLog(logData) {
33-
let ADDITIONAL_COMPUTED_FIELD_COUNT = 19 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GPS coord**/,
33+
let ADDITIONAL_COMPUTED_FIELD_COUNT = 20 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GPS coord, distance and azimuth **/,
3434
that = this,
3535
logIndex = 0,
3636
logIndexes = new FlightLogIndex(logData),
@@ -284,7 +284,7 @@ export function FlightLog(logData) {
284284
fieldNames.push("axisError[0]", "axisError[1]", "axisError[2]"); // Custom calculated error field
285285
}
286286
if (!that.isFieldDisabled().GPS) {
287-
fieldNames.push("gpsCartesianCoords[0]", "gpsCartesianCoords[1]", "gpsCartesianCoords[2]", "gpsDistance"); // GPS coords in cartesian system
287+
fieldNames.push("gpsCartesianCoords[0]", "gpsCartesianCoords[1]", "gpsCartesianCoords[2]", "gpsDistance", "gpsHomeAzimuth"); // GPS coords in cartesian system
288288
}
289289

290290
fieldNameToIndex = {};
@@ -854,11 +854,18 @@ export function FlightLog(logData) {
854854
destFrame[fieldIndex++] = gpsCartesianCoords.y;
855855
destFrame[fieldIndex++] = gpsCartesianCoords.z;
856856
destFrame[fieldIndex++] = Math.sqrt(gpsCartesianCoords.x * gpsCartesianCoords.x + gpsCartesianCoords.z * gpsCartesianCoords.z);
857+
858+
let homeAzimuth = Math.atan2(-gpsCartesianCoords.z, -gpsCartesianCoords.x) * 180 / Math.PI;
859+
if (homeAzimuth < 0) {
860+
homeAzimuth += 360;
861+
}
862+
destFrame[fieldIndex++] = homeAzimuth;
857863
} else {
858864
destFrame[fieldIndex++] = 0;
859865
destFrame[fieldIndex++] = 0;
860866
destFrame[fieldIndex++] = 0;
861867
destFrame[fieldIndex++] = 0;
868+
destFrame[fieldIndex++] = 0;
862869
}
863870
}
864871

src/flightlog_fields_presenter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const FRIENDLY_FIELD_NAMES = {
130130
"gpsCartesianCoords[1]": "GPS Coords [Y]",
131131
"gpsCartesianCoords[2]": "GPS Coords [Z]",
132132
gpsDistance: "GPS Home distance",
133+
gpsHomeAzimuth: "GPS Home azimuth",
133134
};
134135

135136
const DEBUG_FRIENDLY_FIELD_NAMES_INITIAL = {
@@ -1651,6 +1652,8 @@ FlightLogFieldPresenter.decodeFieldToFriendly = function (
16511652
case "gpsCartesianCoords[2]":
16521653
case "gpsDistance":
16531654
return `${value.toFixed(0)} m`;
1655+
case "gpsHomeAzimuth":
1656+
return `${value.toFixed(1)} °`;
16541657

16551658
case "debug[0]":
16561659
case "debug[1]":

src/graph_config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,14 @@ GraphConfig.getDefaultCurveForField = function (flightLog, fieldName) {
476476
max: 100,
477477
},
478478
};
479+
} else if (fieldName == "gpsHomeAzimuth") {
480+
return {
481+
power: 1.0,
482+
MinMax: {
483+
min: 0,
484+
max: 360,
485+
},
486+
};
479487
} else if (fieldName.match(/^debug.*/) && sysConfig.debug_mode != null) {
480488
const debugModeName = DEBUG_MODE[sysConfig.debug_mode];
481489
switch (debugModeName) {
@@ -1542,6 +1550,7 @@ GraphConfig.getExampleGraphConfigs = function (flightLog, graphNames) {
15421550
fields: [
15431551
"gpsCartesianCoords[all]",
15441552
"gpsDistance",
1553+
"gpsHomeAzimuth",
15451554
],
15461555
});
15471556
}

0 commit comments

Comments
 (0)