Skip to content

Commit

Permalink
Refactor DelayChargeController
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeilmeier committed Mar 18, 2018
1 parent f9627e9 commit e3e8ab6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*******************************************************************************/
package io.openems.impl.controller.symmetric.delaycharge;

import java.time.LocalDateTime;
import java.util.Optional;

import io.openems.api.channel.ConfigChannel;
Expand All @@ -35,8 +36,6 @@ public class DelayChargeController extends Controller {

private ThingStateChannels thingState = new ThingStateChannels(this);

private SocQueue socQueue = new SocQueue(10);

/*
* Constructors
*/
Expand Down Expand Up @@ -66,33 +65,24 @@ public void run() {
// Get required variables
Ess ess = this.ess.getValue();
long soc = ess.soc.getValue();
long capacity = ess.capacity.getValue();
long targetSecondOfDay = this.targetHour.getValue() * 3600;

// Verbleibende Kapazität / verbleibende Zeit = limit

// Add SoC to queue if it changed
this.socQueue.addIfChanged(soc);
// calculate remaining capacity in Ws
long remainingCapacity = capacity * (100 - soc) * 36;

// We already passed the "target hour of day" -> no restrictions
if (Util.currentSecondOfDay() > targetSecondOfDay) {
log.info("We already passed the \"target hour of day\" -> no restrictions");
return;
}

double socGradient = this.socQueue.getGradient();

// SoC is not increasing -> no restrictions
if (!(socGradient > 0)) {
log.info("SoC is not increasing -> no restrictions. SoC-Gradient [" + socGradient + "]");
if (!(remainingCapacity > 0)) {
log.error("RemainingCapacity is [" + remainingCapacity + "Ws] must be > 0");
return;
}

double targetGradient = (double) (100 - soc) / (targetSecondOfDay - Util.currentSecondOfDay());
// calculate remaining time
long remainingTime = targetSecondOfDay - currentSecondOfDay();

// SoC is not increasing fast enough -> no restrictions
if (socGradient < targetGradient) {
log.info("SoC is not increasing fast enough -> no restrictions. SoC-Gradient [" + socGradient
+ "] Target-Gradient [" + targetGradient + "]");
// We already passed the "target hour of day" -> no restrictions
if (remainingTime < 0) {
log.info("We already passed the \"target hour of day\" -> no restrictions");
return;
}

Expand All @@ -104,7 +94,7 @@ public void run() {
long currentLimit = currentLimitOpt.get();

// Set limitation for ChargePower
long newLimit = Math.round((targetGradient / socGradient) * currentLimit);
long newLimit = remainingCapacity / remainingTime * -1;
ess.limit.setP(newLimit);
try {
ess.power.applyLimitation(ess.limit);
Expand All @@ -120,4 +110,8 @@ public ThingStateChannels getStateChannel() {
return this.thingState;
}

private static long currentSecondOfDay() {
LocalDateTime now = LocalDateTime.now();
return now.getHour() * 3600 + now.getMinute() * 60 + now.getSecond();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
public class Ess extends ThingMap {

public final ReadChannel<Long> soc;
public final ReadChannel<Long> capacity;
public final SymmetricPower power;
public final PGreaterEqualLimitation limit;

public Ess(SymmetricEssNature ess) {
super(ess);
soc = ess.soc().required();
this.soc = ess.soc().required();
this.capacity = ess.capacity().required();
this.power = ess.getPower();
this.limit = new PGreaterEqualLimitation(power);
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit e3e8ab6

Please sign in to comment.