1
0

correct regulation just for survive

This commit is contained in:
Rémi Heredero 2023-06-14 10:10:59 +02:00
parent 4d428fe301
commit b7aac59564
2 changed files with 40 additions and 141 deletions

View File

@ -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) {
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");
//System.exit(0);
} else {
//System.out.println("Grid is fine");
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);
}

View File

@ -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);
String debug = "Day " + day + " - ";
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;
}
}
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);
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";
}
}
FloatDataPoint solar = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SOLAR_P_FLOAT");
float foo = (1000f- solar.getValue()) / 1000f;
if(spCoal > foo) spCoal = foo;
if (spFactory > 1f) spFactory = 1f;
if (spFactory < 0f) spFactory = 0f;