Skip to content

Commit

Permalink
Fix bug in AC input power calculation
Browse files Browse the repository at this point in the history
Specific to AC inputs on Multi RS systems
  • Loading branch information
DanielMcInnes committed Jun 21, 2024
1 parent e1a56e0 commit f32da52
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
4 changes: 0 additions & 4 deletions data/common/AcInputPhaseModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Victron.VenusOS
ListModel {
id: root

signal phaseValueChanged(int phaseIndex, string propertyName, real propertyValue)

readonly property bool _feedbackEnabled: Global.systemSettings.essFeedbackToGridEnabled

property Instantiator _phaseObjects: Instantiator {
Expand All @@ -25,7 +23,6 @@ ListModel {
onClampedCurrentValueChanged: {
if (model.index >= 0 && model.index < root.count) {
setProperty(model.index, "current", clampedCurrentValue)
root.phaseValueChanged(model.index, "current", clampedCurrentValue)
}
}
}
Expand All @@ -39,7 +36,6 @@ ListModel {
onClampedPowerValueChanged: {
if (model.index >= 0 && model.index < root.count) {
setProperty(model.index, "power", clampedPowerValue)
root.phaseValueChanged(model.index, "power", clampedPowerValue)
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions data/common/AcInputServiceLoader.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ Loader {
property string serviceUid
property string serviceType

readonly property real totalPower: (!hasTotalPower || !item) ? NaN
: isNaN(_itemPower) ? NaN
: _feedbackEnabled ? _itemPower
: _itemPower > 0 ? _itemPower // see AcInputs.clampMeasurement()
: 0.0
readonly property bool hasTotalPower: serviceType === "vebus" || serviceType == "grid" || serviceType == "genset"

readonly property real currentLimit: !!item ? item.currentLimit : NaN
Expand All @@ -29,10 +24,6 @@ Loader {

readonly property bool _feedbackEnabled: Global.systemSettings.essFeedbackToGridEnabled

readonly property real _itemPower: !item ? 0.0
: item.power === undefined ? NaN
: item.power

sourceComponent: {
if (serviceUid == "" || serviceType == "") {
return null
Expand Down
28 changes: 12 additions & 16 deletions data/common/ActiveAcInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Device {
readonly property int source: !!inputInfo ? inputInfo.source : VenusOS.AcInputs_InputSource_NotAvailable
readonly property alias gensetStatusCode: _acInputService.gensetStatusCode

readonly property real power: _acInputService.hasTotalPower ? _acInputService.totalPower : _phases.totalPower
readonly property real power: _phases.totalPower
readonly property real current: phases.count === 1 ? _phases.firstPhaseCurrent : NaN // multi-phase systems don't have a total current
readonly property alias currentLimit: _acInputService.currentLimit
readonly property alias phases: _phases
Expand All @@ -27,23 +27,19 @@ Device {
readonly property AcInputPhaseModel _phases: AcInputPhaseModel {
id: _phases

property real totalPower: NaN
property real firstPhaseCurrent: NaN
property int totalPower
property real firstPhaseCurrent: count === 1 ? get(0).current : NaN

onPhaseValueChanged: function(phaseIndex, propertyName, propertyValue) {
if (propertyName === "power" && !root._acInputService.hasTotalPower) {
let total = NaN
for (let i = 0; i < phases.count; ++i) {
if (i === phaseIndex) {
total = Units.sumRealNumbers(total, propertyValue)
} else {
const phase = get(phaseIndex)
total = Units.sumRealNumbers(total, phase ? phase[propertyName] : NaN)
}
readonly property Timer _timer: Timer { // timer needed so the display doesn't update too frequently
interval: 1000
repeat: true
running: true
onTriggered: {
let sum = 0
for (let i = 0; i < _phases.count; ++i) {
sum += _phases.get(i).power || 0
}
totalPower = total
} else if (propertyName === "current" && count === 1) {
firstPhaseCurrent = propertyValue
_phases.totalPower = sum
}
}
}
Expand Down

0 comments on commit f32da52

Please sign in to comment.