diff --git a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/batteryinverter/GoodWeBatteryInverterImpl.java b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/batteryinverter/GoodWeBatteryInverterImpl.java index 3dd6fdfaec1..f1a73d6df6d 100644 --- a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/batteryinverter/GoodWeBatteryInverterImpl.java +++ b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/batteryinverter/GoodWeBatteryInverterImpl.java @@ -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; @@ -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(// @@ -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] @@ -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 @@ -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(), // @@ -116,54 +109,6 @@ public GoodWeBatteryInverterImpl() throws OpenemsNamedException { this._setStartStop(StartStop.START); } - private void updatechannels() { - Integer productionPower = this.calculatePvProduction(); - final Channel 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. * @@ -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 diff --git a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/common/AbstractGoodWe.java b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/common/AbstractGoodWe.java index 0fba3c80a53..43a6cd4b6b0 100644 --- a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/common/AbstractGoodWe.java +++ b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/common/AbstractGoodWe.java @@ -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; @@ -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 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 @@ -431,4 +456,58 @@ protected final Integer calculatePvProduction() { return productionPower; } + protected void updatePowerAndEnergyChannels() { + Integer productionPower = this.calculatePvProduction(); + final Channel 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); + } + } + } } diff --git a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/ess/GoodWeEssImpl.java b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/ess/GoodWeEssImpl.java index f0e23796410..5c76f1651fc 100644 --- a/io.openems.edge.goodwe/src/io/openems/edge/goodwe/ess/GoodWeEssImpl.java +++ b/io.openems.edge.goodwe/src/io/openems/edge/goodwe/ess/GoodWeEssImpl.java @@ -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; @@ -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(// @@ -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); @@ -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(), // @@ -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); } @@ -126,7 +121,7 @@ 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); @@ -134,33 +129,6 @@ public void handleEvent(Event event) { } } - private void updatechannels() { - /* - * Update ActivePower from P_BATTERY1 and chargers ACTUAL_POWER - */ - Integer productionPower = this.calculatePvProduction(); - final Channel 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;