Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 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 = 20 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GPS coord, distance and azimuth **/,
let ADDITIONAL_COMPUTED_FIELD_COUNT = 21 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GPS coord, distance, azimuth, trajectory tilt angle **/,
that = this,
logIndex = 0,
logIndexes = new FlightLogIndex(logData),
Expand Down Expand Up @@ -285,7 +285,8 @@ 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", "gpsHomeAzimuth"); // GPS coords in cartesian system
// GPS coords in cartesian system, trajectory tilt angle
fieldNames.push("gpsCartesianCoords[0]", "gpsCartesianCoords[1]", "gpsCartesianCoords[2]", "gpsDistance", "gpsHomeAzimuth", "gpsTrajectoryTiltAngle");
}

fieldNameToIndex = {};
Expand Down Expand Up @@ -636,6 +637,11 @@ export function FlightLog(logData) {
fieldNameToIndex["GPS_coord[1]"],
fieldNameToIndex["GPS_altitude"],
];
let gpsVelNED = [
fieldNameToIndex["GPS_velned[0]"],
fieldNameToIndex["GPS_velned[1]"],
fieldNameToIndex["GPS_velned[2]"],
];

const flightModeFlagsIndex = fieldNameToIndex["flightModeFlags"]; // This points to the flightmode data

Expand Down Expand Up @@ -705,6 +711,9 @@ export function FlightLog(logData) {
gpsCoord = false;
}

if (!gpsVelNED[0]) {
gpsVelNED = false;
}

sourceChunkIndex = 0;
destChunkIndex = 0;
Expand Down Expand Up @@ -746,7 +755,7 @@ export function FlightLog(logData) {
if (m < 1.0) {
// reconstruct .w of unit quaternion
q.w = Math.sqrt(1.0 - m);
} else {
} else {
// normalize [0,x,y,z]
m = Math.sqrt(m);
q.x /= m;
Expand Down Expand Up @@ -877,7 +886,7 @@ export function FlightLog(logData) {
}
}

// Calculate cartesian coords by GPS
// Calculate cartesian coords, azimuth and trajectory tilt angle by GPS
if (!that.isFieldDisabled().GPS) {
if (gpsTransform && gpsCoord && srcFrame[gpsCoord[0]]) {
const gpsCartesianCoords = gpsTransform.WGS_BS(srcFrame[gpsCoord[0]] / 10000000, srcFrame[gpsCoord[1]] / 10000000, srcFrame[gpsCoord[2]] / 10);
Expand All @@ -898,6 +907,23 @@ export function FlightLog(logData) {
destFrame[fieldIndex++] = 0;
destFrame[fieldIndex++] = 0;
}

// Calculate trajectory tilt angle by NED GPS velocity
if (gpsVelNED) {
const Vn = srcFrame[gpsVelNED[0]],
Ve = srcFrame[gpsVelNED[1]],
Vd = srcFrame[gpsVelNED[2]];
const velocity = Math.hypot(Vn, Ve, Vd);
const minVelo = 5; // 5cm/s limit to prevent division by zero and miss tiny noise values
let trajectoryTiltAngle = 0;
if (velocity > minVelo) {
const angleSin = Math.max(-1, Math.min(1, Vd / velocity));
trajectoryTiltAngle = -Math.asin(angleSin) * 180 / Math.PI; // [degree], if velo is up then >0
}
destFrame[fieldIndex++] = trajectoryTiltAngle;
} else {
destFrame[fieldIndex++] = 0;
}
}

// Remove empty fields at the end
Expand Down
2 changes: 2 additions & 0 deletions src/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const FRIENDLY_FIELD_NAMES = {
"gpsCartesianCoords[2]": "GPS Coords [Z]",
gpsDistance: "GPS Home distance",
gpsHomeAzimuth: "GPS Home azimuth",
gpsTrajectoryTiltAngle: "GPS Traject. tilt angle",
};

const DEBUG_FRIENDLY_FIELD_NAMES_INITIAL = {
Expand Down Expand Up @@ -1853,6 +1854,7 @@ FlightLogFieldPresenter.decodeFieldToFriendly = function (
case "gpsDistance":
return `${value.toFixed(0)} m`;
case "gpsHomeAzimuth":
case "gpsTrajectoryTiltAngle":
return `${value.toFixed(1)} °`;
case "magADC[0]":
case "magADC[1]":
Expand Down
Loading