@@ -33,6 +33,10 @@ const motors = {
3333 sensorGyroScale : 2000 ,
3434 sensorAccelRate : 20 ,
3535 sensorAccelScale : 2 ,
36+ amperageHistory5s : [ ] , // Store last 5 seconds of amperage readings for average calculation
37+ amperageHistorySize5s : 20 , // Number of readings to keep for 5 seconds average (4Hz * 5s = 20)
38+ amperageHistory10s : [ ] , // Store last 10 seconds of amperage readings for average calculation
39+ amperageHistorySize10s : 40 , // Number of readings to keep for 10 seconds average (4Hz * 10s = 40)
3640 sensorSelectValues : {
3741 gyroScale : {
3842 1 : 1 ,
@@ -77,6 +81,10 @@ motors.initialize = async function (callback) {
7781 self . configHasChanged = false ;
7882 self . configChanges = { } ;
7983
84+ // Reset amperage history when initializing
85+ self . amperageHistory5s = [ ] ;
86+ self . amperageHistory10s = [ ] ;
87+
8088 // Update filtering defaults based on API version
8189 const FILTER_DEFAULT = FC . getFilterDefaults ( ) ;
8290
@@ -463,6 +471,8 @@ motors.initialize = async function (callback) {
463471 const motorVoltage = $ ( ".motors-bat-voltage" ) ;
464472 const motorMahDrawingElement = $ ( ".motors-bat-mah-drawing" ) ;
465473 const motorMahDrawnElement = $ ( ".motors-bat-mah-drawn" ) ;
474+ const motorAmperageAverage5sElement = $ ( ".motors-bat-amperage-average-5s" ) ;
475+ const motorAmperageAverage10sElement = $ ( ".motors-bat-amperage-average-10s" ) ;
466476
467477 const rawDataTextElements = {
468478 x : [ ] ,
@@ -639,6 +649,33 @@ motors.initialize = async function (callback) {
639649 motorVoltage . text ( i18n . getMessage ( "motorsVoltageValue" , [ FC . ANALOG . voltage ] ) ) ;
640650 motorMahDrawingElement . text ( i18n . getMessage ( "motorsADrawingValue" , [ FC . ANALOG . amperage . toFixed ( 2 ) ] ) ) ;
641651 motorMahDrawnElement . text ( i18n . getMessage ( "motorsmAhDrawnValue" , [ FC . ANALOG . mAhdrawn ] ) ) ;
652+
653+ // Calculate amperage averages
654+ const currentAmperage = FC . ANALOG . amperage ;
655+
656+ // 5 seconds average
657+ TABS . motors . amperageHistory5s . push ( currentAmperage ) ;
658+ if ( TABS . motors . amperageHistory5s . length > TABS . motors . amperageHistorySize5s ) {
659+ TABS . motors . amperageHistory5s . shift ( ) ;
660+ }
661+ const amperageSum5s = TABS . motors . amperageHistory5s . reduce ( ( sum , value ) => sum + value , 0 ) ;
662+ const amperageAverage5s = amperageSum5s / TABS . motors . amperageHistory5s . length ;
663+
664+ // 10 seconds average
665+ TABS . motors . amperageHistory10s . push ( currentAmperage ) ;
666+ if ( TABS . motors . amperageHistory10s . length > TABS . motors . amperageHistorySize10s ) {
667+ TABS . motors . amperageHistory10s . shift ( ) ;
668+ }
669+ const amperageSum10s = TABS . motors . amperageHistory10s . reduce ( ( sum , value ) => sum + value , 0 ) ;
670+ const amperageAverage10s = amperageSum10s / TABS . motors . amperageHistory10s . length ;
671+
672+ // Display average amperages
673+ motorAmperageAverage5sElement . text (
674+ i18n . getMessage ( "motorsAmperageAverage5sValue" , [ amperageAverage5s . toFixed ( 2 ) ] ) ,
675+ ) ;
676+ motorAmperageAverage10sElement . text (
677+ i18n . getMessage ( "motorsAmperageAverage10sValue" , [ amperageAverage10s . toFixed ( 2 ) ] ) ,
678+ ) ;
642679 }
643680 }
644681
0 commit comments