@@ -209,27 +209,34 @@ function FlightLog(logData) {
209
209
} ;
210
210
211
211
function buildFieldNames ( ) {
212
- var
213
- i ;
212
+ const disabledFields = that . getSysConfig ( ) . fields_disabled_mask ;
214
213
215
214
// Make an independent copy
216
215
fieldNames = parser . frameDefs . I . name . slice ( 0 ) ;
217
216
218
217
// Add names of slow fields which we'll merge into the main stream
219
218
if ( parser . frameDefs . S ) {
220
- for ( i = 0 ; i < parser . frameDefs . S . name . length ; i ++ ) {
219
+ for ( let i = 0 ; i < parser . frameDefs . S . name . length ; i ++ ) {
221
220
fieldNames . push ( parser . frameDefs . S . name [ i ] ) ;
222
221
}
223
222
}
224
223
225
224
// Add names for our ADDITIONAL_COMPUTED_FIELDS
226
- fieldNames . push ( "heading[0]" , "heading[1]" , "heading[2]" ) ;
227
- fieldNames . push ( "axisSum[0]" , "axisSum[1]" , "axisSum[2]" ) ;
228
- fieldNames . push ( "rcCommands[0]" , "rcCommands[1]" , "rcCommands[2]" , "rcCommands[3]" ) ; // Custom calculated scaled rccommand
229
- fieldNames . push ( "axisError[0]" , "axisError[1]" , "axisError[2]" ) ; // Custom calculated error field
225
+ if ( ! ( disabledFields & 1 << 7 ) ) { //if GYRO disabled
226
+ fieldNames . push ( "heading[0]" , "heading[1]" , "heading[2]" ) ;
227
+ }
228
+ if ( ! ( disabledFields & 1 << 0 ) ) { //if PID disabled
229
+ fieldNames . push ( "axisSum[0]" , "axisSum[1]" , "axisSum[2]" ) ;
230
+ }
231
+ if ( ! ( disabledFields & 1 << 2 ) ) { //if setpoint disabled
232
+ fieldNames . push ( "rcCommands[0]" , "rcCommands[1]" , "rcCommands[2]" , "rcCommands[3]" ) ; // Custom calculated scaled rccommand
233
+ }
234
+ if ( ! ( ( disabledFields & 1 << 7 ) || ( disabledFields & 1 << 0 ) ) ) { //if GYRO or PID disabled
235
+ fieldNames . push ( "axisError[0]" , "axisError[1]" , "axisError[2]" ) ; // Custom calculated error field
236
+ }
230
237
231
238
fieldNameToIndex = { } ;
232
- for ( i = 0 ; i < fieldNames . length ; i ++ ) {
239
+ for ( let i = 0 ; i < fieldNames . length ; i ++ ) {
233
240
fieldNameToIndex [ fieldNames [ i ] ] = i ;
234
241
}
235
242
}
@@ -537,6 +544,26 @@ function FlightLog(logData) {
537
544
magADC = false ;
538
545
}
539
546
547
+ if ( ! gyroADC [ 0 ] ) {
548
+ gyroADC = false ;
549
+ }
550
+
551
+ if ( ! accSmooth [ 0 ] ) {
552
+ accSmooth = false ;
553
+ }
554
+
555
+ if ( ! rcCommand [ 0 ] ) {
556
+ rcCommand = false ;
557
+ }
558
+
559
+ if ( ! setpoint [ 0 ] ) {
560
+ setpoint = false ;
561
+ }
562
+
563
+ if ( ! axisPID [ 0 ] ) {
564
+ axisPID = false ;
565
+ }
566
+
540
567
sysConfig = that . getSysConfig ( ) ;
541
568
542
569
sourceChunkIndex = 0 ;
@@ -564,34 +591,38 @@ function FlightLog(logData) {
564
591
destFrame = destChunk . frames [ i ] ,
565
592
fieldIndex = destFrame . length - ADDITIONAL_COMPUTED_FIELD_COUNT ;
566
593
567
- attitude = chunkIMU . updateEstimatedAttitude (
568
- [ srcFrame [ gyroADC [ 0 ] ] , srcFrame [ gyroADC [ 1 ] ] , srcFrame [ gyroADC [ 2 ] ] ] ,
569
- [ srcFrame [ accSmooth [ 0 ] ] , srcFrame [ accSmooth [ 1 ] ] , srcFrame [ accSmooth [ 2 ] ] ] ,
570
- srcFrame [ FlightLogParser . prototype . FLIGHT_LOG_FIELD_INDEX_TIME ] ,
571
- sysConfig . acc_1G ,
572
- sysConfig . gyroScale ,
573
- magADC ? [ srcFrame [ magADC [ 0 ] ] , srcFrame [ magADC [ 1 ] ] , srcFrame [ magADC [ 2 ] ] ] : false ) ;
574
-
575
- destFrame [ fieldIndex ++ ] = attitude . roll ;
576
- destFrame [ fieldIndex ++ ] = attitude . pitch ;
577
- destFrame [ fieldIndex ++ ] = attitude . heading ;
594
+ if ( gyroADC ) { //don't calculate attitude if no gyro data
595
+ attitude = chunkIMU . updateEstimatedAttitude (
596
+ [ srcFrame [ gyroADC [ 0 ] ] , srcFrame [ gyroADC [ 1 ] ] , srcFrame [ gyroADC [ 2 ] ] ] ,
597
+ [ srcFrame [ accSmooth [ 0 ] ] , srcFrame [ accSmooth [ 1 ] ] , srcFrame [ accSmooth [ 2 ] ] ] ,
598
+ srcFrame [ FlightLogParser . prototype . FLIGHT_LOG_FIELD_INDEX_TIME ] ,
599
+ sysConfig . acc_1G ,
600
+ sysConfig . gyroScale ,
601
+ magADC ) ;
602
+
603
+ destFrame [ fieldIndex ++ ] = attitude . roll ;
604
+ destFrame [ fieldIndex ++ ] = attitude . pitch ;
605
+ destFrame [ fieldIndex ++ ] = attitude . heading ;
606
+ }
578
607
579
608
// Add the Feedforward PID sum (P+I+D+F)
580
- for ( var axis = 0 ; axis < 3 ; axis ++ ) {
581
- let pidSum =
582
- ( axisPID [ axis ] [ 0 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 0 ] ] : 0 ) +
583
- ( axisPID [ axis ] [ 1 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 1 ] ] : 0 ) +
584
- ( axisPID [ axis ] [ 2 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 2 ] ] : 0 ) +
585
- ( axisPID [ axis ] [ 3 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 3 ] ] : 0 ) ;
586
-
587
- // Limit the PID sum by the limits defined in the header
588
- let pidLimit = axis < AXIS . YAW ? sysConfig . pidSumLimit : sysConfig . pidSumLimitYaw ;
589
- if ( pidLimit != null && pidLimit > 0 ) {
590
- pidSum = constrain ( pidSum , - pidLimit , pidLimit ) ;
591
- }
609
+ if ( axisPID ) {
610
+ for ( var axis = 0 ; axis < 3 ; axis ++ ) {
611
+ let pidSum =
612
+ ( axisPID [ axis ] [ 0 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 0 ] ] : 0 ) +
613
+ ( axisPID [ axis ] [ 1 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 1 ] ] : 0 ) +
614
+ ( axisPID [ axis ] [ 2 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 2 ] ] : 0 ) +
615
+ ( axisPID [ axis ] [ 3 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 3 ] ] : 0 ) ;
616
+
617
+ // Limit the PID sum by the limits defined in the header
618
+ let pidLimit = axis < AXIS . YAW ? sysConfig . pidSumLimit : sysConfig . pidSumLimitYaw ;
619
+ if ( pidLimit != null && pidLimit > 0 ) {
620
+ pidSum = constrain ( pidSum , - pidLimit , pidLimit ) ;
621
+ }
592
622
593
- // Assign value
594
- destFrame [ fieldIndex ++ ] = pidSum ;
623
+ // Assign value
624
+ destFrame [ fieldIndex ++ ] = pidSum ;
625
+ }
595
626
}
596
627
597
628
// Check the current flightmode (we need to know this so that we can correctly calculate the rates)
@@ -622,9 +653,11 @@ function FlightLog(logData) {
622
653
}
623
654
624
655
// Calculate the PID Error
625
- for ( var axis = 0 ; axis < 3 ; axis ++ ) {
626
- let gyroADCdegrees = ( gyroADC [ axis ] !== undefined ? that . gyroRawToDegreesPerSecond ( srcFrame [ gyroADC [ axis ] ] ) : 0 ) ;
627
- destFrame [ fieldIndex ++ ] = gyroADCdegrees - destFrame [ fieldIndexRcCommands + axis ] ;
656
+ if ( axisPID && gyroADC ) {
657
+ for ( var axis = 0 ; axis < 3 ; axis ++ ) {
658
+ let gyroADCdegrees = ( gyroADC [ axis ] !== undefined ? that . gyroRawToDegreesPerSecond ( srcFrame [ gyroADC [ axis ] ] ) : 0 ) ;
659
+ destFrame [ fieldIndex ++ ] = gyroADCdegrees - destFrame [ fieldIndexRcCommands + axis ] ;
660
+ }
628
661
}
629
662
630
663
}
0 commit comments