99 * Additional computed fields are derived from the original data set and added as new fields in the resulting data.
1010 * Window based smoothing of fields is offered.
1111 */
12- function FlightLog ( logData ) {
12+ function FlightLog ( logData , newSettings ) {
1313 var
14- ADDITIONAL_COMPUTED_FIELD_COUNT = 6 , /** attitude + PID_SUM **/
14+ ADDITIONAL_COMPUTED_FIELD_COUNT = 15 , /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GYROADC_SCALED **/
1515
1616 that = this ,
1717 logIndex = false ,
@@ -33,10 +33,13 @@ function FlightLog(logData) {
3333 maxSmoothing = 0 ,
3434
3535 smoothedCache = new FIFOCache ( 2 ) ;
36+
3637
3738 //Public fields:
3839 this . parser = parser ;
3940
41+ this . settings = newSettings ;
42+
4043 this . getMainFieldCount = function ( ) {
4144 return fieldNames . length ;
4245 } ;
@@ -199,6 +202,9 @@ function FlightLog(logData) {
199202 // Add names for our ADDITIONAL_COMPUTED_FIELDS
200203 fieldNames . push ( "heading[0]" , "heading[1]" , "heading[2]" ) ;
201204 fieldNames . push ( "axisSum[0]" , "axisSum[1]" , "axisSum[2]" ) ;
205+ fieldNames . push ( "axisError[0]" , "axisError[1]" , "axisError[2]" ) ; // Custom calculated error field
206+ fieldNames . push ( "rcCommands[0]" , "rcCommands[1]" , "rcCommands[2]" ) ; // Custom calculated error field
207+ fieldNames . push ( "gyroADCs[0]" , "gyroADCs[1]" , "gyroADCs[2]" ) ; // Custom calculated error field
202208
203209 fieldNameToIndex = { } ;
204210 for ( i = 0 ; i < fieldNames . length ; i ++ ) {
@@ -469,7 +475,8 @@ function FlightLog(logData) {
469475 gyroADC = [ fieldNameToIndex [ "gyroADC[0]" ] , fieldNameToIndex [ "gyroADC[1]" ] , fieldNameToIndex [ "gyroADC[2]" ] ] ,
470476 accSmooth = [ fieldNameToIndex [ "accSmooth[0]" ] , fieldNameToIndex [ "accSmooth[1]" ] , fieldNameToIndex [ "accSmooth[2]" ] ] ,
471477 magADC = [ fieldNameToIndex [ "magADC[0]" ] , fieldNameToIndex [ "magADC[1]" ] , fieldNameToIndex [ "magADC[2]" ] ] ,
472-
478+ rcCommand = [ fieldNameToIndex [ "rcCommand[0]" ] , fieldNameToIndex [ "rcCommand[1]" ] , fieldNameToIndex [ "rcCommand[2]" ] ] ,
479+
473480 sourceChunkIndex , destChunkIndex ,
474481
475482 sysConfig ,
@@ -534,6 +541,25 @@ function FlightLog(logData) {
534541 ( axisPID [ axis ] [ 1 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 1 ] ] : 0 ) +
535542 ( axisPID [ axis ] [ 2 ] !== undefined ? srcFrame [ axisPID [ axis ] [ 2 ] ] : 0 ) ;
536543 }
544+
545+ // Calculate the PID Error
546+ for ( var axis = 0 ; axis < 3 ; axis ++ ) {
547+ destFrame [ fieldIndex ++ ] =
548+ ( gyroADC [ axis ] !== undefined ? that . gyroRawToDegreesPerSecond ( srcFrame [ gyroADC [ axis ] ] ) : 0 ) -
549+ ( rcCommand [ axis ] !== undefined ? that . rcCommandRawToDegreesPerSecond ( srcFrame [ rcCommand [ axis ] ] , axis ) : 0 ) ;
550+ }
551+ // Calculate the Scaled rcCommand (in deg/s)
552+ for ( var axis = 0 ; axis < 3 ; axis ++ ) {
553+ destFrame [ fieldIndex ++ ] =
554+ ( rcCommand [ axis ] !== undefined ? that . rcCommandRawToDegreesPerSecond ( srcFrame [ rcCommand [ axis ] ] , axis ) : 0 ) ;
555+ }
556+
557+ // Calculate the scaled Gyro ADC
558+ for ( var axis = 0 ; axis < 3 ; axis ++ ) {
559+ destFrame [ fieldIndex ++ ] =
560+ ( gyroADC [ axis ] !== undefined ? that . gyroRawToDegreesPerSecond ( srcFrame [ gyroADC [ axis ] ] ) : 0 ) ;
561+ }
562+
537563 }
538564 }
539565 }
@@ -881,6 +907,28 @@ FlightLog.prototype.gyroRawToDegreesPerSecond = function(value) {
881907 return this . getSysConfig ( ) . gyroScale * 1000000 / ( Math . PI / 180.0 ) * value ;
882908} ;
883909
910+ // Convert rcCommand to degrees per second
911+ FlightLog . prototype . rcCommandRawToDegreesPerSecond = function ( value , axis ) {
912+
913+ // Axis 0,1 refers to Roll and Pitch
914+ // Axis 2 refers to Yaw.
915+
916+ // ReWrite or LUXFloat only
917+
918+
919+ // if(axis==2 /*YAW*/) {
920+ // return ((this.settings[0].parameters[axis].value + 47) * value ) >> 7;
921+ // } else { /*ROLL or PITCH */
922+ // return ((this.settings[0].parameters[axis].value + 27) * value ) >> 6;
923+ // }
924+
925+ if ( axis == 2 /*YAW*/ ) {
926+ return ( ( this . getSysConfig ( ) . yRate + 47 ) * value ) >> 7 ;
927+ } else { /*ROLL or PITCH */
928+ return ( ( ( ( axis == 0 ) ?this . getSysConfig ( ) . rRate :this . getSysConfig ( ) . pRate ) + 27 ) * value ) >> 6 ;
929+ }
930+ } ;
931+
884932FlightLog . prototype . getReferenceVoltageMillivolts = function ( ) {
885933 return this . vbatADCToMillivolts ( this . getSysConfig ( ) . vbatref ) ;
886934} ;
0 commit comments