Skip to content

Commit

Permalink
The azimuth of Home point added as computed field (betaflight#774)
Browse files Browse the repository at this point in the history
* 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 <mark@numloq.nl>

---------

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>
  • Loading branch information
demvlad and haslinghuis authored Oct 5, 2024
1 parent 62978cc commit 97236d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/flightlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
* Window based smoothing of fields is offered.
*/
export function FlightLog(logData) {
let ADDITIONAL_COMPUTED_FIELD_COUNT = 19 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GPS coord**/,
let ADDITIONAL_COMPUTED_FIELD_COUNT = 20 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GPS coord, distance and azimuth **/,
that = this,
logIndex = 0,
logIndexes = new FlightLogIndex(logData),
Expand Down Expand Up @@ -284,7 +284,7 @@ export function FlightLog(logData) {
fieldNames.push("axisError[0]", "axisError[1]", "axisError[2]"); // Custom calculated error field
}
if (!that.isFieldDisabled().GPS) {
fieldNames.push("gpsCartesianCoords[0]", "gpsCartesianCoords[1]", "gpsCartesianCoords[2]", "gpsDistance"); // GPS coords in cartesian system
fieldNames.push("gpsCartesianCoords[0]", "gpsCartesianCoords[1]", "gpsCartesianCoords[2]", "gpsDistance", "gpsHomeAzimuth"); // GPS coords in cartesian system
}

fieldNameToIndex = {};
Expand Down Expand Up @@ -854,11 +854,18 @@ export function FlightLog(logData) {
destFrame[fieldIndex++] = gpsCartesianCoords.y;
destFrame[fieldIndex++] = gpsCartesianCoords.z;
destFrame[fieldIndex++] = Math.sqrt(gpsCartesianCoords.x * gpsCartesianCoords.x + gpsCartesianCoords.z * gpsCartesianCoords.z);

let homeAzimuth = Math.atan2(-gpsCartesianCoords.z, -gpsCartesianCoords.x) * 180 / Math.PI;
if (homeAzimuth < 0) {
homeAzimuth += 360;
}
destFrame[fieldIndex++] = homeAzimuth;
} else {
destFrame[fieldIndex++] = 0;
destFrame[fieldIndex++] = 0;
destFrame[fieldIndex++] = 0;
destFrame[fieldIndex++] = 0;
destFrame[fieldIndex++] = 0;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const FRIENDLY_FIELD_NAMES = {
"gpsCartesianCoords[1]": "GPS Coords [Y]",
"gpsCartesianCoords[2]": "GPS Coords [Z]",
gpsDistance: "GPS Home distance",
gpsHomeAzimuth: "GPS Home azimuth",
};

const DEBUG_FRIENDLY_FIELD_NAMES_INITIAL = {
Expand Down Expand Up @@ -1651,6 +1652,8 @@ FlightLogFieldPresenter.decodeFieldToFriendly = function (
case "gpsCartesianCoords[2]":
case "gpsDistance":
return `${value.toFixed(0)} m`;
case "gpsHomeAzimuth":
return `${value.toFixed(1)} °`;

case "debug[0]":
case "debug[1]":
Expand Down
9 changes: 9 additions & 0 deletions src/graph_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@ GraphConfig.getDefaultCurveForField = function (flightLog, fieldName) {
max: 100,
},
};
} else if (fieldName == "gpsHomeAzimuth") {
return {
power: 1.0,
MinMax: {
min: 0,
max: 360,
},
};
} else if (fieldName.match(/^debug.*/) && sysConfig.debug_mode != null) {
const debugModeName = DEBUG_MODE[sysConfig.debug_mode];
switch (debugModeName) {
Expand Down Expand Up @@ -1542,6 +1550,7 @@ GraphConfig.getExampleGraphConfigs = function (flightLog, graphNames) {
fields: [
"gpsCartesianCoords[all]",
"gpsDistance",
"gpsHomeAzimuth",
],
});
}
Expand Down

0 comments on commit 97236d1

Please sign in to comment.