1
0

Merge branch 'smart' into main

This commit is contained in:
Rémi Heredero 2023-06-02 16:54:53 +02:00 committed by GitHub
commit 11b2d220c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 7 deletions

View File

@ -13,11 +13,8 @@ public class FieldConnector implements DataPointListener {
private static FieldConnector mySelf = null;
private FieldConnector(){
initialize("LocalHost",1502, "C:/Nils/Hesso/4_Semester/SIN/Minecraft_Electrical_Age_Project/ModbusMap.csv");
// Subscribe to the update of DataPoints
DataPointListener.subscribeUpdate(this);
}
/**
@ -79,9 +76,11 @@ 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);
@ -100,6 +99,7 @@ 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);
}
}

View File

@ -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
*
*/
}
}