-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add 5s and 10s average of ampere to help calibrate ampere sensor. #4656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,10 @@ const motors = { | |
| sensorGyroScale: 2000, | ||
| sensorAccelRate: 20, | ||
| sensorAccelScale: 2, | ||
| amperageHistory5s: [], // Store last 5 seconds of amperage readings for average calculation | ||
| amperageHistorySize5s: 20, // Number of readings to keep for 5 seconds average (4Hz * 5s = 20) | ||
| amperageHistory10s: [], // Store last 10 seconds of amperage readings for average calculation | ||
| amperageHistorySize10s: 40, // Number of readings to keep for 10 seconds average (4Hz * 10s = 40) | ||
| sensorSelectValues: { | ||
| gyroScale: { | ||
| 1: 1, | ||
|
|
@@ -77,6 +81,10 @@ motors.initialize = async function (callback) { | |
| self.configHasChanged = false; | ||
| self.configChanges = {}; | ||
|
|
||
| // Reset amperage history when initializing | ||
| self.amperageHistory5s = []; | ||
| self.amperageHistory10s = []; | ||
|
|
||
| // Update filtering defaults based on API version | ||
| const FILTER_DEFAULT = FC.getFilterDefaults(); | ||
|
|
||
|
|
@@ -463,6 +471,8 @@ motors.initialize = async function (callback) { | |
| const motorVoltage = $(".motors-bat-voltage"); | ||
| const motorMahDrawingElement = $(".motors-bat-mah-drawing"); | ||
| const motorMahDrawnElement = $(".motors-bat-mah-drawn"); | ||
| const motorAmperageAverage5sElement = $(".motors-bat-amperage-average-5s"); | ||
| const motorAmperageAverage10sElement = $(".motors-bat-amperage-average-10s"); | ||
|
|
||
| const rawDataTextElements = { | ||
| x: [], | ||
|
|
@@ -639,6 +649,33 @@ motors.initialize = async function (callback) { | |
| motorVoltage.text(i18n.getMessage("motorsVoltageValue", [FC.ANALOG.voltage])); | ||
| motorMahDrawingElement.text(i18n.getMessage("motorsADrawingValue", [FC.ANALOG.amperage.toFixed(2)])); | ||
| motorMahDrawnElement.text(i18n.getMessage("motorsmAhDrawnValue", [FC.ANALOG.mAhdrawn])); | ||
|
|
||
| // Calculate amperage averages | ||
| const currentAmperage = FC.ANALOG.amperage; | ||
|
|
||
| // 5 seconds average | ||
| TABS.motors.amperageHistory5s.push(currentAmperage); | ||
| if (TABS.motors.amperageHistory5s.length > TABS.motors.amperageHistorySize5s) { | ||
| TABS.motors.amperageHistory5s.shift(); | ||
| } | ||
| const amperageSum5s = TABS.motors.amperageHistory5s.reduce((sum, value) => sum + value, 0); | ||
| const amperageAverage5s = amperageSum5s / TABS.motors.amperageHistory5s.length; | ||
|
|
||
| // 10 seconds average | ||
| TABS.motors.amperageHistory10s.push(currentAmperage); | ||
|
||
| if (TABS.motors.amperageHistory10s.length > TABS.motors.amperageHistorySize10s) { | ||
| TABS.motors.amperageHistory10s.shift(); | ||
| } | ||
| const amperageSum10s = TABS.motors.amperageHistory10s.reduce((sum, value) => sum + value, 0); | ||
| const amperageAverage10s = amperageSum10s / TABS.motors.amperageHistory10s.length; | ||
derekhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Display average amperages | ||
| motorAmperageAverage5sElement.text( | ||
| i18n.getMessage("motorsAmperageAverage5sValue", [amperageAverage5s.toFixed(2)]), | ||
| ); | ||
| motorAmperageAverage10sElement.text( | ||
| i18n.getMessage("motorsAmperageAverage10sValue", [amperageAverage10s.toFixed(2)]), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,11 +11,19 @@ import { initializeModalDialog } from "../utils/initializeModalDialog"; | |||||||||||||||||||||||||||||||||||
| const power = { | ||||||||||||||||||||||||||||||||||||
| supported: false, | ||||||||||||||||||||||||||||||||||||
| analyticsChanges: {}, | ||||||||||||||||||||||||||||||||||||
| amperageHistory5s: [], // Store last 5 seconds of amperage readings for average calculation | ||||||||||||||||||||||||||||||||||||
| amperageHistorySize5s: 25, // Number of readings to keep for 5 seconds average (5Hz * 5s = 25) | ||||||||||||||||||||||||||||||||||||
| amperageHistory10s: [], // Store last 10 seconds of amperage readings for average calculation | ||||||||||||||||||||||||||||||||||||
| amperageHistorySize10s: 50, // Number of readings to keep for 10 seconds average (5Hz * 10s = 50) | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
11
to
+17
|
||||||||||||||||||||||||||||||||||||
| const power = { | |
| supported: false, | |
| analyticsChanges: {}, | |
| amperageHistory5s: [], // Store last 5 seconds of amperage readings for average calculation | |
| amperageHistorySize5s: 25, // Number of readings to keep for 5 seconds average (5Hz * 5s = 25) | |
| amperageHistory10s: [], // Store last 10 seconds of amperage readings for average calculation | |
| amperageHistorySize10s: 50, // Number of readings to keep for 10 seconds average (5Hz * 10s = 50) | |
| // Configurable update rate in Hz (readings per second). Change this value if hardware/configuration differs. | |
| const updateRateHz = 5; | |
| const power = { | |
| supported: false, | |
| analyticsChanges: {}, | |
| amperageHistory5s: [], // Store last 5 seconds of amperage readings for average calculation | |
| amperageHistorySize5s: updateRateHz * 5, // Number of readings to keep for 5 seconds average (updateRateHz * 5s) | |
| amperageHistory10s: [], // Store last 10 seconds of amperage readings for average calculation | |
| amperageHistorySize10s: updateRateHz * 10, // Number of readings to keep for 10 seconds average (updateRateHz * 10s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motors tab uses different update rate assumptions (4Hz) compared to the power tab (5Hz). This inconsistency could lead to different averaging behaviors between tabs and should be standardized.