@@ -199,6 +199,7 @@ function FlightLog(logData) {
199
199
// Add names for our ADDITIONAL_COMPUTED_FIELDS
200
200
fieldNames . push ( "heading[0]" , "heading[1]" , "heading[2]" ) ;
201
201
fieldNames . push ( "axisSum[0]" , "axisSum[1]" , "axisSum[2]" ) ;
202
+ fieldNames . push ( "axisError[0]" , "axisError[1]" , "axisError[2]" ) ; // Custom calculated error field
202
203
203
204
fieldNameToIndex = { } ;
204
205
for ( i = 0 ; i < fieldNames . length ; i ++ ) {
@@ -469,7 +470,8 @@ function FlightLog(logData) {
469
470
gyroADC = [ fieldNameToIndex [ "gyroADC[0]" ] , fieldNameToIndex [ "gyroADC[1]" ] , fieldNameToIndex [ "gyroADC[2]" ] ] ,
470
471
accSmooth = [ fieldNameToIndex [ "accSmooth[0]" ] , fieldNameToIndex [ "accSmooth[1]" ] , fieldNameToIndex [ "accSmooth[2]" ] ] ,
471
472
magADC = [ fieldNameToIndex [ "magADC[0]" ] , fieldNameToIndex [ "magADC[1]" ] , fieldNameToIndex [ "magADC[2]" ] ] ,
472
-
473
+ rcCommand = [ fieldNameToIndex [ "rcCommand[0]" ] , fieldNameToIndex [ "rcCommand[1]" ] , fieldNameToIndex [ "rcCommand[2]" ] ] ,
474
+
473
475
sourceChunkIndex , destChunkIndex ,
474
476
475
477
sysConfig ,
@@ -534,6 +536,15 @@ function FlightLog(logData) {
534
536
( axisPID [ axis ] [ 1 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 1 ] ] : 0 ) +
535
537
( axisPID [ axis ] [ 2 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 2 ] ] : 0 ) ;
536
538
}
539
+
540
+ // Calculate the PID Error
541
+ for ( var axis = 0 ; axis < 3 ; axis ++ ) {
542
+ destFrame [ fieldIndex ++ ] =
543
+ ( gyroADC [ axis ] !== undefined ? that . gyroRawToDegreesPerSecond ( srcFrame [ gyroADC [ axis ] ] ) : 0 ) -
544
+ ( rcCommand [ axis ] !== undefined ? that . rcCommandRawToDegreesPerSecond ( srcFrame [ rcCommand [ axis ] ] , axis ) : 0 ) ;
545
+ console . log ( )
546
+ }
547
+
537
548
}
538
549
}
539
550
}
@@ -881,6 +892,43 @@ FlightLog.prototype.gyroRawToDegreesPerSecond = function(value) {
881
892
return this . getSysConfig ( ) . gyroScale * 1000000 / ( Math . PI / 180.0 ) * value ;
882
893
} ;
883
894
895
+ // Convert rcCommand to degrees per second
896
+ FlightLog . prototype . rcCommandRawToDegreesPerSecond = function ( value , axis ) {
897
+
898
+ // Axis 0,1 refers to Roll and Pitch
899
+ // Axis 2 refers to Yaw.
900
+
901
+ var rRate = 65 ; // Roll Rate from configuration
902
+ var pRate = 65 ; // Pitch Rate from configuration
903
+ var yRate = 65 ; // Yaw Rate from configuration
904
+
905
+ var REWRITE = true ; // Define that this is for the Rewrite Data - need to make dynamic!
906
+
907
+ if ( REWRITE ) // PID is ReWrite
908
+ {
909
+ if ( axis == 0 /*ROLL*/ ) {
910
+ return ( ( rRate + 27 ) * value ) >> 6 ;
911
+ }
912
+ if ( axis == 1 /*PITCH*/ ) {
913
+ return ( ( pRate + 27 ) * value ) >> 6 ;
914
+ }
915
+ if ( axis == 2 /*YAW*/ ) {
916
+ return ( ( yRate + 27 ) * value ) >> 7 ;
917
+ }
918
+ } else { // PID is Luxfloat
919
+ if ( axis == 0 /*ROLL*/ ) {
920
+ return ( ( rRate + 20 ) * value ) / 50 ;
921
+ }
922
+ if ( axis == 1 /*PITCH*/ ) {
923
+ return ( ( pRate + 20 ) * value ) / 50 ;
924
+ }
925
+ if ( axis == 2 /*YAW*/ ) {
926
+ return ( ( yRate + 10 ) * value ) / 50 ;
927
+ }
928
+ }
929
+ } ;
930
+
931
+
884
932
FlightLog . prototype . getReferenceVoltageMillivolts = function ( ) {
885
933
return this . vbatADCToMillivolts ( this . getSysConfig ( ) . vbatref ) ;
886
934
} ;
0 commit comments