use of io.openems.core.utilities.power.symmetric.PowerException in project openems by OpenEMS.
the class AvoidTotalDischargeSocTimeLineController method run.
/*
* Methods
*/
@Override
public void run() {
try {
LocalTime time = LocalTime.now();
for (Ess ess : esss.value()) {
if (dischargeStart != null && dischargeStart.isBefore(LocalDateTime.now()) && ess.currentState != Ess.State.EMPTY) {
ess.currentState = Ess.State.EMPTY;
}
switch(ess.currentState) {
case CHARGESOC:
if (ess.soc.value() > ess.getMinSoc(time)) {
ess.currentState = State.MINSOC;
} else {
try {
long maxChargePower = Math.max(ess.power.getMinP().orElse(0L), Math.abs(ess.maxNominalPower.valueOptional().orElse(1000L)) * -1);
ess.maxActivePowerLimit.setP(maxChargePower);
ess.power.applyLimitation(ess.maxActivePowerLimit);
} catch (PowerException e) {
log.error("Failed to set Power!", e);
}
}
break;
case MINSOC:
if (ess.soc.value() < ess.getChargeSoc(time)) {
ess.currentState = State.CHARGESOC;
} else if (ess.soc.value() >= ess.getMinSoc(time) + 5) {
ess.currentState = State.NORMAL;
} else {
ess.maxActivePowerLimit.setP(0L);
try {
ess.power.applyLimitation(ess.maxActivePowerLimit);
} catch (PowerException e) {
log.error("Failed to set Power!", e);
}
}
break;
case NORMAL:
if (ess.soc.value() <= ess.getMinSoc(time)) {
ess.currentState = State.MINSOC;
}
break;
case EMPTY:
if (ess.allowedDischarge.value() == 0 || ess.soc.value() < 1) {
// Ess is Empty set Date and charge to minSoc
addPeriod();
ess.currentState = State.CHARGESOC;
} else {
// Force discharge with max power
try {
long maxDischargePower = Math.min(Math.abs(ess.maxNominalPower.value()), ess.power.getMaxP().orElse(0L));
ess.minActivePowerLimit.setP(maxDischargePower);
ess.power.applyLimitation(ess.minActivePowerLimit);
} catch (PowerException e) {
log.error("Failed to force Discharge!", e);
}
}
break;
}
}
} catch (InvalidValueException e) {
log.error(e.getMessage());
}
}
use of io.openems.core.utilities.power.symmetric.PowerException in project openems by OpenEMS.
the class CosPhiController method run.
/*
* Methods
*/
@Override
public void run() {
try {
Ess ess = this.ess.value();
ess.limit.setCosPhi(cosPhi.valueOptional().orElse(null), capacitive.valueOptional().orElse(null), 0L, 0L);
ess.power.applyLimitation(ess.limit);
} catch (InvalidValueException e) {
log.error("No ess found.", e);
} catch (PowerException e) {
log.error("Failed to set Power!", e);
}
}
Aggregations