Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GPS data option + other improvements #102

Merged
merged 5 commits into from
Aug 24, 2024
Merged
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
18 changes: 14 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h1>INAV Blackbox Explorer!</h1>
</div>
<div class="panel-body">
<p>
The Blackbox feature is built in to <a target="_blank" href="https://github.com/iNavFlight/inav/blob/master/docs/Blackbox.md">INAV</a>
The Blackbox feature is built in to <a target="_blank" href="https://github.com/iNavFlight/inav/blob/master/docs/Blackbox.md">INAV</a>
and is supported on most flight controllers..
</p>
<p>
Expand Down Expand Up @@ -125,7 +125,7 @@ <h1>INAV Blackbox Explorer!</h1>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -824,7 +824,7 @@ <h5 class="modal-title-craft"></h5>
<td name="rates[1]"><label>PITCH Rate</label><input type="number" step="0.01" min="0" max="1.00" readonly /></td>
<td name="rates[2]"><label>YAW Rate</label><input type="number" step="0.01" min="0" max="2.55" readonly /></td>
</tr>

</tbody>
</table>
<table class="parameter cf">
Expand Down Expand Up @@ -937,7 +937,7 @@ <h5 class="modal-title-craft"></h5>
</table>
</div>
</div>

</div>
</div>
</form>
Expand Down Expand Up @@ -1437,6 +1437,16 @@ <h4 class="modal-title">Advanced User Settings</h4>
</div>
</div>
</div>
<div class="gui_box grey top-spacer logdata-settings">
<div class="gui_box_titlebar">
<div class="spacer_box_title">Log Data Settings</div>
</div>
<div class="spacer_box">
<div>
<label class="option">GPS<input class="logdata-gps ios-switch" type="checkbox"/><div><div></div></div><span>Show GPS Data</span></label>
</div>
</div>
</div>
</div>
</div>
<div class="clear-both"></div>
Expand Down
45 changes: 38 additions & 7 deletions js/flightlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
function FlightLog(logData) {
var
ADDITIONAL_COMPUTED_FIELD_COUNT = 9, /** attitude + PID_SUM + PID_ERROR + VELOCITY + WIND_VELOCITY + WIND_HEADING **/
ADDITIONAL_COMPUTED_FIELD_COUNT = 10, /** attitude + PID_SUM + PID_ERROR + VELOCITY + WIND_VELOCITY + WIND_HEADING + HOME DISTANCE**/

that = this,
logIndex = false,
Expand Down Expand Up @@ -222,10 +222,16 @@ function FlightLog(logData) {
}
}

if (userSettings.logDataGps && parser.frameDefs.G) {
for (i = 0; i < parser.frameDefs.G.name.length; i++) {
fieldNames.push(parser.frameDefs.G.name[i]);
}
}

// Add names for our ADDITIONAL_COMPUTED_FIELDS
fieldNames.push("axisSum[0]", "axisSum[1]", "axisSum[2]");
fieldNames.push("axisError[0]", "axisError[1]", "axisError[2]"); // Custom calculated error field
fieldNames.push("velocity", "windVelocity", "windHeading");
fieldNames.push("velocity", "windVelocity", "windHeading", "homeDistance");

fieldNameToIndex = {};
for (i = 0; i < fieldNames.length; i++) {
Expand Down Expand Up @@ -253,7 +259,7 @@ function FlightLog(logData) {
found = false;

var refVoltage;
if((sysConfig.firmwareType == FIRMWARE_TYPE_BETAFLIGHT && semver.gte(sysConfig.firmwareVersion, '3.1.0')) ||
if((sysConfig.firmwareType == FIRMWARE_TYPE_BETAFLIGHT && semver.gte(sysConfig.firmwareVersion, '3.1.0')) ||
(sysConfig.firmwareType == FIRMWARE_TYPE_CLEANFLIGHT && semver.gte(sysConfig.firmwareVersion, '2.0.0'))) {
refVoltage = sysConfig.vbatref;
} else {
Expand Down Expand Up @@ -360,6 +366,11 @@ function FlightLog(logData) {
slowFrameLength = parser.frameDefs.S ? parser.frameDefs.S.count : 0,
lastSlow = parser.frameDefs.S ? iframeDirectory.initialSlow[chunkIndex].slice(0) : [];

var
gpsFrameLength = userSettings.logDataGps && parser.frameDefs.G ? parser.frameDefs.G.count : 0,
lastGPSData = userSettings.logDataGps && parser.frameDefs.G ? iframeDirectory.initialGPSData[chunkIndex].slice(0) : [];


parser.onFrameReady = function(frameValid, frame, frameType, frameOffset, frameSize) {
var
destFrame;
Expand All @@ -369,9 +380,7 @@ function FlightLog(logData) {
case 'P':
case 'I':
//The parser re-uses the "frame" array so we must copy that data somewhere else

var
numOutputFields = frame.length + slowFrameLength + ADDITIONAL_COMPUTED_FIELD_COUNT;
var numOutputFields = frame.length + slowFrameLength + gpsFrameLength + ADDITIONAL_COMPUTED_FIELD_COUNT ;

//Do we have a recycled chunk to copy on top of?
if (chunk.frames[mainFrameIndex]) {
Expand All @@ -393,6 +402,13 @@ function FlightLog(logData) {
destFrame[i + frame.length] = lastSlow[i] === undefined ? null : lastSlow[i];
}

if (userSettings.logDataGps) {
// Then merge in the last seen gps-frame data
for (var i = 0; i < gpsFrameLength; i++) {
destFrame[i + frame.length + slowFrameLength] = lastGPSData[i] === undefined ? null : lastGPSData[i];
}
}

for (var i = 0; i < eventNeedsTimestamp.length; i++) {
eventNeedsTimestamp[i].time = frame[FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME];
}
Expand Down Expand Up @@ -423,6 +439,13 @@ function FlightLog(logData) {
lastSlow[i] = frame[i];
}
break;
case 'G':
if (userSettings.logDataGps) {
for (var i = 0; i < frame.length; i++) {
lastGPSData[i] = frame[i];
}
}
break;
}
} else {
chunk.gapStartsHere[mainFrameIndex - 1] = true;
Expand Down Expand Up @@ -502,7 +525,8 @@ function FlightLog(logData) {
sourceChunkIndex, destChunkIndex,
sysConfig,
navVel = [fieldNameToIndex["navVel[0]"], fieldNameToIndex["navVel[1]"]],
wind = [fieldNameToIndex["wind[0]"], fieldNameToIndex["wind[1]"], fieldNameToIndex["wind[2]"]];
wind = [fieldNameToIndex["wind[0]"], fieldNameToIndex["wind[1]"], fieldNameToIndex["wind[2]"]],
navPos = [fieldNameToIndex["navPos[0]"], fieldNameToIndex["navPos[1]"]];

let axisPID = [
[fieldNameToIndex["axisP[0]"], fieldNameToIndex["axisI[0]"], fieldNameToIndex["axisD[0]"], fieldNameToIndex["axisF[0]"]],
Expand Down Expand Up @@ -580,6 +604,13 @@ function FlightLog(logData) {
destFrame[fieldIndex+1] = windRads;
}
fieldIndex += 2;

// Compute distance to home
let posX = srcFrame[navPos[0]], posY = srcFrame[navPos[1]];
if (posX != undefined && posY != undefined) {
destFrame[fieldIndex] = Math.round(Math.hypot(posX, posY));
}
fieldIndex++;
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion js/flightlog_fielddefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,18 @@ var
"CRUISE_3D_ADJUSTING",
"WAYPOINT_HOLD",
"RTH_HOVER_ABOVE_HOME",
"UNUSED_4"
"UNUSED_4",
"RTH_TRACKBACK",
"MIXERAT_INITIALIZE",
"MIXERAT_IN_PROGRESS",
"MIXERAT_ABORT",
"FW_LANDING_CLIMB_TO_LOITER",
"FW_LANDING_LOITER",
"FW_LANDING_APPROACH",
"FW_LANDING_GLIDE",
"FW_LANDING_FLARE",
"FW_LANDING_ABORT",
"FW_LANDING_FINISHED"
]),

FLIGHT_LOG_NAV_FLAGS = makeReadOnly([
Expand Down
26 changes: 21 additions & 5 deletions js/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function FlightLogFieldPresenter() {
* @param value Value of the field
*/
FlightLogFieldPresenter.decodeFieldToFriendly = function (flightLog, fieldName, value, currentFlightMode) {
if (value === undefined)
if (value === undefined || value === null)
return "";

switch (fieldName) {
Expand Down Expand Up @@ -454,15 +454,18 @@ function FlightLogFieldPresenter() {
case 'windHeading':
return (value / Math.PI * 180).toFixed(1) + "deg";

case 'BaroAlt':
return (value / 100).toFixed(2) + "m";

case "navEPH":
return (value/100).toFixed(2);

case 'BaroAlt':
case "navPos[0]":
case "navPos[1]":
case "navPos[2]":
case "navTgtPos[0]":
case "navTgtPos[1]":
case "navTgtPos[2]":
return (value / 100).toFixed(2) + "m";
case "homeDistance":
return (value / 100).toFixed(2) + " m";

case 'flightModeFlags':
return presentFlags(value, FLIGHT_LOG_FLIGHT_MODE_NAME);
Expand Down Expand Up @@ -506,6 +509,7 @@ function FlightLogFieldPresenter() {
case 'wind[0]':
case 'wind[1]':
case 'windVelocity':
case 'GPS_speed':
if (userSettings.velocityUnits == 'I') // Imperial
return (value * 0.0223694).toFixed(1) + "mph";
if (userSettings.velocityUnits == 'M') // Metric
Expand Down Expand Up @@ -539,6 +543,18 @@ function FlightLogFieldPresenter() {
case 'sens7Temp':
case 'escTemperature':
return (value == -1250) ? "" : (value / 10.0).toFixed(1) + '&deg;';
case 'GPS_coord[0]':
case 'GPS_coord[1]':
return (value / 10000000.0).toFixed(7) + " degs";
case 'GPS_altitude':
return value + " m";
case 'GPS_ground_course':
case 'attitude[0]':
case 'attitude[1]':
case 'attitude[2]':
return (value / 10.0).toFixed(1) + " degs";
case 'navTgtHdg':
return (value / 100.0).toFixed(1) + " degs";

default:
return value.toString();
Expand Down
Loading
Loading