correct regulation just for survive
This commit is contained in:
parent
4d428fe301
commit
b7aac59564
@ -1,5 +1,6 @@
|
|||||||
package ch.hevs.isi;
|
package ch.hevs.isi;
|
||||||
|
|
||||||
|
import ch.hevs.isi.core.BooleanDataPoint;
|
||||||
import ch.hevs.isi.core.DataPoint;
|
import ch.hevs.isi.core.DataPoint;
|
||||||
import ch.hevs.isi.core.FloatDataPoint;
|
import ch.hevs.isi.core.FloatDataPoint;
|
||||||
import ch.hevs.isi.db.DatabaseConnector;
|
import ch.hevs.isi.db.DatabaseConnector;
|
||||||
@ -118,18 +119,20 @@ public class MinecraftController {
|
|||||||
SmartControl smartControl = new SmartControl();
|
SmartControl smartControl = new SmartControl();
|
||||||
System.out.println("SmartControl is running");
|
System.out.println("SmartControl is running");
|
||||||
while (true) {
|
while (true) {
|
||||||
boolean stateGrid = true;
|
BooleanDataPoint man = (BooleanDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_MAN_SW");
|
||||||
try {
|
boolean autoMode = true;
|
||||||
stateGrid = smartControl.run();
|
if(man != null) autoMode = !man.getValue();
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
if (autoMode){
|
||||||
}
|
boolean stateGrid = true;
|
||||||
if(!stateGrid) {
|
try {
|
||||||
System.out.println("Grid is not fine");
|
stateGrid = smartControl.run();
|
||||||
//System.exit(0);
|
} catch (Exception e) {
|
||||||
} else {
|
e.printStackTrace();
|
||||||
//System.out.println("Grid is fine");
|
}
|
||||||
|
if(!stateGrid) System.out.println("Grid is not fine");
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatDataPoint score = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SCORE");
|
FloatDataPoint score = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SCORE");
|
||||||
if(score != null) {
|
if(score != null) {
|
||||||
if(score.getValue() >= 100) {
|
if(score.getValue() >= 100) {
|
||||||
@ -137,6 +140,7 @@ public class MinecraftController {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(SmartControl.TIME_BETWEEN_UPDATES);
|
Thread.sleep(SmartControl.TIME_BETWEEN_UPDATES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,21 +5,12 @@ import ch.hevs.isi.core.DataPoint;
|
|||||||
import ch.hevs.isi.core.FloatDataPoint;
|
import ch.hevs.isi.core.FloatDataPoint;
|
||||||
|
|
||||||
public class SmartControl {
|
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_MIN = 750f;
|
||||||
private static final float GRID_VOLTAGE_MAX = 900f;
|
private static final float GRID_VOLTAGE_MAX = 875f;
|
||||||
private static final float GRID_VOLTAGE_NOMINAL = 800f;
|
|
||||||
private static final float GRID_VOLTAGE_TOLERANCE = 25f;
|
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;
|
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
|
// Ideal goal points variables
|
||||||
private float igpBatteryLevel = 0f;
|
private float igpBatteryLevel = 0f;
|
||||||
private float igpCoalAmount = 0f;
|
|
||||||
|
|
||||||
// Time variables
|
// Time variables
|
||||||
private int day = 1;
|
private int day = 1;
|
||||||
private boolean dayChanged = false;
|
private boolean dayChanged = false;
|
||||||
private float previousCoalAmount = 0f;
|
private float previousCoalAmount = 0f;
|
||||||
private float initialTime;
|
|
||||||
final float kpiFactory = 0.1f;
|
final float kpiFactory = 0.1f;
|
||||||
final float kpiCoal = 0.1f;
|
final float kpiCoal = 0.1f;
|
||||||
final float kpiCoalBatt = 0.8f;
|
|
||||||
|
|
||||||
private void defineDataPoints(){
|
private void defineDataPoints(){
|
||||||
do {
|
do {
|
||||||
@ -84,20 +72,18 @@ public class SmartControl {
|
|||||||
return timeOfTheDay;
|
return timeOfTheDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getProducerPower(){
|
private float getUnregProducerPower(){
|
||||||
float producerPower = 0f;
|
float producerPower = 0f;
|
||||||
FloatDataPoint solar = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SOLAR_P_FLOAT");
|
FloatDataPoint solar = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("SOLAR_P_FLOAT");
|
||||||
FloatDataPoint wind = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("WIND_P_FLOAT");
|
FloatDataPoint wind = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("WIND_P_FLOAT");
|
||||||
FloatDataPoint coal = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("COAL_P_FLOAT");
|
|
||||||
|
|
||||||
producerPower += solar.getValue();
|
producerPower += solar.getValue();
|
||||||
producerPower += wind.getValue();
|
producerPower += wind.getValue();
|
||||||
producerPower += coal.getValue();
|
|
||||||
|
|
||||||
return producerPower;
|
return producerPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getConsumerPower(){
|
private float getUnregConsumerPower(){
|
||||||
float consumerPower = 0f;
|
float consumerPower = 0f;
|
||||||
FloatDataPoint home = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("HOME_P_FLOAT");
|
FloatDataPoint home = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("HOME_P_FLOAT");
|
||||||
FloatDataPoint factory = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("FACTORY_P_FLOAT");
|
FloatDataPoint factory = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("FACTORY_P_FLOAT");
|
||||||
@ -150,55 +136,6 @@ public class SmartControl {
|
|||||||
return periodOfDay;
|
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() {
|
public SmartControl() {
|
||||||
|
|
||||||
@ -210,88 +147,46 @@ public class SmartControl {
|
|||||||
|
|
||||||
defineDataPoints();
|
defineDataPoints();
|
||||||
|
|
||||||
initialTime = getTimeOfTheDay();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean run() {
|
public boolean run() {
|
||||||
float spCoal = remoteCoalSp.getValue();
|
|
||||||
float spFactory = remoteFactorySp.getValue();
|
|
||||||
|
|
||||||
if ((getTimeOfTheDay() < 0.5f) && !dayChanged) {
|
if ((getTimeOfTheDay() < 0.5f) && !dayChanged) {
|
||||||
dayChanged = true;
|
dayChanged = true;
|
||||||
day++;
|
day++;
|
||||||
}
|
}
|
||||||
if (getTimeOfTheDay() > 23f) {
|
if (getTimeOfTheDay() > 23f) dayChanged = false;
|
||||||
dayChanged = false;
|
|
||||||
}
|
|
||||||
if(coalAmount.getValue() > previousCoalAmount) {
|
if(coalAmount.getValue() > previousCoalAmount) {
|
||||||
previousCoalAmount = coalAmount.getValue();
|
previousCoalAmount = coalAmount.getValue();
|
||||||
day = 1;
|
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 + " - ";
|
String debug = "Day " + day + " - ";
|
||||||
//debug += "IGP battery level: " + igpBatteryLevel;
|
|
||||||
//debug += " IGP coal amount: " + igpCoalAmount;
|
|
||||||
// debug += " - ";
|
|
||||||
|
|
||||||
|
if(battChrg.getValue()<0.45f){
|
||||||
float battDiff = battChrg.getValue() - igpBatteryLevel;
|
igpBatteryLevel = 0.45f;
|
||||||
new FloatDataPoint("BATT_DIFF", true).setValue(battDiff);
|
spCoal = -(battChrg.getValue()-0.45f)*5 + 0.2f;
|
||||||
debug += "Batt. diff.: " + battDiff + " - ";
|
debug += "BattChrg < 0.45f - ";
|
||||||
|
} else {
|
||||||
float igpEnergyBattery = battDiff * BATTERY_POWER_MAX / 0.4f; // Over energy in battery
|
if (getUnregProducerPower() < 500f) {
|
||||||
new FloatDataPoint("IGP_ENERGY_BATTERY", true).setValue(igpEnergyBattery);
|
spCoal = 0.2f;
|
||||||
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");
|
if(battChrg.getValue()>0.55f){
|
||||||
float foo = (1000f- solar.getValue()) / 1000f;
|
igpBatteryLevel = 0.55f;
|
||||||
|
if(battChrg.getValue()>0.6f) spCoal -= (battChrg.getValue()-0.55f)*kpiCoal;
|
||||||
if(spCoal > foo) spCoal = foo;
|
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 > 1f) spFactory = 1f;
|
||||||
if (spFactory < 0f) spFactory = 0f;
|
if (spFactory < 0f) spFactory = 0f;
|
||||||
|
Reference in New Issue
Block a user