Skip to content

Commit fcbcdfb

Browse files
author
Felix Remmel
committed
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.
1 parent 5214d22 commit fcbcdfb

File tree

3 files changed

+327
-22
lines changed

3 files changed

+327
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.openems.edge.ess.api;
2+
3+
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
4+
import io.openems.common.function.ThrowingBiConsumer;
5+
import io.openems.edge.ess.power.api.Phase;
6+
import io.openems.edge.ess.power.api.Pwr;
7+
8+
public final class ActivePowerConstraintWithPid implements ThrowingBiConsumer<ManagedSymmetricEss, Integer, OpenemsNamedException> {
9+
10+
@Override
11+
public void accept(ManagedSymmetricEss ess, Integer value) throws OpenemsNamedException {
12+
if (value != null) {
13+
var power = ess.getPower();
14+
var pidFilter = power.getPidFilter();
15+
16+
// configure PID filter
17+
var minPower = power.getMinPower(ess, Phase.ALL, Pwr.ACTIVE);
18+
var maxPower = power.getMaxPower(ess, Phase.ALL, Pwr.ACTIVE);
19+
if (maxPower < minPower) {
20+
maxPower = minPower; // avoid rounding error
21+
}
22+
23+
int currentActivePower = ess.getActivePower().orElse(0);
24+
25+
if (value <= 0 && currentActivePower <= 0 && minPower < 0 && maxPower > 0) {
26+
// Prevent PID filter to overshoot and flicker from charging to discharging
27+
pidFilter.setLimits(minPower, 0);
28+
} else if (value >= 0 && currentActivePower >= 0 && minPower < 0 && maxPower > 0) {
29+
pidFilter.setLimits(0, maxPower);
30+
} else {
31+
// changing between charging/discharging is intended behavior, so we allow it.
32+
pidFilter.setLimits(minPower, maxPower);
33+
}
34+
35+
var pidOutput = pidFilter.applyPidFilter(currentActivePower, value);
36+
37+
ess.setActivePowerEquals(pidOutput);
38+
}
39+
}
40+
}

io.openems.edge.ess.api/src/io/openems/edge/ess/api/ManagedSymmetricEss.java

+1-22
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,7 @@ public enum ChannelId implements io.openems.edge.common.channel.ChannelId {
8585
.unit(Unit.WATT) //
8686
.accessMode(AccessMode.WRITE_ONLY) //
8787
.onChannelSetNextWrite(
88-
new PowerConstraint("SetActivePowerEqualsWithPid", Phase.ALL, Pwr.ACTIVE, Relationship.EQUALS) {
89-
@Override
90-
public void accept(ManagedSymmetricEss ess, Integer value) throws OpenemsNamedException {
91-
if (value != null) {
92-
var power = ess.getPower();
93-
var pidFilter = power.getPidFilter();
94-
95-
// configure PID filter
96-
var minPower = power.getMinPower(ess, Phase.ALL, Pwr.ACTIVE);
97-
var maxPower = power.getMaxPower(ess, Phase.ALL, Pwr.ACTIVE);
98-
if (maxPower < minPower) {
99-
maxPower = minPower; // avoid rounding error
100-
}
101-
pidFilter.setLimits(minPower, maxPower);
102-
103-
int currentActivePower = ess.getActivePower().orElse(0);
104-
var pidOutput = pidFilter.applyPidFilter(currentActivePower, value);
105-
106-
ess.setActivePowerEquals(pidOutput);
107-
}
108-
}
109-
})),
88+
new ActivePowerConstraintWithPid())),
11089
/**
11190
* Sets a fixed Reactive Power.
11291
*

0 commit comments

Comments
 (0)