From 6ea85aa945d18a535735c7fbe53d6301fb1bd9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 9 Jun 2023 16:23:59 +0200 Subject: [PATCH 1/6] change System.out.println to pDebug --- src/main/java/ch/hevs/isi/db/DatabaseConnector.java | 2 +- src/main/java/ch/hevs/isi/field/FieldConnector.java | 3 ++- src/main/java/ch/hevs/isi/web/WebConnector.java | 9 +++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/hevs/isi/db/DatabaseConnector.java b/src/main/java/ch/hevs/isi/db/DatabaseConnector.java index 63eb65a..5a2bbc0 100644 --- a/src/main/java/ch/hevs/isi/db/DatabaseConnector.java +++ b/src/main/java/ch/hevs/isi/db/DatabaseConnector.java @@ -163,7 +163,7 @@ public class DatabaseConnector implements DataPointListener { if(respondCode != 204){ System.out.println("Error: " + respondCode + ", Data: " + data); } else { - System.out.println(data + " -> Database"); + Utility.pDebug(data + " -> Database"); } con.disconnect(); con = null; diff --git a/src/main/java/ch/hevs/isi/field/FieldConnector.java b/src/main/java/ch/hevs/isi/field/FieldConnector.java index 5b5b9c1..26b00a1 100644 --- a/src/main/java/ch/hevs/isi/field/FieldConnector.java +++ b/src/main/java/ch/hevs/isi/field/FieldConnector.java @@ -3,6 +3,7 @@ package ch.hevs.isi.field; import ch.hevs.isi.core.DataPoint; import ch.hevs.isi.core.DataPointListener; import ch.hevs.isi.core.FloatDataPoint; +import ch.hevs.isi.utils.Utility; import java.io.BufferedReader; import java.io.FileNotFoundException; @@ -89,7 +90,7 @@ public class FieldConnector implements DataPointListener { } private void pushToField(String label, String value){ - System.out.println("Field: " + label + " " + value); + Utility.pDebug("Field: " + label + " " + value); } @Override public void onNewValue(DataPoint dp) { diff --git a/src/main/java/ch/hevs/isi/web/WebConnector.java b/src/main/java/ch/hevs/isi/web/WebConnector.java index 9b6f119..292dfab 100644 --- a/src/main/java/ch/hevs/isi/web/WebConnector.java +++ b/src/main/java/ch/hevs/isi/web/WebConnector.java @@ -4,6 +4,7 @@ import ch.hevs.isi.core.BooleanDataPoint; import ch.hevs.isi.core.DataPoint; import ch.hevs.isi.core.DataPointListener; import ch.hevs.isi.core.FloatDataPoint; +import ch.hevs.isi.utils.Utility; import org.java_websocket.WebSocket; import org.java_websocket.handshake.ClientHandshake; import org.java_websocket.server.WebSocketServer; @@ -50,7 +51,7 @@ public class WebConnector implements DataPointListener { @Override public void onMessage(WebSocket conn, String message) { - System.out.println("received message from " + conn.getRemoteSocketAddress() + ": " + message); + Utility.pDebug("received message from " + conn.getRemoteSocketAddress() + ": " + message); updateDataPoint(message); } @@ -74,15 +75,15 @@ public class WebConnector implements DataPointListener { private void pushToWeb(DataPoint dp){ wss.broadcast(dp.toString()); - System.out.println(dp.toString() + " -> Web"); + Utility.pDebug(dp.toString() + " -> Web"); } private void updateDataPoint(String message){ String label = message.split("=")[0]; - System.out.println("Label: " + label); + Utility.pDebug("Label: " + label); String value = message.split("=")[1]; - System.out.println("Value: " + value); + Utility.pDebug("Value: " + value); if( (value.equals("true")) || value.equals("false") ) { new BooleanDataPoint(label, true).setValue(Boolean.parseBoolean(value)); From f170d6f8b96228a470d49bb65d9f94a48d57f447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 9 Jun 2023 16:24:20 +0200 Subject: [PATCH 2/6] start SmartControl but nothing work (nullPointerException) --- .../java/ch/hevs/isi/MinecraftController.java | 26 +- src/main/java/ch/hevs/isi/SmartControl.java | 241 ++++++++++++++++++ .../java/ch/hevs/isi/field/SmartControl.java | 64 ----- 3 files changed, 264 insertions(+), 67 deletions(-) create mode 100644 src/main/java/ch/hevs/isi/SmartControl.java delete mode 100644 src/main/java/ch/hevs/isi/field/SmartControl.java diff --git a/src/main/java/ch/hevs/isi/MinecraftController.java b/src/main/java/ch/hevs/isi/MinecraftController.java index 1e6b4ac..66da3ec 100644 --- a/src/main/java/ch/hevs/isi/MinecraftController.java +++ b/src/main/java/ch/hevs/isi/MinecraftController.java @@ -34,7 +34,7 @@ public class MinecraftController { } @SuppressWarnings("all") - public static void main(String[] args) { + public static void main(String[] args) throws InterruptedException { // ------------------------------------- DO NOT CHANGE THE FOLLOWING LINES ------------------------------------- String dbProtocol = "http"; @@ -99,17 +99,37 @@ public class MinecraftController { Utility.pDebug("Database URL: " + DatabaseConnector.url); Utility.pDebug("Config: " + properties.getProperty("DB.URL")); DatabaseConnector.getMySelf().initialize(DatabaseConnector.url); + System.out.println("Database is running on " + DatabaseConnector.url); } // Initialize the Modbus TCP connector FieldConnector.getMySelf().initialize(modbusTcpHost, modbusTcpPort,"src/main/resources/ModbusMap.csv"); - - + System.out.println("Field is running on " + modbusTcpHost + ":" + modbusTcpPort); // Initialize the web server String host = properties.getProperty("WEB.URL"); int port = Integer.parseInt(properties.getProperty("WEB.PORT")); WebConnector.getMySelf().initialize(host, port); + System.out.println("Web server is running on " + host + ":" + port); + + + SmartControl smartControl = new SmartControl(); + System.out.println("SmartControl is running"); + while (true) { + boolean stateGrid = true; + try { + stateGrid = smartControl.run(); + } catch (Exception e) { + e.printStackTrace(); + } + if(!stateGrid) { + System.out.println("Grid is not fine"); + System.exit(0); + } else { + System.out.println("Grid is fine"); + } + Thread.sleep(SmartControl.TIME_BETWEEN_UPDATES); + } } diff --git a/src/main/java/ch/hevs/isi/SmartControl.java b/src/main/java/ch/hevs/isi/SmartControl.java new file mode 100644 index 0000000..5b39be3 --- /dev/null +++ b/src/main/java/ch/hevs/isi/SmartControl.java @@ -0,0 +1,241 @@ +package ch.hevs.isi; + +import ch.hevs.isi.core.BooleanDataPoint; +import ch.hevs.isi.core.DataPoint; +import ch.hevs.isi.core.FloatDataPoint; + +public class SmartControl { + + private static final float BATTERY_LEVEL_LOW = 0.1f; + private static final float BATTERY_LEVEL_HIGH = 0.9f; + private static final float BATTERY_POWER_MAX = 2500f; + private static final float COAL_AMOUNT_DAY = (1f-0.2f)/3f; + private static final float GRID_VOLTAGE_MIN = 750f; + private static final float GRID_VOLTAGE_MAX = 900f; + private static final float GRID_VOLTAGE_NOMINAL = 800f; + private static final float GRID_VOLTAGE_TOLERANCE = 25f; + private static final float PV_PANEL_NOMINAL = 1000f; + private static final float PV_PANEL_NOMINAL_RAINING = 500f; + + public static final long TIME_BETWEEN_UPDATES = 10; + + + + // Useful data points + private FloatDataPoint clock; + private FloatDataPoint battChrg; + private FloatDataPoint battPwrIn; + private FloatDataPoint remoteCoalSp; + private FloatDataPoint remoteFactorySp; + private FloatDataPoint coalAmount; + + + private void defineDataPoints(){ + clock = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("CLOCK_FLOAT"); + battChrg = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("BATT_CHRG_FLOAT"); + battPwrIn = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("BATT_P_FLOAT"); + remoteCoalSp = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_COAL_SP"); + remoteFactorySp = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_FACTORY_SP"); + coalAmount = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("COAL_AMOUNT"); + gridVoltage = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("GRID_U_FLOAT"); + } + + float getValue(FloatDataPoint fdp){ + if(fdp == null) return 0f; + return fdp.getValue(); + } + + // Emergency data points + private FloatDataPoint gridVoltage; + + // Ideal goal points variables + private float igpBatteryLevel = 0f; + private float igpCoalAmount = 0f; + + // Time variables + private int day = 0; + private float previousTime; + final float kpiFactory = 1f; + final float kpiCoal = 1f; + + + + + private float getTimeOfTheDay(){ + float timeOfTheDay = getValue(clock); + timeOfTheDay %= 1; + timeOfTheDay *= 24; + return timeOfTheDay; + } + + private float getProducerPower(){ + float producerPower = 0f; + FloatDataPoint solar = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SOLAR_P_FLOAT"); + FloatDataPoint wind = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("WIND_P_FLOAT"); + FloatDataPoint coal = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("COAL_P_FLOAT"); + + producerPower += getValue(solar); + producerPower += getValue(wind); + producerPower += getValue(coal); + + return producerPower; + } + + private float getConsumerPower(){ + float consumerPower = 0f; + FloatDataPoint home = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("HOME_P_FLOAT"); + FloatDataPoint factory = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("FACTORY_P_FLOAT"); + FloatDataPoint bunker = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("BUNKER_P_FLOAT"); + + consumerPower += getValue(home); + consumerPower += getValue(factory); + consumerPower += getValue(bunker); + return consumerPower; + } + + private boolean checkIfGridIsFine(){ + boolean gridIsFine = true; + + // Grid voltage is too high + if(getValue(gridVoltage) > (GRID_VOLTAGE_MAX-GRID_VOLTAGE_TOLERANCE)) { + gridIsFine = false; + new BooleanDataPoint("SOLAR_CONNECT_ST", true).setValue(false); + new BooleanDataPoint("WIND_CONNECT_ST", true).setValue(false); + remoteCoalSp.setValue(0f); + if(getValue(gridVoltage) > GRID_VOLTAGE_MAX) { + remoteFactorySp.setValue(1f); + } + } + + // Grid voltage is too low + if(getValue(gridVoltage) < (GRID_VOLTAGE_MIN+GRID_VOLTAGE_TOLERANCE)) { + gridIsFine = false; + new BooleanDataPoint("SOLAR_CONNECT_ST", true).setValue(true); + new BooleanDataPoint("WIND_CONNECT_ST", true).setValue(true); + remoteCoalSp.setValue(1f); + if(getValue(gridVoltage) < GRID_VOLTAGE_MIN) { + remoteFactorySp.setValue(0f); + } + } + + return gridIsFine; + } + + private int getPeriodOfDay(){ + float timeOfTheDay = getTimeOfTheDay(); + + // 0 = Night, 1 = Morning, 2 = Afternoon + int periodOfDay = 0; + if(timeOfTheDay >= 0 && timeOfTheDay < 6) periodOfDay = 1; // Night + if(timeOfTheDay >= 6 && timeOfTheDay < 12) periodOfDay = 2; // Morning + if(timeOfTheDay >= 12 && timeOfTheDay < 18) periodOfDay = 3; // Afternoon + if(timeOfTheDay >= 18 && timeOfTheDay < 24) periodOfDay = 4; // Evening + + return periodOfDay; + } + + private void defineIGPbatteryLevel(){ + + switch (getPeriodOfDay()){ + case 1: // Night + if(getTimeOfTheDay() < 5f) igpBatteryLevel = BATTERY_LEVEL_HIGH-0.5f; + else igpBatteryLevel = BATTERY_LEVEL_LOW+0.2f; + break; + case 2: // Morning + igpBatteryLevel = BATTERY_LEVEL_LOW; + break; + case 3: // Afternoon + igpBatteryLevel = BATTERY_LEVEL_HIGH; + break; + case 4: // Evening + if(getTimeOfTheDay() < 21f) igpBatteryLevel = BATTERY_LEVEL_HIGH-0.2f; + else igpBatteryLevel = BATTERY_LEVEL_HIGH-0.4f; + break; + default: + break; + } + } + + private void defineIGPcoalAmount(int day){ + float igpCoalAmountForTheDay = 1f; + switch (getPeriodOfDay()){ + case 1: // Night + if(getTimeOfTheDay() < 5f) igpCoalAmountForTheDay = 0.93f; + else igpCoalAmountForTheDay = 0.8f; + break; + case 2: // Morning + igpCoalAmountForTheDay = 0.7f; + break; + case 3: // Afternoon + igpCoalAmountForTheDay = 0.6f; + break; + case 4: // Evening + if(getTimeOfTheDay() < 21f) igpCoalAmountForTheDay = 0.5f; + else igpCoalAmountForTheDay = 0.3f; + break; + default: + break; + } + igpCoalAmountForTheDay += day; + igpCoalAmountForTheDay /= 3f; + + + } + + + public SmartControl() { + defineDataPoints(); + + previousTime = getTimeOfTheDay(); + + // start the solar and wind power plants + new BooleanDataPoint("REMOTE_SOLAR_SW", true).setValue(true); + new BooleanDataPoint("REMOTE_WIND_SW", true).setValue(true); + + + } + + public boolean run() { + defineDataPoints(); + float spCoal = getValue(remoteCoalSp); + float spFactory = getValue(remoteFactorySp); + + if (getTimeOfTheDay() < previousTime) { + previousTime = getTimeOfTheDay(); + day++; + day %= 3; + } + defineIGPbatteryLevel(); + defineIGPcoalAmount(day); + + if (getValue(battChrg) < igpBatteryLevel) { + spFactory -= (igpBatteryLevel - getValue(battChrg)) * kpiFactory; + spCoal += (igpBatteryLevel - getValue(battChrg)) * kpiCoal; + } + + if (getValue(battChrg) > igpBatteryLevel) { + spFactory += (getValue(battChrg) - igpBatteryLevel) * kpiFactory; + spCoal -= (getValue(battChrg) - igpBatteryLevel) * kpiCoal; + } + + if (getValue(coalAmount) < igpCoalAmount) { + spFactory -= (igpCoalAmount - getValue(coalAmount)) * kpiFactory; + spCoal += (igpCoalAmount - getValue(coalAmount)) * kpiCoal; + } + + if (getValue(coalAmount) > igpCoalAmount) { + spFactory += (getValue(coalAmount) - igpCoalAmount) * kpiFactory; + spCoal -= (getValue(coalAmount) - igpCoalAmount) * kpiCoal; + } + + if (spFactory > 1f) spFactory = 1f; + if (spFactory < 0f) spFactory = 0f; + if (spCoal > 1f) spCoal = 1f; + if (spCoal < 0f) spCoal = 0f; + + remoteFactorySp.setValue(spFactory); + remoteCoalSp.setValue(spCoal); + + return checkIfGridIsFine(); + } +} diff --git a/src/main/java/ch/hevs/isi/field/SmartControl.java b/src/main/java/ch/hevs/isi/field/SmartControl.java deleted file mode 100644 index 72ac3c7..0000000 --- a/src/main/java/ch/hevs/isi/field/SmartControl.java +++ /dev/null @@ -1,64 +0,0 @@ -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 - * - */ - } -} From 0fdcbba01bdb89826ba6b3c72405b87a5e19dc1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= <63239207+Klagarge@users.noreply.github.com> Date: Sun, 11 Jun 2023 18:33:44 +0200 Subject: [PATCH 3/6] do stuff only for DataPoints who have a register --- src/main/java/ch/hevs/isi/field/FieldConnector.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ch/hevs/isi/field/FieldConnector.java b/src/main/java/ch/hevs/isi/field/FieldConnector.java index 26b00a1..23a372c 100644 --- a/src/main/java/ch/hevs/isi/field/FieldConnector.java +++ b/src/main/java/ch/hevs/isi/field/FieldConnector.java @@ -95,6 +95,8 @@ public class FieldConnector implements DataPointListener { @Override public void onNewValue(DataPoint dp) { ModbusRegister mR = ModbusRegister.getRegisterFromDatapoint(dp); //search the corresponding register to the datapoint + if(mR == null) return; //if the register is not found, return + if(dp.isOutput()){ //write only on the datapoints, which are outputs if(dp.getLabel().equals("REMOTE_SOLAR_SW") //write only boolean outputs ||dp.getLabel().equals("REMOTE_WIND_SW") From c97d42893570888081a9344ab8ad0aa7eb5f40fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= <63239207+Klagarge@users.noreply.github.com> Date: Sun, 11 Jun 2023 18:34:35 +0200 Subject: [PATCH 4/6] Do a bit SmartControler but regulation won't really work --- .../java/ch/hevs/isi/MinecraftController.java | 13 +- src/main/java/ch/hevs/isi/SmartControl.java | 177 ++++++++++++------ 2 files changed, 128 insertions(+), 62 deletions(-) diff --git a/src/main/java/ch/hevs/isi/MinecraftController.java b/src/main/java/ch/hevs/isi/MinecraftController.java index 66da3ec..a01547e 100644 --- a/src/main/java/ch/hevs/isi/MinecraftController.java +++ b/src/main/java/ch/hevs/isi/MinecraftController.java @@ -1,5 +1,7 @@ package ch.hevs.isi; +import ch.hevs.isi.core.DataPoint; +import ch.hevs.isi.core.FloatDataPoint; import ch.hevs.isi.db.DatabaseConnector; import ch.hevs.isi.field.FieldConnector; import ch.hevs.isi.utils.Utility; @@ -124,9 +126,16 @@ public class MinecraftController { } if(!stateGrid) { System.out.println("Grid is not fine"); - System.exit(0); + //System.exit(0); } else { - System.out.println("Grid is fine"); + //System.out.println("Grid is fine"); + } + FloatDataPoint score = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SCORE"); + if(score != null) { + if(score.getValue() >= 100) { + System.out.println("Game finished with score: " + score.getValue()); + System.exit(0); + } } Thread.sleep(SmartControl.TIME_BETWEEN_UPDATES); } diff --git a/src/main/java/ch/hevs/isi/SmartControl.java b/src/main/java/ch/hevs/isi/SmartControl.java index 5b39be3..c63209d 100644 --- a/src/main/java/ch/hevs/isi/SmartControl.java +++ b/src/main/java/ch/hevs/isi/SmartControl.java @@ -6,10 +6,12 @@ import ch.hevs.isi.core.FloatDataPoint; public class SmartControl { - private static final float BATTERY_LEVEL_LOW = 0.1f; - private static final float BATTERY_LEVEL_HIGH = 0.9f; - private static final float BATTERY_POWER_MAX = 2500f; + private static final float BATTERY_LEVEL_LOW = 0.4f; + private static final float BATTERY_LEVEL_HIGH = 0.85f; + private static final float BATTERY_POWER_MAX = 1000f; private static final float COAL_AMOUNT_DAY = (1f-0.2f)/3f; + private static final float COAL_POWER_MAX = 500f; + private static final float FACTORY_POWER_MAX = 1000f; private static final float GRID_VOLTAGE_MIN = 750f; private static final float GRID_VOLTAGE_MAX = 900f; private static final float GRID_VOLTAGE_NOMINAL = 800f; @@ -17,7 +19,7 @@ public class SmartControl { private static final float PV_PANEL_NOMINAL = 1000f; private static final float PV_PANEL_NOMINAL_RAINING = 500f; - public static final long TIME_BETWEEN_UPDATES = 10; + public static final long TIME_BETWEEN_UPDATES = 20; @@ -30,21 +32,6 @@ public class SmartControl { private FloatDataPoint coalAmount; - private void defineDataPoints(){ - clock = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("CLOCK_FLOAT"); - battChrg = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("BATT_CHRG_FLOAT"); - battPwrIn = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("BATT_P_FLOAT"); - remoteCoalSp = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_COAL_SP"); - remoteFactorySp = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_FACTORY_SP"); - coalAmount = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("COAL_AMOUNT"); - gridVoltage = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("GRID_U_FLOAT"); - } - - float getValue(FloatDataPoint fdp){ - if(fdp == null) return 0f; - return fdp.getValue(); - } - // Emergency data points private FloatDataPoint gridVoltage; @@ -53,16 +40,45 @@ public class SmartControl { private float igpCoalAmount = 0f; // Time variables - private int day = 0; - private float previousTime; - final float kpiFactory = 1f; - final float kpiCoal = 1f; - + private int day = 2; // TODO : Change to 1 + private boolean dayChanged = false; + private float previousCoalAmount = 0f; + private float initialTime; + final float kpiFactory = 0.5f; + final float kpiCoal = 0.5f; + final float kpiCoalBatt = 0.8f; + private void defineDataPoints(){ + do { + try { + Thread.sleep(20); + } catch (InterruptedException e) { + e.printStackTrace(); + } + clock = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("CLOCK_FLOAT"); + battChrg = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("BATT_CHRG_FLOAT"); + battPwrIn = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("BATT_P_FLOAT"); + remoteCoalSp = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_COAL_SP"); + remoteFactorySp = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_FACTORY_SP"); + coalAmount = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("COAL_AMOUNT"); + gridVoltage = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("GRID_U_FLOAT"); + System.out.println("Test if data points are defined"); + } while (!testIfDataPointsAreDefined()); + } + private boolean testIfDataPointsAreDefined(){ + if(clock == null) return false; + if(battChrg == null) return false; + if(battPwrIn == null) return false; + if(remoteCoalSp == null) return false; + if(remoteFactorySp == null) return false; + if(coalAmount == null) return false; + if(gridVoltage == null) return false; + return true; + } private float getTimeOfTheDay(){ - float timeOfTheDay = getValue(clock); + float timeOfTheDay = clock.getValue(); timeOfTheDay %= 1; timeOfTheDay *= 24; return timeOfTheDay; @@ -74,9 +90,9 @@ public class SmartControl { FloatDataPoint wind = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("WIND_P_FLOAT"); FloatDataPoint coal = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("COAL_P_FLOAT"); - producerPower += getValue(solar); - producerPower += getValue(wind); - producerPower += getValue(coal); + producerPower += solar.getValue(); + producerPower += wind.getValue(); + producerPower += coal.getValue(); return producerPower; } @@ -87,9 +103,9 @@ public class SmartControl { FloatDataPoint factory = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("FACTORY_P_FLOAT"); FloatDataPoint bunker = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("BUNKER_P_FLOAT"); - consumerPower += getValue(home); - consumerPower += getValue(factory); - consumerPower += getValue(bunker); + consumerPower += home.getValue(); + consumerPower += factory.getValue(); + consumerPower += bunker.getValue(); return consumerPower; } @@ -97,23 +113,23 @@ public class SmartControl { boolean gridIsFine = true; // Grid voltage is too high - if(getValue(gridVoltage) > (GRID_VOLTAGE_MAX-GRID_VOLTAGE_TOLERANCE)) { + if(gridVoltage.getValue() > (GRID_VOLTAGE_MAX-GRID_VOLTAGE_TOLERANCE)) { gridIsFine = false; new BooleanDataPoint("SOLAR_CONNECT_ST", true).setValue(false); new BooleanDataPoint("WIND_CONNECT_ST", true).setValue(false); remoteCoalSp.setValue(0f); - if(getValue(gridVoltage) > GRID_VOLTAGE_MAX) { + if(gridVoltage.getValue() > GRID_VOLTAGE_MAX) { remoteFactorySp.setValue(1f); } } // Grid voltage is too low - if(getValue(gridVoltage) < (GRID_VOLTAGE_MIN+GRID_VOLTAGE_TOLERANCE)) { + if(gridVoltage.getValue() < (GRID_VOLTAGE_MIN+GRID_VOLTAGE_TOLERANCE)) { gridIsFine = false; new BooleanDataPoint("SOLAR_CONNECT_ST", true).setValue(true); new BooleanDataPoint("WIND_CONNECT_ST", true).setValue(true); remoteCoalSp.setValue(1f); - if(getValue(gridVoltage) < GRID_VOLTAGE_MIN) { + if(gridVoltage.getValue() < GRID_VOLTAGE_MIN) { remoteFactorySp.setValue(0f); } } @@ -176,57 +192,96 @@ public class SmartControl { default: break; } - igpCoalAmountForTheDay += day; + igpCoalAmountForTheDay += (3-day); igpCoalAmountForTheDay /= 3f; + igpCoalAmount = igpCoalAmountForTheDay; } public SmartControl() { - defineDataPoints(); - - previousTime = getTimeOfTheDay(); // start the solar and wind power plants new BooleanDataPoint("REMOTE_SOLAR_SW", true).setValue(true); new BooleanDataPoint("REMOTE_WIND_SW", true).setValue(true); + new FloatDataPoint("REMOTE_COAL_SP", true).setValue(0f); + new FloatDataPoint("REMOTE_FACTORY_SP", true).setValue(0f); + defineDataPoints(); + + initialTime = getTimeOfTheDay(); } public boolean run() { - defineDataPoints(); - float spCoal = getValue(remoteCoalSp); - float spFactory = getValue(remoteFactorySp); + float spCoal = remoteCoalSp.getValue(); + float spFactory = remoteFactorySp.getValue(); - if (getTimeOfTheDay() < previousTime) { - previousTime = getTimeOfTheDay(); + if (getTimeOfTheDay() < 1f && !dayChanged) { + dayChanged = true; day++; - day %= 3; + } + if (getPeriodOfDay() > 23f) { + dayChanged = false; + } + if(coalAmount.getValue() > previousCoalAmount) { + day = 1; } defineIGPbatteryLevel(); defineIGPcoalAmount(day); - if (getValue(battChrg) < igpBatteryLevel) { - spFactory -= (igpBatteryLevel - getValue(battChrg)) * kpiFactory; - spCoal += (igpBatteryLevel - getValue(battChrg)) * kpiCoal; + new FloatDataPoint("IGP_BATTERY_LEVEL", true).setValue(igpBatteryLevel); + new FloatDataPoint("IGP_COAL_AMOUNT", true).setValue(igpCoalAmount); + + String debug = "Day " + day + " - "; + //debug += "IGP battery level: " + igpBatteryLevel; + //debug += " IGP coal amount: " + igpCoalAmount; + // debug += " - "; + + + float battDiff = battChrg.getValue() - igpBatteryLevel; + new FloatDataPoint("BATT_DIFF", true).setValue(battDiff); + debug += "Batt. diff.: " + battDiff + " - "; + + float igpEnergyBattery = battDiff * BATTERY_POWER_MAX / 0.4f; // Over energy in battery + new FloatDataPoint("IGP_ENERGY_BATTERY", true).setValue(igpEnergyBattery); + debug += "IGP en. batt.: " + igpEnergyBattery + " - "; + + float powerDiff = getProducerPower() - getConsumerPower(); + new FloatDataPoint("POWER_DIFF", true).setValue(powerDiff); + debug += "Power diff: " + powerDiff + " - "; + + float balance = powerDiff + igpEnergyBattery; // Energy to use + new FloatDataPoint("BALANCE", true).setValue(balance); + debug += "Balance: " + balance + " - "; + + float coalDiff = coalAmount.getValue() - igpCoalAmount; // Over coal in storage + new FloatDataPoint("COAL_DIFF", true).setValue(coalDiff); + //debug += "Coal diff.: " + coalDiff + " - "; + + + if(balance < 0){ // Produce more energy or consume less + if(coalDiff > 0){ // Produce more energy + spCoal += kpiCoal * (balance / COAL_POWER_MAX); + debug += "Produce more energy"; + } else { // Consume less energy + spFactory -= kpiFactory * (balance / FACTORY_POWER_MAX); + debug += "Consume less energy"; + } + } else { // Produce less energy or consume more + if(coalDiff > 0){ // Produce less energy + spCoal -= kpiCoal * (balance / COAL_POWER_MAX); + debug += "Produce less energy"; + } else { // Consume more energy + spFactory += kpiFactory * (balance / FACTORY_POWER_MAX); + debug += "Consume more energy"; + } + } - if (getValue(battChrg) > igpBatteryLevel) { - spFactory += (getValue(battChrg) - igpBatteryLevel) * kpiFactory; - spCoal -= (getValue(battChrg) - igpBatteryLevel) * kpiCoal; - } - if (getValue(coalAmount) < igpCoalAmount) { - spFactory -= (igpCoalAmount - getValue(coalAmount)) * kpiFactory; - spCoal += (igpCoalAmount - getValue(coalAmount)) * kpiCoal; - } - if (getValue(coalAmount) > igpCoalAmount) { - spFactory += (getValue(coalAmount) - igpCoalAmount) * kpiFactory; - spCoal -= (getValue(coalAmount) - igpCoalAmount) * kpiCoal; - } if (spFactory > 1f) spFactory = 1f; if (spFactory < 0f) spFactory = 0f; @@ -236,6 +291,8 @@ public class SmartControl { remoteFactorySp.setValue(spFactory); remoteCoalSp.setValue(spCoal); + System.out.println(debug); + return checkIfGridIsFine(); } } From 4d428fe301df0bba2dcb61c76b3ca04bfe81ad80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 13 Jun 2023 06:32:08 +0200 Subject: [PATCH 5/6] pretty bad regulation, but won't collapse --- src/main/java/ch/hevs/isi/SmartControl.java | 34 +++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/ch/hevs/isi/SmartControl.java b/src/main/java/ch/hevs/isi/SmartControl.java index c63209d..b3846a6 100644 --- a/src/main/java/ch/hevs/isi/SmartControl.java +++ b/src/main/java/ch/hevs/isi/SmartControl.java @@ -19,7 +19,7 @@ public class SmartControl { private static final float PV_PANEL_NOMINAL = 1000f; private static final float PV_PANEL_NOMINAL_RAINING = 500f; - public static final long TIME_BETWEEN_UPDATES = 20; + public static final long TIME_BETWEEN_UPDATES = 100; @@ -40,12 +40,12 @@ public class SmartControl { private float igpCoalAmount = 0f; // Time variables - private int day = 2; // TODO : Change to 1 + private int day = 1; private boolean dayChanged = false; private float previousCoalAmount = 0f; private float initialTime; - final float kpiFactory = 0.5f; - final float kpiCoal = 0.5f; + final float kpiFactory = 0.1f; + final float kpiCoal = 0.1f; final float kpiCoalBatt = 0.8f; private void defineDataPoints(){ @@ -62,8 +62,8 @@ public class SmartControl { remoteFactorySp = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_FACTORY_SP"); coalAmount = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("COAL_AMOUNT"); gridVoltage = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("GRID_U_FLOAT"); - System.out.println("Test if data points are defined"); } while (!testIfDataPointsAreDefined()); + System.out.println("Data points defined"); } private boolean testIfDataPointsAreDefined(){ @@ -218,16 +218,18 @@ public class SmartControl { float spCoal = remoteCoalSp.getValue(); float spFactory = remoteFactorySp.getValue(); - if (getTimeOfTheDay() < 1f && !dayChanged) { + if ((getTimeOfTheDay() < 0.5f) && !dayChanged) { dayChanged = true; day++; } - if (getPeriodOfDay() > 23f) { + if (getTimeOfTheDay() > 23f) { dayChanged = false; } if(coalAmount.getValue() > previousCoalAmount) { + previousCoalAmount = coalAmount.getValue(); day = 1; } + defineIGPbatteryLevel(); defineIGPcoalAmount(day); @@ -260,26 +262,34 @@ public class SmartControl { new FloatDataPoint("COAL_DIFF", true).setValue(coalDiff); //debug += "Coal diff.: " + coalDiff + " - "; - if(balance < 0){ // Produce more energy or consume less if(coalDiff > 0){ // Produce more energy spCoal += kpiCoal * (balance / COAL_POWER_MAX); + spFactory -= kpiFactory * (balance / FACTORY_POWER_MAX); debug += "Produce more energy"; } else { // Consume less energy spFactory -= kpiFactory * (balance / FACTORY_POWER_MAX); + spCoal += kpiCoal * (balance / COAL_POWER_MAX); debug += "Consume less energy"; } } else { // Produce less energy or consume more - if(coalDiff > 0){ // Produce less energy + if(coalDiff < 0){ // Produce less energy spCoal -= kpiCoal * (balance / COAL_POWER_MAX); + spFactory += kpiFactory * (balance / FACTORY_POWER_MAX); debug += "Produce less energy"; } else { // Consume more energy spFactory += kpiFactory * (balance / FACTORY_POWER_MAX); + spCoal -= kpiCoal * (balance / COAL_POWER_MAX); debug += "Consume more energy"; } - } + FloatDataPoint solar = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SOLAR_P_FLOAT"); + float foo = (1000f- solar.getValue()) / 1000f; + + if(spCoal > foo) spCoal = foo; + + @@ -288,8 +298,8 @@ public class SmartControl { if (spCoal > 1f) spCoal = 1f; if (spCoal < 0f) spCoal = 0f; - remoteFactorySp.setValue(spFactory); - remoteCoalSp.setValue(spCoal); + new FloatDataPoint("REMOTE_FACTORY_SP", true).setValue(spFactory); + new FloatDataPoint("REMOTE_COAL_SP", true).setValue(spCoal); System.out.println(debug); From b7aac5956493548b798ac5c28bba366e3752c0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Wed, 14 Jun 2023 10:10:59 +0200 Subject: [PATCH 6/6] correct regulation just for survive --- .../java/ch/hevs/isi/MinecraftController.java | 26 +-- src/main/java/ch/hevs/isi/SmartControl.java | 155 +++--------------- 2 files changed, 40 insertions(+), 141 deletions(-) diff --git a/src/main/java/ch/hevs/isi/MinecraftController.java b/src/main/java/ch/hevs/isi/MinecraftController.java index a01547e..2aec9fd 100644 --- a/src/main/java/ch/hevs/isi/MinecraftController.java +++ b/src/main/java/ch/hevs/isi/MinecraftController.java @@ -1,5 +1,6 @@ package ch.hevs.isi; +import ch.hevs.isi.core.BooleanDataPoint; import ch.hevs.isi.core.DataPoint; import ch.hevs.isi.core.FloatDataPoint; import ch.hevs.isi.db.DatabaseConnector; @@ -118,18 +119,20 @@ public class MinecraftController { SmartControl smartControl = new SmartControl(); System.out.println("SmartControl is running"); while (true) { - boolean stateGrid = true; - try { - stateGrid = smartControl.run(); - } catch (Exception e) { - e.printStackTrace(); - } - if(!stateGrid) { - System.out.println("Grid is not fine"); - //System.exit(0); - } else { - //System.out.println("Grid is fine"); + BooleanDataPoint man = (BooleanDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_MAN_SW"); + boolean autoMode = true; + if(man != null) autoMode = !man.getValue(); + + if (autoMode){ + boolean stateGrid = true; + try { + stateGrid = smartControl.run(); + } catch (Exception e) { + e.printStackTrace(); + } + if(!stateGrid) System.out.println("Grid is not fine"); } + FloatDataPoint score = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SCORE"); if(score != null) { if(score.getValue() >= 100) { @@ -137,6 +140,7 @@ public class MinecraftController { System.exit(0); } } + Thread.sleep(SmartControl.TIME_BETWEEN_UPDATES); } diff --git a/src/main/java/ch/hevs/isi/SmartControl.java b/src/main/java/ch/hevs/isi/SmartControl.java index b3846a6..9085957 100644 --- a/src/main/java/ch/hevs/isi/SmartControl.java +++ b/src/main/java/ch/hevs/isi/SmartControl.java @@ -5,21 +5,12 @@ import ch.hevs.isi.core.DataPoint; import ch.hevs.isi.core.FloatDataPoint; public class SmartControl { - - private static final float BATTERY_LEVEL_LOW = 0.4f; - private static final float BATTERY_LEVEL_HIGH = 0.85f; - private static final float BATTERY_POWER_MAX = 1000f; - private static final float COAL_AMOUNT_DAY = (1f-0.2f)/3f; - private static final float COAL_POWER_MAX = 500f; - private static final float FACTORY_POWER_MAX = 1000f; private static final float GRID_VOLTAGE_MIN = 750f; - private static final float GRID_VOLTAGE_MAX = 900f; - private static final float GRID_VOLTAGE_NOMINAL = 800f; + private static final float GRID_VOLTAGE_MAX = 875f; private static final float GRID_VOLTAGE_TOLERANCE = 25f; - private static final float PV_PANEL_NOMINAL = 1000f; - private static final float PV_PANEL_NOMINAL_RAINING = 500f; - public static final long TIME_BETWEEN_UPDATES = 100; + private float spCoal = 0; + private float spFactory = 0; @@ -37,16 +28,13 @@ public class SmartControl { // Ideal goal points variables private float igpBatteryLevel = 0f; - private float igpCoalAmount = 0f; // Time variables private int day = 1; private boolean dayChanged = false; private float previousCoalAmount = 0f; - private float initialTime; final float kpiFactory = 0.1f; final float kpiCoal = 0.1f; - final float kpiCoalBatt = 0.8f; private void defineDataPoints(){ do { @@ -84,20 +72,18 @@ public class SmartControl { return timeOfTheDay; } - private float getProducerPower(){ + private float getUnregProducerPower(){ float producerPower = 0f; FloatDataPoint solar = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SOLAR_P_FLOAT"); FloatDataPoint wind = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("WIND_P_FLOAT"); - FloatDataPoint coal = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("COAL_P_FLOAT"); producerPower += solar.getValue(); producerPower += wind.getValue(); - producerPower += coal.getValue(); return producerPower; } - private float getConsumerPower(){ + private float getUnregConsumerPower(){ float consumerPower = 0f; FloatDataPoint home = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("HOME_P_FLOAT"); FloatDataPoint factory = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("FACTORY_P_FLOAT"); @@ -150,55 +136,6 @@ public class SmartControl { return periodOfDay; } - private void defineIGPbatteryLevel(){ - - switch (getPeriodOfDay()){ - case 1: // Night - if(getTimeOfTheDay() < 5f) igpBatteryLevel = BATTERY_LEVEL_HIGH-0.5f; - else igpBatteryLevel = BATTERY_LEVEL_LOW+0.2f; - break; - case 2: // Morning - igpBatteryLevel = BATTERY_LEVEL_LOW; - break; - case 3: // Afternoon - igpBatteryLevel = BATTERY_LEVEL_HIGH; - break; - case 4: // Evening - if(getTimeOfTheDay() < 21f) igpBatteryLevel = BATTERY_LEVEL_HIGH-0.2f; - else igpBatteryLevel = BATTERY_LEVEL_HIGH-0.4f; - break; - default: - break; - } - } - - private void defineIGPcoalAmount(int day){ - float igpCoalAmountForTheDay = 1f; - switch (getPeriodOfDay()){ - case 1: // Night - if(getTimeOfTheDay() < 5f) igpCoalAmountForTheDay = 0.93f; - else igpCoalAmountForTheDay = 0.8f; - break; - case 2: // Morning - igpCoalAmountForTheDay = 0.7f; - break; - case 3: // Afternoon - igpCoalAmountForTheDay = 0.6f; - break; - case 4: // Evening - if(getTimeOfTheDay() < 21f) igpCoalAmountForTheDay = 0.5f; - else igpCoalAmountForTheDay = 0.3f; - break; - default: - break; - } - igpCoalAmountForTheDay += (3-day); - igpCoalAmountForTheDay /= 3f; - igpCoalAmount = igpCoalAmountForTheDay; - - - } - public SmartControl() { @@ -210,88 +147,46 @@ public class SmartControl { defineDataPoints(); - initialTime = getTimeOfTheDay(); - } public boolean run() { - float spCoal = remoteCoalSp.getValue(); - float spFactory = remoteFactorySp.getValue(); if ((getTimeOfTheDay() < 0.5f) && !dayChanged) { dayChanged = true; day++; } - if (getTimeOfTheDay() > 23f) { - dayChanged = false; - } + if (getTimeOfTheDay() > 23f) dayChanged = false; if(coalAmount.getValue() > previousCoalAmount) { previousCoalAmount = coalAmount.getValue(); day = 1; } - defineIGPbatteryLevel(); - defineIGPcoalAmount(day); - - new FloatDataPoint("IGP_BATTERY_LEVEL", true).setValue(igpBatteryLevel); - new FloatDataPoint("IGP_COAL_AMOUNT", true).setValue(igpCoalAmount); - String debug = "Day " + day + " - "; - //debug += "IGP battery level: " + igpBatteryLevel; - //debug += " IGP coal amount: " + igpCoalAmount; - // debug += " - "; - - float battDiff = battChrg.getValue() - igpBatteryLevel; - new FloatDataPoint("BATT_DIFF", true).setValue(battDiff); - debug += "Batt. diff.: " + battDiff + " - "; - - float igpEnergyBattery = battDiff * BATTERY_POWER_MAX / 0.4f; // Over energy in battery - new FloatDataPoint("IGP_ENERGY_BATTERY", true).setValue(igpEnergyBattery); - debug += "IGP en. batt.: " + igpEnergyBattery + " - "; - - float powerDiff = getProducerPower() - getConsumerPower(); - new FloatDataPoint("POWER_DIFF", true).setValue(powerDiff); - debug += "Power diff: " + powerDiff + " - "; - - float balance = powerDiff + igpEnergyBattery; // Energy to use - new FloatDataPoint("BALANCE", true).setValue(balance); - debug += "Balance: " + balance + " - "; - - float coalDiff = coalAmount.getValue() - igpCoalAmount; // Over coal in storage - new FloatDataPoint("COAL_DIFF", true).setValue(coalDiff); - //debug += "Coal diff.: " + coalDiff + " - "; - - if(balance < 0){ // Produce more energy or consume less - if(coalDiff > 0){ // Produce more energy - spCoal += kpiCoal * (balance / COAL_POWER_MAX); - spFactory -= kpiFactory * (balance / FACTORY_POWER_MAX); - debug += "Produce more energy"; - } else { // Consume less energy - spFactory -= kpiFactory * (balance / FACTORY_POWER_MAX); - spCoal += kpiCoal * (balance / COAL_POWER_MAX); - debug += "Consume less energy"; - } - } else { // Produce less energy or consume more - if(coalDiff < 0){ // Produce less energy - spCoal -= kpiCoal * (balance / COAL_POWER_MAX); - spFactory += kpiFactory * (balance / FACTORY_POWER_MAX); - debug += "Produce less energy"; - } else { // Consume more energy - spFactory += kpiFactory * (balance / FACTORY_POWER_MAX); - spCoal -= kpiCoal * (balance / COAL_POWER_MAX); - debug += "Consume more energy"; + if(battChrg.getValue()<0.45f){ + igpBatteryLevel = 0.45f; + spCoal = -(battChrg.getValue()-0.45f)*5 + 0.2f; + debug += "BattChrg < 0.45f - "; + } else { + if (getUnregProducerPower() < 500f) { + spCoal = 0.2f; } } - FloatDataPoint solar = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SOLAR_P_FLOAT"); - float foo = (1000f- solar.getValue()) / 1000f; - - if(spCoal > foo) spCoal = foo; - - + if(battChrg.getValue()>0.55f){ + igpBatteryLevel = 0.55f; + if(battChrg.getValue()>0.6f) spCoal -= (battChrg.getValue()-0.55f)*kpiCoal; + debug += "BattChrg > 0.55f"; + spFactory = (battChrg.getValue()-0.55f)*5; + } + if(battChrg.getValue()<0.55f){ + igpBatteryLevel = 0.55f; + spFactory += (battChrg.getValue()-0.55f)*kpiFactory; + debug += "BattChrg < 0.55f"; + } + new FloatDataPoint("IGP_BATTERY_LEVEL", true).setValue(igpBatteryLevel); if (spFactory > 1f) spFactory = 1f; if (spFactory < 0f) spFactory = 0f;