Skip to content
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

fix(core): Avoid flickering between charge/discharge due to PID filter #2960

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,7 @@ public enum ChannelId implements io.openems.edge.common.channel.ChannelId {
.unit(Unit.WATT) //
.accessMode(AccessMode.WRITE_ONLY) //
.onChannelSetNextWrite(
new PowerConstraint("SetActivePowerEqualsWithPid", Phase.ALL, Pwr.ACTIVE, Relationship.EQUALS) {
@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
}
pidFilter.setLimits(minPower, maxPower);

int currentActivePower = ess.getActivePower().orElse(0);
var pidOutput = pidFilter.applyPidFilter(currentActivePower, value);

ess.setActivePowerEquals(pidOutput);
}
}
})),
new ActivePowerConstraintWithPid())),
/**
* Sets a fixed Reactive Power.
*
Expand Down
Loading
Loading