-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Avoid flickering between charge/discharge due to PID filter
Before this change the PID filter implementation eventually caused the behavior to switch from charging to discharing, eventhough the system wanted to (a) charge with a lower value than before (b) set active power to 0. This was due to the fact, that the PID filter overshoots its target. By detecting if the system wants charge/discharge/no current flow the battery, it now dynamically adjusts the limits of the battery so it does not overshoot in the unwanted area. This reduces stress on the battery. It also improves the controller that are using this filter (e.g. self consumption optimization, peak load shaving). Sometimes they showed behavior where they wildly flicker between charging/discharging.
- Loading branch information
Felix Remmel
committed
Jan 8, 2025
1 parent
5214d22
commit b477aca
Showing
3 changed files
with
328 additions
and
22 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
io.openems.edge.ess.api/src/io/openems/edge/ess/api/ActivePowerConstraintWithPid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.openems.edge.ess.api; | ||
|
||
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException; | ||
import io.openems.common.function.ThrowingBiConsumer; | ||
import io.openems.edge.ess.power.api.Phase; | ||
import io.openems.edge.ess.power.api.Pwr; | ||
|
||
public final class ActivePowerConstraintWithPid implements ThrowingBiConsumer<ManagedSymmetricEss, Integer, OpenemsNamedException> { | ||
|
||
@Override | ||
public void accept(ManagedSymmetricEss ess, Integer value) throws OpenemsNamedException { | ||
if (value != null) { | ||
var power = ess.getPower(); | ||
var pidFilter = power.getPidFilter(); | ||
|
||
// configure PID filter | ||
var minPower = power.getMinPower(ess, Phase.ALL, Pwr.ACTIVE); | ||
var maxPower = power.getMaxPower(ess, Phase.ALL, Pwr.ACTIVE); | ||
if (maxPower < minPower) { | ||
maxPower = minPower; // avoid rounding error | ||
} | ||
|
||
int currentActivePower = ess.getActivePower().orElse(0); | ||
|
||
if (value <= 0 && currentActivePower <= 0 && minPower < 0 && maxPower > 0) { | ||
// Prevent PID filter to overshoot and flicker from charging to discharging | ||
pidFilter.setLimits(minPower, 0); | ||
} else if (value >= 0 && currentActivePower >= 0 && minPower < 0 && maxPower > 0) { | ||
pidFilter.setLimits(0, maxPower); | ||
} else { | ||
// changing between charging/discharging is intended behavior, so we allow it. | ||
pidFilter.setLimits(minPower, maxPower); | ||
} | ||
|
||
var pidOutput = pidFilter.applyPidFilter(currentActivePower, value); | ||
|
||
ess.setActivePowerEquals(pidOutput); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.