Skip to content

Commit 4b20639

Browse files
LinusThorsellbonchanhaslinghuis
authored
Allow for GPS Data in Table/Graph/Exports (#606)
* c * haslinghuis diff from 602#issuecomment-1320958859 * added check undefined returning undefined * displays data in table and graph * progress, table loads offset by 5, but works * GPS G Frame logs successfully. * removed unecessary comments * fixed names in table * removed test code in main, remove whitespaces * fixed GPS cases and added gps example graph * using const name of, instead of normal for in flightlog as suggested by haslinghuis Co-authored-by: haslinghuis <[email protected]> * changes suggested by ctzsnooze (presentability) Changed GPS Ground Course to GPS Heading Changed GPS numSat to GPS Sat Count Changed gps heading to return from 180 to -180 degrees. * readability changes * make numsat and speed start at bottom of graph * removed time field. refactored code * cosmetic code changes * changed live gps to GPS Reported Altitude * fixed gps ASL altitude scaling, changed reported gps alt to alt ASL Co-authored-by: bonchan <[email protected]> Co-authored-by: haslinghuis <[email protected]>
1 parent 6b80c9f commit 4b20639

File tree

5 files changed

+92
-13
lines changed

5 files changed

+92
-13
lines changed

js/flightlog.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,23 @@ function FlightLog(logData) {
207207
} else
208208
return false;
209209
};
210-
210+
211211
function buildFieldNames() {
212212
// Make an independent copy
213213
fieldNames = parser.frameDefs.I.name.slice(0);
214214

215215
// Add names of slow fields which we'll merge into the main stream
216216
if (parser.frameDefs.S) {
217-
for (let i = 0; i < parser.frameDefs.S.name.length; i++) {
218-
fieldNames.push(parser.frameDefs.S.name[i]);
217+
for (const name of parser.frameDefs.S.name) {
218+
fieldNames.push(name);
219+
}
220+
}
221+
// Add names of gps fields which we'll merge into the main stream
222+
if (parser.frameDefs.G) {
223+
for (const name of parser.frameDefs.G.name) {
224+
if (name !== 'time') { // remove duplicate time field
225+
fieldNames.push(name);
226+
}
219227
}
220228
}
221229

@@ -375,11 +383,14 @@ function FlightLog(logData) {
375383
var
376384
mainFrameIndex = 0,
377385
slowFrameLength = parser.frameDefs.S ? parser.frameDefs.S.count : 0,
378-
lastSlow = parser.frameDefs.S ? iframeDirectory.initialSlow[chunkIndex].slice(0) : [];
386+
lastSlow = parser.frameDefs.S ? iframeDirectory.initialSlow[chunkIndex].slice(0) : [],
387+
lastGPSLength = parser.frameDefs.G ? parser.frameDefs.G.count-1 : 0, // -1 since we exclude the time field
388+
lastGPS = parser.frameDefs.G ? iframeDirectory.initialGPS[chunkIndex].slice(0) : [];
379389

380390
parser.onFrameReady = function(frameValid, frame, frameType, frameOffset, frameSize) {
381391
var
382-
destFrame;
392+
destFrame,
393+
destFrame_currentIndex;
383394

384395
// The G frames need to be processed always. They are "invalid" if not H (Home) has been detected
385396
// before, but if not processed the viewer shows cuts and gaps. This happens if the quad takes off before
@@ -392,7 +403,7 @@ function FlightLog(logData) {
392403
//The parser re-uses the "frame" array so we must copy that data somewhere else
393404

394405
var
395-
numOutputFields = frame.length + slowFrameLength + ADDITIONAL_COMPUTED_FIELD_COUNT;
406+
numOutputFields = frame.length + slowFrameLength + lastGPSLength + ADDITIONAL_COMPUTED_FIELD_COUNT;
396407

397408
//Do we have a recycled chunk to copy on top of?
398409
if (chunk.frames[mainFrameIndex]) {
@@ -409,10 +420,18 @@ function FlightLog(logData) {
409420
destFrame[i] = frame[i];
410421
}
411422

423+
destFrame_currentIndex = frame.length; // Keeps track of where to place direct data in the destFrame.
412424
// Then merge in the last seen slow-frame data
413-
for (var i = 0; i < slowFrameLength; i++) {
414-
destFrame[i + frame.length] = lastSlow[i] === undefined ? null : lastSlow[i];
425+
for (let slowFrameIndex = 0; slowFrameIndex < slowFrameLength; slowFrameIndex++) {
426+
destFrame[slowFrameIndex + destFrame_currentIndex] = lastSlow[slowFrameIndex] === undefined ? null : lastSlow[slowFrameIndex];
415427
}
428+
destFrame_currentIndex += slowFrameLength;
429+
430+
// Also merge last seen gps-frame data
431+
for (let gpsFrameIndex = 0; gpsFrameIndex < lastGPSLength; gpsFrameIndex++) {
432+
destFrame[gpsFrameIndex + destFrame_currentIndex] = lastGPS[gpsFrameIndex] === undefined ? null : lastGPS[gpsFrameIndex];
433+
}
434+
// destFrame_currentIndex += lastGPSLength; Add this line if you wish to add more fields.
416435

417436
for (var i = 0; i < eventNeedsTimestamp.length; i++) {
418437
eventNeedsTimestamp[i].time = frame[FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME];
@@ -446,10 +465,18 @@ function FlightLog(logData) {
446465
}
447466
break;
448467
case 'H':
468+
// TODO
469+
// contains coordinates only
470+
// should be handled separately
449471
case 'G':
450-
// TODO pending to do something with GPS frames
451472
// The frameValid can be false, when no GPS home (the G frames contains GPS position as diff of GPS Home position).
452473
// But other data from the G frame can be valid (time, num sats)
474+
475+
//H Field G name:time,GPS_numSat,GPS_coord[0],GPS_coord[1],GPS_altitude,GPS_speed,GPS_ground_course
476+
frame.shift(); // remove time
477+
for (let i = 0; i < frame.length; i++) {
478+
lastGPS[i] = frame[i];
479+
}
453480
break;
454481
}
455482
} else {

js/flightlog_fields_presenter.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ function FlightLogFieldPresenter() {
106106
'rxSignalReceived': 'RX Signal Received',
107107
'rxFlightChannelsValid': 'RX Flight Ch. Valid',
108108
'rssi': 'RSSI',
109+
110+
'GPS_numSat': "GPS Sat Count",
111+
'GPS_coord[0]': "GPS Latitude",
112+
'GPS_coord[1]': "GPS Longitude",
113+
'GPS_altitude': "GPS Altitude ASL",
114+
'GPS_speed': "GPS Speed",
115+
'GPS_ground_course': "GPS Heading",
109116
};
110117

111118
const DEBUG_FRIENDLY_FIELD_NAMES_INITIAL = {
@@ -977,6 +984,19 @@ function FlightLogFieldPresenter() {
977984
case 'rssi':
978985
return (value / 1024 * 100).toFixed(2) + " %";
979986

987+
//H Field G name:time,GPS_numSat,GPS_coord[0],GPS_coord[1],GPS_altitude,GPS_speed,GPS_ground_course
988+
case 'GPS_numSat':
989+
return `${value}`;
990+
case 'GPS_coord[0]':
991+
case 'GPS_coord[1]':
992+
return `${(value/10000000).toFixed(5)}`;
993+
case 'GPS_altitude':
994+
return `${(value/10).toFixed(2)} m`;
995+
case 'GPS_speed':
996+
return `${(value/100).toFixed(2)} m/s`;
997+
case 'GPS_ground_course':
998+
return `${(value/10).toFixed(1)} °`;
999+
9801000
case 'debug[0]':
9811001
case 'debug[1]':
9821002
case 'debug[2]':

js/flightlog_index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function FlightLogIndex(logData) {
4646
initialIMU: [],
4747
initialSlow: [],
4848
initialGPSHome: [],
49+
initialGPS: [],
4950
hasEvent: [],
5051
minTime: false,
5152
maxTime: false
@@ -77,14 +78,15 @@ function FlightLogIndex(logData) {
7778
var
7879
sysConfig = parser.sysConfig,
7980
mainFrameDef = parser.frameDefs.I,
80-
81+
8182
gyroADC = [mainFrameDef.nameToIndex["gyroADC[0]"], mainFrameDef.nameToIndex["gyroADC[1]"], mainFrameDef.nameToIndex["gyroADC[2]"]],
8283
accSmooth = [mainFrameDef.nameToIndex["accSmooth[0]"], mainFrameDef.nameToIndex["accSmooth[1]"], mainFrameDef.nameToIndex["accSmooth[2]"]],
8384
magADC = [mainFrameDef.nameToIndex["magADC[0]"], mainFrameDef.nameToIndex["magADC[1]"], mainFrameDef.nameToIndex["magADC[2]"]],
8485

8586
lastSlow = [],
86-
lastGPSHome = [];
87-
87+
lastGPSHome = [],
88+
lastGPS = [];
89+
8890
// Identify motor fields so they can be used to show the activity summary bar
8991
for (var j = 0; j < 8; j++) {
9092
if (mainFrameDef.nameToIndex["motor[" + j + "]"] !== undefined) {
@@ -139,6 +141,7 @@ function FlightLogIndex(logData) {
139141
intraIndex.initialIMU.push(new IMU(imu));
140142
intraIndex.initialSlow.push(lastSlow);
141143
intraIndex.initialGPSHome.push(lastGPSHome);
144+
intraIndex.initialGPS.push(lastGPS);
142145
}
143146

144147
iframeCount++;
@@ -153,6 +156,10 @@ function FlightLogIndex(logData) {
153156
magADC ? [frame[magADC[0]], frame[magADC[1]], frame[magADC[2]]] : false
154157
);
155158
break;
159+
case 'G':
160+
lastGPS = frame.slice(0);
161+
lastGPS.shift(); // Remove the time field
162+
break;
156163
case 'H':
157164
lastGPSHome = frame.slice(0);
158165
break;

js/graph_config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,27 @@ GraphConfig.load = function(config) {
353353
inputRange: 512,
354354
outputRange: 1.0
355355
};
356+
} else if (fieldName == 'GPS_ground_course') {
357+
return {
358+
offset: -1800,
359+
power: 1.0,
360+
inputRange: 1800,
361+
outputRange: 1.0
362+
};
363+
} else if (fieldName == 'GPS_numSat') {
364+
return {
365+
offset: -20,
366+
power: 1.0,
367+
inputRange: 20,
368+
outputRange: 1.0
369+
};
370+
} else if (fieldName == 'GPS_speed') {
371+
return {
372+
offset: 0,
373+
power: 1.0,
374+
inputRange: 1000,
375+
outputRange: 1.0
376+
};
356377
} else if (fieldName.match(/^debug.*/) && sysConfig.debug_mode!=null) {
357378

358379
var debugModeName = DEBUG_MODE[sysConfig.debug_mode];
@@ -956,6 +977,10 @@ GraphConfig.load = function(config) {
956977
EXAMPLE_GRAPHS.push({label: "Debug",fields: ["debug[all]"]});
957978
}
958979

980+
if (!flightLog.isFieldDisabled().GPS) {
981+
EXAMPLE_GRAPHS.push({label: "GPS",fields: ["GPS_numSat", "GPS_altitude", "GPS_speed", "GPS_ground_course", "GPS_coord[all]"]});
982+
}
983+
959984
for (i = 0; i < EXAMPLE_GRAPHS.length; i++) {
960985
var
961986
srcGraph = EXAMPLE_GRAPHS[i],

js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function BlackboxLogViewer() {
166166

167167
if (value === null)
168168
return "(absent)";
169-
169+
170170
return value.toFixed(2);
171171
}
172172

0 commit comments

Comments
 (0)