Skip to content

Commit

Permalink
ESS Generic: improve handling of force charge/discharge corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeilmeier committed Jan 29, 2021
1 parent c9e9e08 commit 81dcb84
Showing 1 changed file with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,55 @@ public void activate(Battery battery, ManagedSymmetricBatteryInverter batteryInv
float allowedChargePower;
float allowedDischargePower;

// If the GenericEss is not in State "STARTED" block ACTIVE and REACTIVE Power!
if (this.parent.isStarted() && voltage.isDefined() && dischargeMaxCurrent.isDefined()
&& chargeMaxCurrent.isDefined()) {
/*
* Calculate initial AllowedChargePower and AllowedDischargePower
*/
if (!this.parent.isStarted()) {
// If the GenericEss is not in State "STARTED" block ACTIVE and REACTIVE Power!
allowedChargePower = 0;
allowedDischargePower = 0;

} else {
// Calculate AllowedChargePower and AllowedDischargePower from battery current
// limits and voltage
// efficiency factor is not considered in chargeMaxCurrent (DC Power > AC Power)
allowedChargePower = chargeMaxCurrent.get() * voltage.get() * -1;
allowedDischargePower = dischargeMaxCurrent.get() * voltage.get() * efficiencyFactor;

} else {
allowedChargePower = 0;
allowedDischargePower = 0;
}

// Allow max increase of 1 %
if (allowedDischargePower > lastAllowedDischargePower + allowedDischargePower * 0.01F) {
allowedDischargePower = lastAllowedDischargePower + allowedDischargePower * 0.01F;
/*
* Allow max increase of 1 % per Cycle
*/
if (allowedChargePower < 0 && this.lastAllowedChargePower < 0) {
allowedChargePower = Math.max(allowedChargePower, this.lastAllowedChargePower * 1.01F);
}
ChannelManager.this.lastAllowedDischargePower = allowedDischargePower;
this.lastAllowedChargePower = allowedChargePower;

if (allowedChargePower < lastAllowedChargePower + allowedChargePower * 0.01F) {
allowedChargePower = lastAllowedChargePower + allowedChargePower * 0.01F;
if (allowedDischargePower > 0 && this.lastAllowedDischargePower > 0) {
allowedDischargePower = Math.min(allowedDischargePower, this.lastAllowedDischargePower * 1.01F);
}
ChannelManager.this.lastAllowedChargePower = allowedChargePower;
this.lastAllowedDischargePower = allowedDischargePower;

// Make sure solution is feasible
if (allowedChargePower > allowedDischargePower) { // Force Discharge
allowedDischargePower = allowedChargePower;
}
if (allowedDischargePower < allowedChargePower) { // Force Charge
allowedChargePower = allowedDischargePower;
/*
* Handle Force Charge and Discharge
*/
if (allowedChargePower > 0 && allowedDischargePower < 0) {
// Both Force Charge and Discharge are active -> cannot do anything
allowedChargePower = 0;
allowedDischargePower = 0;

} else if (allowedDischargePower < 0) {
// Force Charge is active
// Make sure AllowedChargePower is less-or-equals AllowedDischargePower
allowedChargePower = Math.min(allowedChargePower, allowedDischargePower);

} else if (allowedChargePower > 0) {
// Force Discharge is active
// Make sure AllowedDischargePower is greater-or-equals AllowedChargePower
allowedDischargePower = Math.max(allowedChargePower, allowedDischargePower);
}

// Apply AllowedChargePower and AllowedDischargePower
this.parent._setAllowedChargePower(Math.round(allowedChargePower));
this.parent._setAllowedDischargePower(Math.round(allowedDischargePower));
};
Expand Down

0 comments on commit 81dcb84

Please sign in to comment.