Merge branch 'smart' into main
This commit is contained in:
commit
11b2d220c6
@ -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);
|
||||
}
|
||||
}
|
||||
|
64
src/main/java/ch/hevs/isi/field/SmartControl.java
Normal file
64
src/main/java/ch/hevs/isi/field/SmartControl.java
Normal 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
|
||||
*
|
||||
*/
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user