1
0

Merge branch 'main' into improvement

This commit is contained in:
Rémi Heredero 2023-06-09 12:34:37 +02:00 committed by GitHub
commit de288176d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 0 deletions

View File

@ -15,6 +15,10 @@ public class FieldConnector implements DataPointListener {
private FieldConnector(){
initialize("LocalHost",1502, "src/main/resources/ModbusMap.csv");
// Subscribe to the update of DataPoints
DataPointListener.subscribeUpdate(this);
}
@ -78,9 +82,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); //connect to the modbus server
createRegister(pathToFile); //create the all needed modbus registers and save them in a map
startPeriodicalPolling(); //start periodical reading of the values
}
private void pushToField(String label, String value){
System.out.println("Field: " + label + " " + value);
@ -111,5 +117,6 @@ public class FieldConnector implements DataPointListener {
Timer pollTimer = new Timer(); //create a new timer,
PollTask pollTask = new PollTask(); //create a new task to do every period.
pollTimer.scheduleAtFixedRate(pollTask,0,100); //do the run-function of the polltask every period
}
}

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