From 2c4867204d492cf4f9674ee52cc7b7ec4291076b Mon Sep 17 00:00:00 2001 From: Nils Ritler <79571155+Slisls@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:04:44 +0200 Subject: [PATCH] started smartcontrol --- .../ch/hevs/isi/field/FieldConnector.java | 8 +-- .../java/ch/hevs/isi/field/SmartControl.java | 64 +++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ch/hevs/isi/field/SmartControl.java diff --git a/src/main/java/ch/hevs/isi/field/FieldConnector.java b/src/main/java/ch/hevs/isi/field/FieldConnector.java index 3d26045..0207dab 100644 --- a/src/main/java/ch/hevs/isi/field/FieldConnector.java +++ b/src/main/java/ch/hevs/isi/field/FieldConnector.java @@ -75,9 +75,9 @@ public class FieldConnector implements DataPointListener { * @param pathToFile path to the file of all modbus registers (C:/.../ModbusMap.csv) */ public void initialize(String host, int port, String pathToFile){ - ModbusAccessor.getMySelf().connect(host,port); - createRegister(pathToFile); - startPeriodicalPolling(); + ModbusAccessor.getMySelf().connect(host,port); //connect with Modbus + createRegister(pathToFile); //read the csv file of the modbus registers + startPeriodicalPolling(); //start periodical reading of the float values } private void pushToField(String label, String value){ System.out.println("Field: " + label + " " + value); @@ -96,6 +96,6 @@ public class FieldConnector implements DataPointListener { public void startPeriodicalPolling(){ Timer pollTimer = new Timer(); PollTask pollTask = new PollTask(); - pollTimer.scheduleAtFixedRate(pollTask,0,100); + pollTimer.scheduleAtFixedRate(pollTask,0,2000); } } diff --git a/src/main/java/ch/hevs/isi/field/SmartControl.java b/src/main/java/ch/hevs/isi/field/SmartControl.java new file mode 100644 index 0000000..72ac3c7 --- /dev/null +++ b/src/main/java/ch/hevs/isi/field/SmartControl.java @@ -0,0 +1,64 @@ +package ch.hevs.isi.field; + +import ch.hevs.isi.core.DataPoint; +import ch.hevs.isi.core.FloatDataPoint; + +public class SmartControl { + + public SmartControl(){ + + //time + FloatDataPoint clockFloat = (FloatDataPoint) DataPoint.getDataPointFromLabel("CLOCK_FLOAT"); + int timeOfTheDay = 0; //0=default 1=beginning 2=day 3=end 4=night + if (clockFloat.getValue() > 0.2f && clockFloat.getValue() <= 0.3f) { //beginning of the day + timeOfTheDay =1; + } + if (clockFloat.getValue() > 0.3f && clockFloat.getValue() <= 0.7f){ //day + timeOfTheDay = 2; + } + if (clockFloat.getValue() > 0.7f && clockFloat.getValue() <= 0.8f){ //end of the day + timeOfTheDay = 3; + } + if (clockFloat.getValue() <= 0.2f && clockFloat.getValue() > 0.8f){ //night + timeOfTheDay = 4; + } + + + //Factory and coal + FloatDataPoint battChrgFloat = (FloatDataPoint) DataPoint.getDataPointFromLabel("BATT_CHRG_FLOAT"); + FloatDataPoint remoteCoalSp = (FloatDataPoint) DataPoint.getDataPointFromLabel("REMOTE_COAL_SP"); + FloatDataPoint remoteFactorySp = (FloatDataPoint) DataPoint.getDataPointFromLabel("REMOTE_FACTORY_SP"); + FloatDataPoint coalAmount = (FloatDataPoint) DataPoint.getDataPointFromLabel("COAL_AMOUNT"); + + if (battChrgFloat.getValue() <= 0.4f){ //if battery level is under 40 % + if(coalAmount.getValue() <= 0.5f){ + remoteCoalSp.setValue(0.5f); //start the coal power plant with 50% + }else{ + remoteCoalSp.setValue(1f); //start the coal power plant with 100% + } + remoteFactorySp.setValue(0f); //stop the consumption of the factory + } + if (battChrgFloat.getValue() > 0.4f && battChrgFloat.getValue() < 0.6f){ //if battery lever is between 40% and 60% + remoteCoalSp.setValue(0f); //stop the coal power plant + remoteFactorySp.setValue(0f); //stop the consumption of the factory + } + if(battChrgFloat.getValue() >= 0.6f){ //if battery level is over 60 % + remoteCoalSp.setValue(0f); //stop the coal power plant + remoteFactorySp.setValue(1f); //start the consumption of the factory + } + + //Solar + FloatDataPoint weatherFloat = (FloatDataPoint) DataPoint.getDataPointFromLabel("WEATHER_FLOAT"); + FloatDataPoint weatherCountdownFloat = (FloatDataPoint) DataPoint.getDataPointFromLabel("WEATHER_COUNTDOWN_FLOAT"); + FloatDataPoint weatherForecastFloat = (FloatDataPoint) DataPoint.getDataPointFromLabel("WEATHER_FORECAST_FLOAT"); + + /** TODO Solar Smartcontrol + * check the value of weatherForecastFloat and weatherFloat + */ + + //Wind + /** TODO Wind Smartcontrol + * + */ + } +}