From a6a419c873fc7e9b3cee43804de4ef6627081d57 Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 6 Sep 2024 13:16:38 +0300 Subject: [PATCH 01/22] added gps coords transform module gps_transform.js --- src/gps_transform.js | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/gps_transform.js diff --git a/src/gps_transform.js b/src/gps_transform.js new file mode 100644 index 00000000..dad43dd7 --- /dev/null +++ b/src/gps_transform.js @@ -0,0 +1,71 @@ +export function GPS_transform(Lat0, Lon0, H0, Heading) { + + function rad2deg(rad) { + return rad * 180.0 / Math.PI; + } + + function deg2rad(deg) { + return deg * Math.PI / 180.0; + } + + Lat0 = deg2rad(Lat0); + Lon0 = deg2rad(Lon0); + const Semimajor = 6378137.0, + Flat = 1.0/298.257223563, + Ecc_2 = Flat*(2-Flat), + SinB = Math.sin(Lat0), + CosB = Math.cos(Lat0), + SinL = Math.sin(Lon0), + CosL = Math.cos(Lon0), + N = Semimajor/Math.sqrt(1.0 - Ecc_2*SinB*SinB), + + a11 = -SinB*CosL, + a12 = -SinB*SinL, + a13 = CosB, + a21 = -SinL, + a22 = CosL, + a23 = 0, + a31 = CosL*CosB, + a32 = CosB*SinL, + a33 = SinB, + + X0 = (N + H0)*CosB*CosL, + Y0 = (N + H0)*CosB*SinL, + Z0 = (N + H0 - Ecc_2*N) * SinB, + c11 = Math.cos( deg2rad(Heading) ), + c12 = Math.sin( deg2rad(Heading) ), + c21 = -c12, + c22 = c11; + + this.WGS_ECEF = function (Lat, Lon, H) { + Lat = deg2rad(Lat); + Lon = deg2rad(Lon); + const + SinB = Math.sin(Lat), + CosB = Math.cos(Lat), + SinL = Math.sin(Lon), + CosL = Math.cos(Lon), + N = Semimajor/Math.sqrt(1-Ecc_2*SinB*SinB); + + return { + x: (N + H)*CosB*CosL, + y: (N + H)*CosB*SinL, + z: (N + H - Ecc_2*N) * SinB + }; + } + + this.ECEF_BS = function (pos) { + const PosX1= a11*(pos.x-X0) + a12*(pos.y-Y0) + a13*(pos.z-Z0); + const PosZ1= a21*(pos.x-X0) + a22*(pos.y-Y0) + a23*(pos.z-Z0); + + return { + x: c11*PosX1 + c12*PosZ1, + y: a31*(pos.x-X0) + a32*(pos.y-Y0) + a33*(pos.z-Z0), + z: c21*PosX1 + c22*PosZ1 + } + } + + this.WGS_BS = function (Lat, Lon, H) { + return this.ECEF_BS(this.WGS_ECEF(Lat, Lon, H)); + } +} \ No newline at end of file From e24e31c03bba901348ba93ee4fca05d808f4f7df Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 6 Sep 2024 13:17:53 +0300 Subject: [PATCH 02/22] Added computed fields for coords in cartesian system --- src/flightlog.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/flightlog.js b/src/flightlog.js index 89c122c5..e10d4a95 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -1,5 +1,6 @@ import { FlightLogIndex } from "./flightlog_index"; import { FlightLogParser } from "./flightlog_parser"; +import { GPS_transform } from "./gps_transform"; import { MAX_MOTOR_NUMBER, DSHOT_MIN_VALUE, @@ -29,7 +30,7 @@ import { * Window based smoothing of fields is offered. */ export function FlightLog(logData) { - let ADDITIONAL_COMPUTED_FIELD_COUNT = 15 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED **/, + let ADDITIONAL_COMPUTED_FIELD_COUNT = 18 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GPS coord**/, that = this, logIndex = 0, logIndexes = new FlightLogIndex(logData), @@ -44,7 +45,8 @@ export function FlightLog(logData) { // Map from field indexes to smoothing window size in microseconds fieldSmoothing = {}, maxSmoothing = 0, - smoothedCache = new FIFOCache(2); + smoothedCache = new FIFOCache(2), + gpsTransform = null; //Public fields: this.parser = parser; @@ -130,7 +132,7 @@ export function FlightLog(logData) { index = index ?? logIndex; return logIndexes.getIntraframeDirectory(index).maxTime; }; - + this.getActualLoggedTime = function (index) { index = index ?? logIndex; const directory = logIndexes.getIntraframeDirectory(index); @@ -281,6 +283,9 @@ export function FlightLog(logData) { if (!that.isFieldDisabled().GYRO && !that.isFieldDisabled().SETPOINT) { fieldNames.push("axisError[0]", "axisError[1]", "axisError[2]"); // Custom calculated error field } + if (!that.isFieldDisabled().GPS) { + fieldNames.push("gpsCartesian[0]", "gpsCartesian[1]", "gpsCartesian[2]"); // GPS coords in cartesian system + } fieldNameToIndex = {}; for (let i = 0; i < fieldNames.length; i++) { @@ -519,9 +524,7 @@ export function FlightLog(logData) { } break; case "H": - // TODO - // contains coordinates only - // should be handled separately + gpsTransform = new GPS_transform(frame[0]/10000000, frame[1]/10000000, 0.0, 0.0); case "G": // The frameValid can be false, when no GPS home (the G frames contains GPS position as diff of GPS Home position). // But other data from the G frame can be valid (time, num sats) @@ -631,6 +634,11 @@ export function FlightLog(logData) { fieldNameToIndex["setpoint[2]"], fieldNameToIndex["setpoint[3]"], ]; + let gpsCoord = [ + fieldNameToIndex["GPS_coord[0]"], + fieldNameToIndex["GPS_coord[1]"], + fieldNameToIndex["GPS_altitude"], + ]; const flightModeFlagsIndex = fieldNameToIndex["flightModeFlags"]; // This points to the flightmode data @@ -690,6 +698,11 @@ export function FlightLog(logData) { axisPID = false; } + if (!gpsCoord[0]) { + gpsCoord = false; + } + + sourceChunkIndex = 0; destChunkIndex = 0; @@ -830,6 +843,20 @@ export function FlightLog(logData) { } } + // Calculate cartesian coords by GPS + if (!that.isFieldDisabled().GPS) { + if (gpsTransform && gpsCoord && srcFrame[gpsCoord[0]]) { + const gpsCartesian = gpsTransform.WGS_BS(srcFrame[gpsCoord[0]]/10000000, srcFrame[gpsCoord[1]]/10000000, srcFrame[gpsCoord[2]]/10); + destFrame[fieldIndex++] = gpsCartesian.x; + destFrame[fieldIndex++] = gpsCartesian.y; + destFrame[fieldIndex++] = gpsCartesian.z; + } else { + destFrame[fieldIndex++] = 0; + destFrame[fieldIndex++] = 0; + destFrame[fieldIndex++] = 0; + } + } + // Remove empty fields at the end destFrame.splice(fieldIndex); } From ae429530bc0f2311c96f348a78848b76dfaacc4c Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 6 Sep 2024 13:18:56 +0300 Subject: [PATCH 03/22] added coords values at curves legend --- src/flightlog_fields_presenter.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/flightlog_fields_presenter.js b/src/flightlog_fields_presenter.js index fd21c49d..170aae17 100644 --- a/src/flightlog_fields_presenter.js +++ b/src/flightlog_fields_presenter.js @@ -1639,6 +1639,11 @@ FlightLogFieldPresenter.decodeFieldToFriendly = function ( } case "GPS_ground_course": return `${(value / 10).toFixed(1)} °`; + + case "gpsCartesian[0]": + case "gpsCartesian[1]": + case "gpsCartesian[2]": + return `${value.toFixed(0)} m`; case "debug[0]": case "debug[1]": From 7b8640b69b41264036a6688aa33bbd2781f1f390 Mon Sep 17 00:00:00 2001 From: demvlad Date: Thu, 26 Sep 2024 14:12:11 +0300 Subject: [PATCH 04/22] The home distance id added as computed field --- src/flightlog.js | 6 ++++-- src/flightlog_fields_presenter.js | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/flightlog.js b/src/flightlog.js index e10d4a95..20b7f1eb 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -30,7 +30,7 @@ import { * Window based smoothing of fields is offered. */ export function FlightLog(logData) { - let ADDITIONAL_COMPUTED_FIELD_COUNT = 18 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GPS coord**/, + let ADDITIONAL_COMPUTED_FIELD_COUNT = 19 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GPS coord**/, that = this, logIndex = 0, logIndexes = new FlightLogIndex(logData), @@ -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("gpsCartesian[0]", "gpsCartesian[1]", "gpsCartesian[2]"); // GPS coords in cartesian system + fieldNames.push("gpsCartesian[0]", "gpsCartesian[1]", "gpsCartesian[2]", "gpsDistance"); // GPS coords in cartesian system } fieldNameToIndex = {}; @@ -850,10 +850,12 @@ export function FlightLog(logData) { destFrame[fieldIndex++] = gpsCartesian.x; destFrame[fieldIndex++] = gpsCartesian.y; destFrame[fieldIndex++] = gpsCartesian.z; + destFrame[fieldIndex++] = Math.sqrt(gpsCartesian.x*gpsCartesian.x + gpsCartesian.z*gpsCartesian.z); } else { destFrame[fieldIndex++] = 0; destFrame[fieldIndex++] = 0; destFrame[fieldIndex++] = 0; + destFrame[fieldIndex++] = 0; } } diff --git a/src/flightlog_fields_presenter.js b/src/flightlog_fields_presenter.js index 170aae17..ca0f6363 100644 --- a/src/flightlog_fields_presenter.js +++ b/src/flightlog_fields_presenter.js @@ -1643,6 +1643,7 @@ FlightLogFieldPresenter.decodeFieldToFriendly = function ( case "gpsCartesian[0]": case "gpsCartesian[1]": case "gpsCartesian[2]": + case "gpsDistance": return `${value.toFixed(0)} m`; case "debug[0]": From 490fa9e8f0573c3b57f323d3590b4344e29288a9 Mon Sep 17 00:00:00 2001 From: demvlad Date: Thu, 26 Sep 2024 14:24:51 +0300 Subject: [PATCH 05/22] added friendly names for gps cartesian coords --- src/flightlog_fields_presenter.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/flightlog_fields_presenter.js b/src/flightlog_fields_presenter.js index ca0f6363..8a92a49e 100644 --- a/src/flightlog_fields_presenter.js +++ b/src/flightlog_fields_presenter.js @@ -124,6 +124,12 @@ const FRIENDLY_FIELD_NAMES = { GPS_altitude: "GPS Altitude ASL", GPS_speed: "GPS Speed", GPS_ground_course: "GPS Heading", + + "gpsCartesian[all]": "Positions", + "gpsCartesian[0]": "Position X", + "gpsCartesian[1]": "Position Y", + "gpsCartesian[2]": "Position Z", + gpsDistance: "Home distance", }; const DEBUG_FRIENDLY_FIELD_NAMES_INITIAL = { From aaf34885718743e821330aa8c004f4d48df8c5ba Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 27 Sep 2024 08:33:03 +0300 Subject: [PATCH 06/22] added using of gps home points altitude if it exists in log file --- src/flightlog.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flightlog.js b/src/flightlog.js index 20b7f1eb..a62d3469 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -524,7 +524,8 @@ export function FlightLog(logData) { } break; case "H": - gpsTransform = new GPS_transform(frame[0]/10000000, frame[1]/10000000, 0.0, 0.0); + const homeAltitude = frame.length == 3 ? frame[2]*10 : 0; + gpsTransform = new GPS_transform(frame[0]/10000000, frame[1]/10000000, homeAltitude, 0.0); case "G": // The frameValid can be false, when no GPS home (the G frames contains GPS position as diff of GPS Home position). // But other data from the G frame can be valid (time, num sats) From b7b9bebf6676021a0900f08557ea4054e21ca233 Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 27 Sep 2024 08:50:02 +0300 Subject: [PATCH 07/22] gps coord names are changed --- src/flightlog.js | 12 ++++++------ src/flightlog_fields_presenter.js | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/flightlog.js b/src/flightlog.js index a62d3469..55a8740d 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -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("gpsCartesian[0]", "gpsCartesian[1]", "gpsCartesian[2]", "gpsDistance"); // GPS coords in cartesian system + fieldNames.push("gpsCartesianCoords[0]", "gpsCartesianCoords[1]", "gpsCartesianCoords[2]", "gpsDistance"); // GPS coords in cartesian system } fieldNameToIndex = {}; @@ -847,11 +847,11 @@ export function FlightLog(logData) { // Calculate cartesian coords by GPS if (!that.isFieldDisabled().GPS) { if (gpsTransform && gpsCoord && srcFrame[gpsCoord[0]]) { - const gpsCartesian = gpsTransform.WGS_BS(srcFrame[gpsCoord[0]]/10000000, srcFrame[gpsCoord[1]]/10000000, srcFrame[gpsCoord[2]]/10); - destFrame[fieldIndex++] = gpsCartesian.x; - destFrame[fieldIndex++] = gpsCartesian.y; - destFrame[fieldIndex++] = gpsCartesian.z; - destFrame[fieldIndex++] = Math.sqrt(gpsCartesian.x*gpsCartesian.x + gpsCartesian.z*gpsCartesian.z); + const gpsCartesianCoords = gpsTransform.WGS_BS(srcFrame[gpsCoord[0]]/10000000, srcFrame[gpsCoord[1]]/10000000, srcFrame[gpsCoord[2]]/10); + destFrame[fieldIndex++] = gpsCartesianCoords.x; + destFrame[fieldIndex++] = gpsCartesianCoords.y; + destFrame[fieldIndex++] = gpsCartesianCoords.z; + destFrame[fieldIndex++] = Math.sqrt(gpsCartesianCoords.x*gpsCartesianCoords.x + gpsCartesianCoords.z*gpsCartesianCoords.z); } else { destFrame[fieldIndex++] = 0; destFrame[fieldIndex++] = 0; diff --git a/src/flightlog_fields_presenter.js b/src/flightlog_fields_presenter.js index 8a92a49e..38a35cbc 100644 --- a/src/flightlog_fields_presenter.js +++ b/src/flightlog_fields_presenter.js @@ -125,11 +125,11 @@ const FRIENDLY_FIELD_NAMES = { GPS_speed: "GPS Speed", GPS_ground_course: "GPS Heading", - "gpsCartesian[all]": "Positions", - "gpsCartesian[0]": "Position X", - "gpsCartesian[1]": "Position Y", - "gpsCartesian[2]": "Position Z", - gpsDistance: "Home distance", + "gpsCartesianCoords[all]": "GPS Coords", + "gpsCartesianCoords[0]": "GPS Coords [X]", + "gpsCartesianCoords[1]": "GPS Coords [H]", + "gpsCartesianCoords[2]": "GPS Coords [Z]", + gpsDistance: "GPS Home distance", }; const DEBUG_FRIENDLY_FIELD_NAMES_INITIAL = { @@ -1646,9 +1646,9 @@ FlightLogFieldPresenter.decodeFieldToFriendly = function ( case "GPS_ground_course": return `${(value / 10).toFixed(1)} °`; - case "gpsCartesian[0]": - case "gpsCartesian[1]": - case "gpsCartesian[2]": + case "gpsCartesianCoords[0]": + case "gpsCartesianCoords[1]": + case "gpsCartesianCoords[2]": case "gpsDistance": return `${value.toFixed(0)} m`; From 0660ea1015d584c6dc2a9378ae72d121668a38ad Mon Sep 17 00:00:00 2001 From: demvlad Date: Fri, 27 Sep 2024 08:57:47 +0300 Subject: [PATCH 08/22] Added example graphs for GPS Cartesian coords data --- src/graph_config.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/graph_config.js b/src/graph_config.js index 87092a3e..89670574 100644 --- a/src/graph_config.js +++ b/src/graph_config.js @@ -1537,6 +1537,13 @@ GraphConfig.getExampleGraphConfigs = function (flightLog, graphNames) { "GPS_coord[all]", ], }); + EXAMPLE_GRAPHS.push({ + label: "GPS Cartesian coords", + fields: [ + "gpsCartesianCoords[all]", + "gpsDistance", + ], + }); } for (const srcGraph of EXAMPLE_GRAPHS) { From ab122c07b8ab01d300958ab63ca28290a9d38dbe Mon Sep 17 00:00:00 2001 From: demvlad Date: Sat, 28 Sep 2024 13:24:19 +0300 Subject: [PATCH 09/22] code issues are resolved --- src/gps_transform.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/gps_transform.js b/src/gps_transform.js index dad43dd7..fc584fdd 100644 --- a/src/gps_transform.js +++ b/src/gps_transform.js @@ -1,9 +1,5 @@ export function GPS_transform(Lat0, Lon0, H0, Heading) { - function rad2deg(rad) { - return rad * 180.0 / Math.PI; - } - function deg2rad(deg) { return deg * Math.PI / 180.0; } @@ -52,7 +48,7 @@ export function GPS_transform(Lat0, Lon0, H0, Heading) { y: (N + H)*CosB*SinL, z: (N + H - Ecc_2*N) * SinB }; - } + }; this.ECEF_BS = function (pos) { const PosX1= a11*(pos.x-X0) + a12*(pos.y-Y0) + a13*(pos.z-Z0); @@ -62,10 +58,10 @@ export function GPS_transform(Lat0, Lon0, H0, Heading) { x: c11*PosX1 + c12*PosZ1, y: a31*(pos.x-X0) + a32*(pos.y-Y0) + a33*(pos.z-Z0), z: c21*PosX1 + c22*PosZ1 - } - } + }; + }; this.WGS_BS = function (Lat, Lon, H) { return this.ECEF_BS(this.WGS_ECEF(Lat, Lon, H)); - } + }; } \ No newline at end of file From d0dd7733fe15e248e16f950ca970b26fba1d10cd Mon Sep 17 00:00:00 2001 From: demvlad Date: Sat, 28 Sep 2024 13:28:41 +0300 Subject: [PATCH 10/22] code issues are resolved --- src/gps_transform.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gps_transform.js b/src/gps_transform.js index fc584fdd..6fbb5d49 100644 --- a/src/gps_transform.js +++ b/src/gps_transform.js @@ -46,7 +46,7 @@ export function GPS_transform(Lat0, Lon0, H0, Heading) { return { x: (N + H)*CosB*CosL, y: (N + H)*CosB*SinL, - z: (N + H - Ecc_2*N) * SinB + z: (N + H - Ecc_2*N) * SinB, }; }; @@ -57,7 +57,7 @@ export function GPS_transform(Lat0, Lon0, H0, Heading) { return { x: c11*PosX1 + c12*PosZ1, y: a31*(pos.x-X0) + a32*(pos.y-Y0) + a33*(pos.z-Z0), - z: c21*PosX1 + c22*PosZ1 + z: c21*PosX1 + c22*PosZ1, }; }; From 3a23761ec30c3ba207173f1d133d88c9c60b13d4 Mon Sep 17 00:00:00 2001 From: demvlad Date: Sat, 28 Sep 2024 13:33:03 +0300 Subject: [PATCH 11/22] code issues are resolved --- src/flightlog.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/flightlog.js b/src/flightlog.js index 55a8740d..20572a2c 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -526,6 +526,7 @@ export function FlightLog(logData) { case "H": const homeAltitude = frame.length == 3 ? frame[2]*10 : 0; gpsTransform = new GPS_transform(frame[0]/10000000, frame[1]/10000000, homeAltitude, 0.0); + break; case "G": // The frameValid can be false, when no GPS home (the G frames contains GPS position as diff of GPS Home position). // But other data from the G frame can be valid (time, num sats) From 026e65f6ee5fb3ac373a3a0374bd1755e8cd5b1a Mon Sep 17 00:00:00 2001 From: demvlad Date: Sat, 28 Sep 2024 13:46:39 +0300 Subject: [PATCH 12/22] code style improvement --- src/flightlog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flightlog.js b/src/flightlog.js index 20572a2c..16b50160 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -524,7 +524,7 @@ export function FlightLog(logData) { } break; case "H": - const homeAltitude = frame.length == 3 ? frame[2]*10 : 0; + const homeAltitude = frame.length > 2 ? frame[2]/10 : 0; // will work after BF firmware improvement gpsTransform = new GPS_transform(frame[0]/10000000, frame[1]/10000000, homeAltitude, 0.0); break; case "G": From 64ff0ae220520f1254fce36a0b70ea75cb29dfe9 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Sat, 28 Sep 2024 22:53:58 +0300 Subject: [PATCH 13/22] Field name is improved Co-authored-by: Mark Haslinghuis --- src/flightlog_fields_presenter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flightlog_fields_presenter.js b/src/flightlog_fields_presenter.js index 38a35cbc..50ce336a 100644 --- a/src/flightlog_fields_presenter.js +++ b/src/flightlog_fields_presenter.js @@ -127,7 +127,7 @@ const FRIENDLY_FIELD_NAMES = { "gpsCartesianCoords[all]": "GPS Coords", "gpsCartesianCoords[0]": "GPS Coords [X]", - "gpsCartesianCoords[1]": "GPS Coords [H]", + "gpsCartesianCoords[1]": "GPS Coords [Y]", "gpsCartesianCoords[2]": "GPS Coords [Z]", gpsDistance: "GPS Home distance", }; From 2bee001e4f03c936881e2ff1981f41d919b3908f Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Sat, 28 Sep 2024 22:54:29 +0300 Subject: [PATCH 14/22] Code style improvement Co-authored-by: Mark Haslinghuis --- src/flightlog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/flightlog.js b/src/flightlog.js index 16b50160..cd478ae9 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -524,8 +524,8 @@ export function FlightLog(logData) { } break; case "H": - const homeAltitude = frame.length > 2 ? frame[2]/10 : 0; // will work after BF firmware improvement - gpsTransform = new GPS_transform(frame[0]/10000000, frame[1]/10000000, homeAltitude, 0.0); + const homeAltitude = frame.length > 2 ? frame[2 ] /10 : 0; // will work after BF firmware improvement + gpsTransform = new GPS_transform(frame[0] / 10000000, frame[1] / 10000000, homeAltitude, 0.0); break; case "G": // The frameValid can be false, when no GPS home (the G frames contains GPS position as diff of GPS Home position). From 80c78f87f887763c638a4d8dc67fb2bda110d170 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Sat, 28 Sep 2024 22:55:40 +0300 Subject: [PATCH 15/22] Code style improvement Co-authored-by: Mark Haslinghuis --- src/flightlog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flightlog.js b/src/flightlog.js index cd478ae9..7c7e23e5 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -852,7 +852,7 @@ export function FlightLog(logData) { destFrame[fieldIndex++] = gpsCartesianCoords.x; destFrame[fieldIndex++] = gpsCartesianCoords.y; destFrame[fieldIndex++] = gpsCartesianCoords.z; - destFrame[fieldIndex++] = Math.sqrt(gpsCartesianCoords.x*gpsCartesianCoords.x + gpsCartesianCoords.z*gpsCartesianCoords.z); + destFrame[fieldIndex++] = Math.sqrt(gpsCartesianCoords.x * gpsCartesianCoords.x + gpsCartesianCoords.z * gpsCartesianCoords.z); } else { destFrame[fieldIndex++] = 0; destFrame[fieldIndex++] = 0; From 1fcd35a93d063d83976410471c4468ffee92f81e Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Sat, 28 Sep 2024 22:56:34 +0300 Subject: [PATCH 16/22] Code style improvement Co-authored-by: Mark Haslinghuis --- src/gps_transform.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gps_transform.js b/src/gps_transform.js index 6fbb5d49..86c4fab6 100644 --- a/src/gps_transform.js +++ b/src/gps_transform.js @@ -64,4 +64,5 @@ export function GPS_transform(Lat0, Lon0, H0, Heading) { this.WGS_BS = function (Lat, Lon, H) { return this.ECEF_BS(this.WGS_ECEF(Lat, Lon, H)); }; + } \ No newline at end of file From 05d351563189b819e0d37cbf353d3287d4076712 Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Sat, 28 Sep 2024 22:57:24 +0300 Subject: [PATCH 17/22] Code style improvement Co-authored-by: Mark Haslinghuis --- src/flightlog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flightlog.js b/src/flightlog.js index 7c7e23e5..c86bff60 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -848,7 +848,7 @@ export function FlightLog(logData) { // Calculate cartesian coords 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); + const gpsCartesianCoords = gpsTransform.WGS_BS(srcFrame[gpsCoord[0]] / 10000000, srcFrame[gpsCoord[1] ] /10000000, srcFrame[gpsCoord[2]] / 10); destFrame[fieldIndex++] = gpsCartesianCoords.x; destFrame[fieldIndex++] = gpsCartesianCoords.y; destFrame[fieldIndex++] = gpsCartesianCoords.z; From 9bb97fa29cbc0011d5bd1e8feedb6afc0198113e Mon Sep 17 00:00:00 2001 From: Vladimir Demidov Date: Sat, 28 Sep 2024 23:11:51 +0300 Subject: [PATCH 18/22] Code style improvement Co-authored-by: Mark Haslinghuis --- src/gps_transform.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gps_transform.js b/src/gps_transform.js index 86c4fab6..35a31ee4 100644 --- a/src/gps_transform.js +++ b/src/gps_transform.js @@ -64,5 +64,6 @@ export function GPS_transform(Lat0, Lon0, H0, Heading) { this.WGS_BS = function (Lat, Lon, H) { return this.ECEF_BS(this.WGS_ECEF(Lat, Lon, H)); }; +} -} \ No newline at end of file +Also please add spaces around operators in this file. \ No newline at end of file From d4b67def254edd604634da6f62bbbaffe6dd594f Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Sat, 28 Sep 2024 22:25:08 +0200 Subject: [PATCH 19/22] Update gps_transform.js --- src/gps_transform.js | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/gps_transform.js b/src/gps_transform.js index 35a31ee4..f9feaef3 100644 --- a/src/gps_transform.js +++ b/src/gps_transform.js @@ -7,27 +7,27 @@ export function GPS_transform(Lat0, Lon0, H0, Heading) { Lat0 = deg2rad(Lat0); Lon0 = deg2rad(Lon0); const Semimajor = 6378137.0, - Flat = 1.0/298.257223563, - Ecc_2 = Flat*(2-Flat), + Flat = 1.0 / 298.257223563, + Ecc_2 = Flat * (2 - Flat), SinB = Math.sin(Lat0), CosB = Math.cos(Lat0), SinL = Math.sin(Lon0), CosL = Math.cos(Lon0), - N = Semimajor/Math.sqrt(1.0 - Ecc_2*SinB*SinB), + N = Semimajor / Math.sqrt(1.0 - Ecc_2 * SinB * SinB), - a11 = -SinB*CosL, - a12 = -SinB*SinL, + a11 = -SinB * CosL, + a12 = -SinB * SinL, a13 = CosB, a21 = -SinL, a22 = CosL, a23 = 0, - a31 = CosL*CosB, - a32 = CosB*SinL, + a31 = CosL * CosB, + a32 = CosB * SinL, a33 = SinB, - X0 = (N + H0)*CosB*CosL, - Y0 = (N + H0)*CosB*SinL, - Z0 = (N + H0 - Ecc_2*N) * SinB, + X0 = (N + H0) * CosB * CosL, + Y0 = (N + H0) * CosB * SinL, + Z0 = (N + H0 - Ecc_2 * N) * SinB, c11 = Math.cos( deg2rad(Heading) ), c12 = Math.sin( deg2rad(Heading) ), c21 = -c12, @@ -41,23 +41,23 @@ export function GPS_transform(Lat0, Lon0, H0, Heading) { CosB = Math.cos(Lat), SinL = Math.sin(Lon), CosL = Math.cos(Lon), - N = Semimajor/Math.sqrt(1-Ecc_2*SinB*SinB); + N = Semimajor / Math.sqrt(1 - Ecc_2 * SinB * SinB); return { - x: (N + H)*CosB*CosL, - y: (N + H)*CosB*SinL, - z: (N + H - Ecc_2*N) * SinB, + x: (N + H) * CosB * CosL, + y: (N + H) * CosB * SinL, + z: (N + H - Ecc_2 * N) * SinB, }; }; this.ECEF_BS = function (pos) { - const PosX1= a11*(pos.x-X0) + a12*(pos.y-Y0) + a13*(pos.z-Z0); - const PosZ1= a21*(pos.x-X0) + a22*(pos.y-Y0) + a23*(pos.z-Z0); + const PosX1= a11 * (pos.x - X0) + a12 * (pos.y - Y0) + a13 * (pos.z - Z0); + const PosZ1= a21 * (pos.x - X0) + a22 * (pos.y - Y0) + a23 * (pos.z - Z0); return { - x: c11*PosX1 + c12*PosZ1, - y: a31*(pos.x-X0) + a32*(pos.y-Y0) + a33*(pos.z-Z0), - z: c21*PosX1 + c22*PosZ1, + x: c11 * PosX1 + c12 * PosZ1, + y: a31 * (pos.x - X0) + a32 * (pos.y - Y0) + a33 * (pos.z - Z0), + z: c21 * PosX1 + c22 * PosZ1, }; }; @@ -65,5 +65,3 @@ export function GPS_transform(Lat0, Lon0, H0, Heading) { return this.ECEF_BS(this.WGS_ECEF(Lat, Lon, H)); }; } - -Also please add spaces around operators in this file. \ No newline at end of file From 39ced3429b761e1fb421b1f96d387cd70c036e80 Mon Sep 17 00:00:00 2001 From: demvlad Date: Sat, 28 Sep 2024 23:51:08 +0300 Subject: [PATCH 20/22] Code style improvement --- src/flightlog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flightlog.js b/src/flightlog.js index c86bff60..51e55b82 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -848,7 +848,7 @@ export function FlightLog(logData) { // Calculate cartesian coords 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); + const gpsCartesianCoords = gpsTransform.WGS_BS(srcFrame[gpsCoord[0]] / 10000000, srcFrame[gpsCoord[1]] / 10000000, srcFrame[gpsCoord[2]] / 10); destFrame[fieldIndex++] = gpsCartesianCoords.x; destFrame[fieldIndex++] = gpsCartesianCoords.y; destFrame[fieldIndex++] = gpsCartesianCoords.z; From 255d625d8722c0c6ab8b85c76f08b4532bf35601 Mon Sep 17 00:00:00 2001 From: demvlad Date: Sun, 29 Sep 2024 00:01:12 +0300 Subject: [PATCH 21/22] Code style improvement --- src/flightlog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flightlog.js b/src/flightlog.js index 51e55b82..aa4be883 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -524,7 +524,7 @@ export function FlightLog(logData) { } break; case "H": - const homeAltitude = frame.length > 2 ? frame[2 ] /10 : 0; // will work after BF firmware improvement + const homeAltitude = frame.length > 2 ? frame[2] / 10 : 0; // will work after BF firmware improvement gpsTransform = new GPS_transform(frame[0] / 10000000, frame[1] / 10000000, homeAltitude, 0.0); break; case "G": From 26c6a7c7935995ab0d9337b439110690a6f84c4e Mon Sep 17 00:00:00 2001 From: demvlad Date: Sun, 29 Sep 2024 00:40:20 +0300 Subject: [PATCH 22/22] Code style improvement --- src/flightlog.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flightlog.js b/src/flightlog.js index aa4be883..8b1b7107 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -523,10 +523,11 @@ export function FlightLog(logData) { lastSlow[i] = frame[i]; } break; - case "H": + case "H": { const homeAltitude = frame.length > 2 ? frame[2] / 10 : 0; // will work after BF firmware improvement gpsTransform = new GPS_transform(frame[0] / 10000000, frame[1] / 10000000, homeAltitude, 0.0); break; + } case "G": // The frameValid can be false, when no GPS home (the G frames contains GPS position as diff of GPS Home position). // But other data from the G frame can be valid (time, num sats)