Skip to content

Commit

Permalink
Merge branch 'release/2018.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeilmeier committed Apr 25, 2018
2 parents 7811bd6 + 2563f35 commit 328c2c1
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 55 deletions.
4 changes: 2 additions & 2 deletions edge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<url>http://openems.io</url>
<groupId>io.openems</groupId>
<artifactId>edge</artifactId>
<!-- <version>2018.5.0</version> -->
<version>2018.6.0-SNAPSHOT</version>
<version>2018.6.0</version>
<!-- <version>2018.7.0-SNAPSHOT</version> -->
<packaging>jar</packaging>
<scm>
<url>https://github.com/OpenEMS/openems</url>
Expand Down
4 changes: 2 additions & 2 deletions edge/src/io/openems/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
public class App {
private final static Logger log = LoggerFactory.getLogger(App.class);

// public final static String OPENEMS_VERSION = "2018.5.0";
public final static String OPENEMS_VERSION = "2018.6.0-SNAPSHOT";
public final static String OPENEMS_VERSION = "2018.6.0";
// public final static String OPENEMS_VERSION = "2018.7.0-SNAPSHOT";

public static void main(String[] args) {
log.info("OpenEMS version [" + OPENEMS_VERSION + "] started");
Expand Down
2 changes: 1 addition & 1 deletion edge/src/io/openems/core/utilities/AsymmetricPower.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void reducePower(ReductionType reductionType) throws WriteChannelExceptio
break;
}
} catch (InvalidValueException e) {
log.error("Failed to reduce power", e);
log.error("Failed to reduce power: " + e.getMessage());
}
// log.info(
// "Reduce activePower L1:[{}]->[{}], L2:[{}]->[{}],L3:[{}]->[{}] "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
/*
* Example config:
* <pre>
* {
* "class": "io.openems.impl.controller.channelthreshold.ChannelThresholdController",
* "priority": 65,
* "thresholdChannelAddress": "ess0/Soc",
* "outputChannelAddress": "output0/1",
* "lowerThreshold": 75,
* "upperThreshold": 80,
* "invertOutput": true,
* "hysteresis": 2
* }
{
"class": "io.openems.impl.controller.channelthreshold.ChannelThresholdController",
"priority": 65,
"thresholdChannelAddress": "ess0/Soc",
"outputChannelAddress": "output0/1",
"lowerThreshold": 75,
"upperThreshold": 80,
"invertOutput": true,
"hysteresis": 2
}
* </pre>
*/

Expand Down Expand Up @@ -77,7 +77,6 @@ public ChannelThresholdController(String thingId) {
private ThingRepository repo = ThingRepository.getInstance();
private ReadChannel<Long> thresholdChannel;
private WriteChannel<Boolean> outputChannel;
private boolean isActive = false;

/*
* Config
Expand Down Expand Up @@ -128,59 +127,206 @@ public ChannelThresholdController(String thingId) {
@ChannelInfo(title = "Invert-Output", description = "True if the digital output should be inverted.", type = Boolean.class)
public ConfigChannel<Boolean> invertOutput = new ConfigChannel<Boolean>("invertOutput", this).defaultValue(false);

private enum State {
UNDEFINED, /* Unknown state on first start */
BELOW_LOW, /* Value is smaller than the low threshold */
PASS_LOW_COMING_FROM_BELOW, /* Value just passed the low threshold. Last value was even lower. */
PASS_LOW_COMING_FROM_ABOVE, /* Value just passed the low threshold. Last value was higher. */
BETWEEN_LOW_AND_HIGH, /* Value is between low and high threshold */
PASS_HIGH_COMING_FROM_BELOW, /* Value just passed the high threshold. Last value was lower. */
PASS_HIGH_COMING_FROM_ABOVE, /* Value just passed the high threshold. Last value was higher. */
ABOVE_HIGH /* Value is bigger than the high threshold */
}

/**
* The current state in the State Machine
*/
private State state = State.UNDEFINED;

/**
* Should the hysteresis be applied on passing high threshold?
*/
private boolean applyHighHysteresis = true;
/**
* Should the hysteresis be applied on passing low threshold?
*/
private boolean applyLowHysteresis = true;

/*
* Methods
*/
@Override
public void run() {
// Check if all parameters are available
long threshold;
/*
* Check if all parameters are available
*/
long value;
long lowerThreshold;
long upperThreshold;
long hysteresis;
boolean invertOutput;
try {
threshold = this.thresholdChannel.value();
value = this.thresholdChannel.value();
lowerThreshold = this.lowerThreshold.value();
upperThreshold = this.upperThreshold.value();
hysteresis = this.hysteresis.value();
invertOutput = this.invertOutput.value();
} catch (InvalidValueException e) {
log.error("ChannelThresholdController error: " + e.getMessage());
return;
}
try {
if (isActive) {
if (threshold < lowerThreshold || threshold > upperThreshold + hysteresis) {
isActive = false;
} else {
on(invertOutput);

/*
* State Machine
*/
switch (this.state) {
case UNDEFINED:
if (value < lowerThreshold) {
this.state = State.BELOW_LOW;
} else if (value > upperThreshold) {
this.state = State.ABOVE_HIGH;
} else {
this.state = State.BETWEEN_LOW_AND_HIGH;
}
break;

case BELOW_LOW:
/*
* Value is smaller than the low threshold -> always OFF
*/
if (value >= lowerThreshold) {
this.state = State.PASS_LOW_COMING_FROM_BELOW;
break;
}

this.off();
break;

case PASS_LOW_COMING_FROM_BELOW:
/*
* Value just passed the low threshold coming from below -> turn ON
*/
this.on();
this.applyLowHysteresis = true;
this.state = State.BETWEEN_LOW_AND_HIGH;
break;

case BETWEEN_LOW_AND_HIGH:
/*
* Value is between low and high threshold -> always ON
*/
// evaluate if hysteresis is necessary
if (value >= lowerThreshold + hysteresis) {
this.applyLowHysteresis = false; // do not apply low hysteresis anymore
}
if (value <= upperThreshold - hysteresis) {
this.applyHighHysteresis = false; // do not apply high hysteresis anymore
}

/*
* Check LOW threshold
*/
if (applyLowHysteresis) {
if (value <= lowerThreshold - hysteresis) {
// pass low with hysteresis
this.state = State.PASS_LOW_COMING_FROM_ABOVE;
break;
}
} else {
if (threshold >= lowerThreshold + hysteresis && threshold <= upperThreshold) {
isActive = true;
} else {
off(invertOutput);
if (value <= lowerThreshold) {
// pass low, not applying hysteresis
this.state = State.PASS_LOW_COMING_FROM_ABOVE;
break;
}
}
} catch (WriteChannelException e) {
log.error("Failed to write Channel[" + outputChannel.address() + "]: " + e.getMessage());

/*
* Check HIGH threshold
*/
if (applyHighHysteresis) {
if (value >= upperThreshold + hysteresis) {
// pass high with hysteresis
this.state = State.PASS_HIGH_COMING_FROM_BELOW;
break;
}
} else {
if (value >= upperThreshold) {
// pass high, not applying hysteresis
this.state = State.PASS_HIGH_COMING_FROM_BELOW;
break;
}
}

// Default: not switching the State -> always ON
this.on();
break;

case PASS_HIGH_COMING_FROM_BELOW:
/*
* Value just passed the high threshold coming from below -> turn OFF
*/
this.off();
this.state = State.ABOVE_HIGH;
break;

case PASS_LOW_COMING_FROM_ABOVE:
/*
* Value just passed the low threshold from above -> turn OFF
*/
this.off();
this.state = State.BELOW_LOW;
break;

case PASS_HIGH_COMING_FROM_ABOVE:
/*
* Value just passed the high threshold coming from above -> turn ON
*/
this.on();
this.applyHighHysteresis = true;
this.state = State.BETWEEN_LOW_AND_HIGH;
break;

case ABOVE_HIGH:
/*
* Value is bigger than the high threshold -> always OFF
*/
if (value <= upperThreshold) {
this.state = State.PASS_HIGH_COMING_FROM_ABOVE;
}

this.off();
break;
}
}

private void on(boolean invertOutput) throws WriteChannelException {
Optional<Boolean> currentValueOpt = this.outputChannel.valueOptional();
if (!currentValueOpt.isPresent() || currentValueOpt.get() != (true ^ invertOutput)) {
log.info("Set output [" + this.outputChannel.address() + "] ON.");
outputChannel.pushWrite(true ^ invertOutput);
}
/**
* Switch the output ON
*/
private void on() {
this.setOutput(true);
}

private void off(boolean invertOutput) throws WriteChannelException {
/**
* Switch the output OFF
*/
private void off() {
this.setOutput(false);
}

/**
* Helper function to switch an output if it was not switched before.
*
* @param value
* true to switch ON, false to switch ON; is inverted if 'invertOutput' config is set
*/
private void setOutput(boolean value) {
Optional<Boolean> currentValueOpt = this.outputChannel.valueOptional();
if (!currentValueOpt.isPresent() || currentValueOpt.get() != (false ^ invertOutput)) {
log.info("Set output [" + this.outputChannel.address() + "] OFF.");
outputChannel.pushWrite(false ^ invertOutput);
boolean invertOutput = this.invertOutput.valueOptional().orElse(false);
if (!currentValueOpt.isPresent() || currentValueOpt.get() != (value ^ invertOutput)) {
log.info("Set output [" + this.outputChannel.address() + "] " + (value ? "ON" : "OFF") + ".");
try {
outputChannel.pushWrite(value ^ invertOutput);
} catch (WriteChannelException e) {
log.error("ChannelThresholdController error: " + e.getMessage());
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openems-ui",
"version": "2018.6.0-SNAPSHOT",
"version": "2018.6.0",
"license": "AGPL",
"scripts": {
"ng": "ng",
Expand Down
4 changes: 2 additions & 2 deletions ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<parent>
<groupId>io.openems</groupId>
<artifactId>pom</artifactId>
<!-- <version>2018.5.0</version> -->
<version>2018.6.0-SNAPSHOT</version>
<version>2018.6.0</version>
<!-- <version>2018.7.0-SNAPSHOT</version> -->
</parent>
<artifactId>edge</artifactId>
<packaging>pom</packaging>
Expand Down
16 changes: 8 additions & 8 deletions ui/src/app/about/about.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
<a target="_blank" href="https://fenecon.de" translate>About.Fenecon</a>
</li>
<li>
<a target="_blank" href="https://fenecon.de/page/stromspeicher-fems" translate>About.Fems</a>
<a target="_blank" href="https://fenecon.de/page/fems" translate>About.Fems</a>
</li>
<li>
<a target="_blank" href="https://github.com/OpenEMS/openems" translate>About.Sourcecode</a>
</li>
<!-- <li>
<a target="_blank" href="https://github.com/OpenEMS/openems/releases/tag/2018.5">
<span translate>About.Build</span>: 2018.5 (2018-04-12)</a>
</li> -->
<li>
<a target="_blank" href="https://github.com/OpenEMS/openems/tree/develop">
<span translate>About.Build</span>: 2018.6.0-SNAPSHOT</a>
<a target="_blank" href="https://github.com/OpenEMS/openems/releases/tag/2018.6">
<span translate>About.Build</span>: 2018.6 (2018-04-25)</a>
</li>
<!-- <li>
<a target="_blank" href="https://github.com/OpenEMS/openems/tree/develop">
<span translate>About.Build</span>: 2018.7.0-SNAPSHOT</a>
</li> -->
</ul>
<p>
<span [innerHTML]="'About.Contact' | translate:{value: '[email protected]'}"></span>
Expand All @@ -36,4 +36,4 @@
</select>
</ul>
</mat-card-content>
</mat-card>
</mat-card>

0 comments on commit 328c2c1

Please sign in to comment.