Skip to content

Commit

Permalink
GoodWe: update calculation of DC and AC Power and Energy
Browse files Browse the repository at this point in the history
(cherry picked from commit c434ee3)
  • Loading branch information
sfeilmeier committed May 4, 2021
1 parent 671c937 commit 700b0e3
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
import io.openems.edge.batteryinverter.api.ManagedSymmetricBatteryInverter;
import io.openems.edge.batteryinverter.api.SymmetricBatteryInverter;
import io.openems.edge.bridge.modbus.api.BridgeModbus;
import io.openems.edge.common.channel.Channel;
import io.openems.edge.common.channel.IntegerWriteChannel;
import io.openems.edge.common.channel.value.Value;
import io.openems.edge.common.component.OpenemsComponent;
import io.openems.edge.common.startstop.StartStop;
import io.openems.edge.common.startstop.StartStoppable;
import io.openems.edge.common.type.TypeUtils;
import io.openems.edge.ess.api.HybridEss;
import io.openems.edge.ess.power.api.Phase;
import io.openems.edge.ess.power.api.Power;
import io.openems.edge.ess.power.api.Pwr;
Expand All @@ -37,8 +35,6 @@
import io.openems.edge.goodwe.common.ApplyPowerHandler;
import io.openems.edge.goodwe.common.GoodWe;
import io.openems.edge.timedata.api.Timedata;
import io.openems.edge.timedata.api.TimedataProvider;
import io.openems.edge.timedata.api.utils.CalculateEnergyFromPower;

@Designate(ocd = Config.class, factory = true)
@Component(//
Expand All @@ -48,7 +44,7 @@
) //
public class GoodWeBatteryInverterImpl extends AbstractGoodWe
implements GoodWeBatteryInverter, GoodWe, HybridManagedSymmetricBatteryInverter,
ManagedSymmetricBatteryInverter, SymmetricBatteryInverter, OpenemsComponent, TimedataProvider {
ManagedSymmetricBatteryInverter, SymmetricBatteryInverter, OpenemsComponent {

private static final int MAX_DC_CURRENT = 25; // [A]

Expand All @@ -61,15 +57,6 @@ public class GoodWeBatteryInverterImpl extends AbstractGoodWe
@Reference
private Power power;

private final CalculateEnergyFromPower calculateAcChargeEnergy = new CalculateEnergyFromPower(this,
SymmetricBatteryInverter.ChannelId.ACTIVE_CHARGE_ENERGY);
private final CalculateEnergyFromPower calculateAcDischargeEnergy = new CalculateEnergyFromPower(this,
SymmetricBatteryInverter.ChannelId.ACTIVE_DISCHARGE_ENERGY);
private final CalculateEnergyFromPower calculateDcChargeEnergy = new CalculateEnergyFromPower(this,
HybridEss.ChannelId.DC_CHARGE_ENERGY);
private final CalculateEnergyFromPower calculateDcDischargeEnergy = new CalculateEnergyFromPower(this,
HybridEss.ChannelId.DC_DISCHARGE_ENERGY);

// For Fenecon Home Battery, Lead Battery Capacity has to be set as a battery
// parameter
// TODO get from Battery
Expand Down Expand Up @@ -104,6 +91,12 @@ protected void deactivate() {

public GoodWeBatteryInverterImpl() throws OpenemsNamedException {
super(//
SymmetricBatteryInverter.ChannelId.ACTIVE_POWER, //
HybridManagedSymmetricBatteryInverter.ChannelId.DC_DISCHARGE_POWER, //
SymmetricBatteryInverter.ChannelId.ACTIVE_CHARGE_ENERGY, //
SymmetricBatteryInverter.ChannelId.ACTIVE_DISCHARGE_ENERGY, //
HybridManagedSymmetricBatteryInverter.ChannelId.DC_CHARGE_ENERGY, //
HybridManagedSymmetricBatteryInverter.ChannelId.DC_DISCHARGE_ENERGY, //
OpenemsComponent.ChannelId.values(), //
StartStoppable.ChannelId.values(), //
SymmetricBatteryInverter.ChannelId.values(), //
Expand All @@ -116,54 +109,6 @@ public GoodWeBatteryInverterImpl() throws OpenemsNamedException {
this._setStartStop(StartStop.START);
}

private void updatechannels() {
Integer productionPower = this.calculatePvProduction();
final Channel<Integer> pBattery1Channel = this.channel(GoodWe.ChannelId.P_BATTERY1);
Integer dcDischargePower = pBattery1Channel.value().get();
Integer acActivePower = TypeUtils.sum(productionPower, dcDischargePower);

/*
* Update ActivePower
*/
this._setActivePower(acActivePower);

/*
* Calculate AC Energy
*/
if (acActivePower == null) {
// Not available
this.calculateAcChargeEnergy.update(null);
this.calculateAcDischargeEnergy.update(null);
} else if (acActivePower > 0) {
// Discharge
this.calculateAcChargeEnergy.update(0);
this.calculateAcDischargeEnergy.update(acActivePower);
} else {
// Charge
this.calculateAcChargeEnergy.update(acActivePower * -1);
this.calculateAcDischargeEnergy.update(0);
}
/*
* Calculate DC Power and Energy
*/
this._setDcDischargePower(dcDischargePower);
if (dcDischargePower == null) {
// Not available
this.calculateDcChargeEnergy.update(null);
this.calculateDcDischargeEnergy.update(null);
} else {
if (dcDischargePower > 0) {
// Discharge
this.calculateDcChargeEnergy.update(0);
this.calculateDcDischargeEnergy.update(dcDischargePower);
} else {
// Charge
this.calculateDcChargeEnergy.update(dcDischargePower * -1);
this.calculateDcDischargeEnergy.update(0);
}
}
}

/**
* Sets the Battery Limits.
*
Expand Down Expand Up @@ -222,7 +167,7 @@ public void run(Battery battery, int setActivePower, int setReactivePower) throw
this.setBatteryLimits(battery);

// Calculate ActivePower and Energy values.
this.updatechannels();
this.updatePowerAndEnergyChannels();
this.lastSoc = battery.getSoc();

// Calculate and store Max-AC-Export and -Import for use in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import io.openems.edge.bridge.modbus.api.task.FC16WriteRegistersTask;
import io.openems.edge.bridge.modbus.api.task.FC3ReadRegistersTask;
import io.openems.edge.bridge.modbus.api.task.FC6WriteRegisterTask;
import io.openems.edge.common.channel.Channel;
import io.openems.edge.common.channel.EnumReadChannel;
import io.openems.edge.common.channel.IntegerReadChannel;
import io.openems.edge.common.component.OpenemsComponent;
import io.openems.edge.common.sum.GridMode;
import io.openems.edge.common.taskmanager.Priority;
Expand All @@ -34,16 +36,39 @@
import io.openems.edge.goodwe.charger.AbstractGoodWeEtCharger;
import io.openems.edge.goodwe.common.enums.BatteryMode;
import io.openems.edge.goodwe.common.enums.GoodweType;
import io.openems.edge.timedata.api.TimedataProvider;
import io.openems.edge.timedata.api.utils.CalculateEnergyFromPower;

public abstract class AbstractGoodWe extends AbstractOpenemsModbusComponent implements GoodWe, OpenemsComponent {
public abstract class AbstractGoodWe extends AbstractOpenemsModbusComponent
implements GoodWe, OpenemsComponent, TimedataProvider {

private final Logger log = LoggerFactory.getLogger(AbstractGoodWe.class);

private final io.openems.edge.common.channel.ChannelId activePowerChannelId;
private final io.openems.edge.common.channel.ChannelId dcDischargePowerChannelId;
private final CalculateEnergyFromPower calculateAcChargeEnergy;
private final CalculateEnergyFromPower calculateAcDischargeEnergy;
private final CalculateEnergyFromPower calculateDcChargeEnergy;
private final CalculateEnergyFromPower calculateDcDischargeEnergy;

protected final Set<AbstractGoodWeEtCharger> chargers = new HashSet<>();

public AbstractGoodWe(io.openems.edge.common.channel.ChannelId[] firstInitialChannelIds,
protected AbstractGoodWe(//
io.openems.edge.common.channel.ChannelId activePowerChannelId, //
io.openems.edge.common.channel.ChannelId dcDischargePowerChannelId, //
io.openems.edge.common.channel.ChannelId activeChargeEnergyChannelId, //
io.openems.edge.common.channel.ChannelId activeDischargeEnergyChannelId, //
io.openems.edge.common.channel.ChannelId dcChargeEnergyChannelId, //
io.openems.edge.common.channel.ChannelId dcDischargeEnergyChannelId, //
io.openems.edge.common.channel.ChannelId[] firstInitialChannelIds, //
io.openems.edge.common.channel.ChannelId[]... furtherInitialChannelIds) throws OpenemsNamedException {
super(firstInitialChannelIds, furtherInitialChannelIds);
this.activePowerChannelId = activePowerChannelId;
this.dcDischargePowerChannelId = dcDischargePowerChannelId;
this.calculateAcChargeEnergy = new CalculateEnergyFromPower(this, activeChargeEnergyChannelId);
this.calculateAcDischargeEnergy = new CalculateEnergyFromPower(this, activeDischargeEnergyChannelId);
this.calculateDcChargeEnergy = new CalculateEnergyFromPower(this, dcChargeEnergyChannelId);
this.calculateDcDischargeEnergy = new CalculateEnergyFromPower(this, dcDischargeEnergyChannelId);
}

@Override
Expand Down Expand Up @@ -431,4 +456,58 @@ protected final Integer calculatePvProduction() {
return productionPower;
}

protected void updatePowerAndEnergyChannels() {
Integer productionPower = this.calculatePvProduction();
final Channel<Integer> pBattery1Channel = this.channel(GoodWe.ChannelId.P_BATTERY1);
Integer dcDischargePower = pBattery1Channel.value().get();
Integer acActivePower = TypeUtils.sum(productionPower, dcDischargePower);

/*
* Update AC Active Power
*/
IntegerReadChannel activePowerChannel = this.channel(this.activePowerChannelId);
activePowerChannel.setNextValue(acActivePower);

/*
* Calculate AC Energy
*/
if (acActivePower == null) {
// Not available
this.calculateAcChargeEnergy.update(null);
this.calculateAcDischargeEnergy.update(null);
} else if (acActivePower > 0) {
// Discharge
this.calculateAcChargeEnergy.update(0);
this.calculateAcDischargeEnergy.update(acActivePower);
} else {
// Charge
this.calculateAcChargeEnergy.update(acActivePower * -1);
this.calculateAcDischargeEnergy.update(0);
}

/*
* Update DC Discharge Power
*/
IntegerReadChannel dcDischargePowerChannel = this.channel(this.dcDischargePowerChannelId);
dcDischargePowerChannel.setNextValue(dcDischargePower);

/*
* Calculate DC Energy
*/
if (dcDischargePower == null) {
// Not available
this.calculateDcChargeEnergy.update(null);
this.calculateDcDischargeEnergy.update(null);
} else {
if (dcDischargePower > 0) {
// Discharge
this.calculateDcChargeEnergy.update(0);
this.calculateDcDischargeEnergy.update(dcDischargePower);
} else {
// Charge
this.calculateDcChargeEnergy.update(dcDischargePower * -1);
this.calculateDcDischargeEnergy.update(0);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.edge.bridge.modbus.api.BridgeModbus;
import io.openems.edge.common.channel.Channel;
import io.openems.edge.common.component.ComponentManager;
import io.openems.edge.common.component.OpenemsComponent;
import io.openems.edge.common.event.EdgeEventConstants;
import io.openems.edge.common.type.TypeUtils;
import io.openems.edge.ess.api.HybridEss;
import io.openems.edge.ess.api.ManagedSymmetricEss;
import io.openems.edge.ess.api.SymmetricEss;
Expand All @@ -35,7 +33,6 @@
import io.openems.edge.goodwe.common.GoodWe;
import io.openems.edge.timedata.api.Timedata;
import io.openems.edge.timedata.api.TimedataProvider;
import io.openems.edge.timedata.api.utils.CalculateEnergyFromPower;

@Designate(ocd = Config.class, factory = true)
@Component(//
Expand Down Expand Up @@ -64,11 +61,6 @@ public class GoodWeEssImpl extends AbstractGoodWe implements GoodWeEss, GoodWe,
@Reference
private Power power;

private final CalculateEnergyFromPower calculateAcChargeEnergy = new CalculateEnergyFromPower(this,
SymmetricEss.ChannelId.ACTIVE_CHARGE_ENERGY);
private final CalculateEnergyFromPower calculateAcDischargeEnergy = new CalculateEnergyFromPower(this,
SymmetricEss.ChannelId.ACTIVE_DISCHARGE_ENERGY);

@Reference(policy = ReferencePolicy.STATIC, policyOption = ReferencePolicyOption.GREEDY, cardinality = ReferenceCardinality.MANDATORY)
protected void setModbus(BridgeModbus modbus) {
super.setModbus(modbus);
Expand All @@ -91,6 +83,12 @@ protected void deactivate() {

public GoodWeEssImpl() throws OpenemsNamedException {
super(//
SymmetricEss.ChannelId.ACTIVE_POWER, //
HybridEss.ChannelId.DC_DISCHARGE_POWER, //
SymmetricEss.ChannelId.ACTIVE_CHARGE_ENERGY, //
SymmetricEss.ChannelId.ACTIVE_DISCHARGE_ENERGY, //
HybridEss.ChannelId.DC_CHARGE_ENERGY, //
HybridEss.ChannelId.DC_DISCHARGE_ENERGY, //
OpenemsComponent.ChannelId.values(), //
SymmetricEss.ChannelId.values(), //
ManagedSymmetricEss.ChannelId.values(), //
Expand All @@ -102,9 +100,6 @@ public GoodWeEssImpl() throws OpenemsNamedException {

@Override
public void applyPower(int activePower, int reactivePower) throws OpenemsNamedException {
// Calculate ActivePower and Energy values.
this.updatechannels();

// Apply Power Set-Point
ApplyPowerHandler.apply(this, false /* read-only mode is never true */, activePower);
}
Expand All @@ -126,41 +121,14 @@ public void handleEvent(Event event) {

switch (event.getTopic()) {
case EdgeEventConstants.TOPIC_CYCLE_BEFORE_PROCESS_IMAGE:
this.updatechannels();
this.updatePowerAndEnergyChannels();
break;
case EdgeEventConstants.TOPIC_CYCLE_AFTER_PROCESS_IMAGE:
this.allowedChargeDischargeHandler.accept(this.componentManager);
break;
}
}

private void updatechannels() {
/*
* Update ActivePower from P_BATTERY1 and chargers ACTUAL_POWER
*/
Integer productionPower = this.calculatePvProduction();
final Channel<Integer> batteryPower = this.channel(GoodWe.ChannelId.P_BATTERY1);
Integer activePower = TypeUtils.sum(productionPower, batteryPower.value().get());
this._setActivePower(activePower);

/*
* Calculate AC Energy
*/
if (activePower == null) {
// Not available
this.calculateAcChargeEnergy.update(null);
this.calculateAcDischargeEnergy.update(null);
} else if (activePower > 0) {
// Discharge
this.calculateAcChargeEnergy.update(0);
this.calculateAcDischargeEnergy.update(activePower);
} else {
// Charge
this.calculateAcChargeEnergy.update(activePower * -1);
this.calculateAcDischargeEnergy.update(0);
}
}

@Override
public Power getPower() {
return this.power;
Expand Down

0 comments on commit 700b0e3

Please sign in to comment.