Hello again community!
I’m creating a package for my project using OpenEms and I require some help with the coding part.
I have now created a State Machine that does a simple discerning process : To turn on a diesel generator or not. The idea behind this is to use 2 values to compare: Forecasted power vs Actual active power. If the forecasted one is less than the actual power, then my diesel generator should turn on. The other way around leads to the diesel generator to be off, as expected.
Now, since I’m not a expert in programming in this language I’m having some hard time. The forecasted values for now will be simulated and loaded in a csv file. My question now is how should my state machine work to load this csv file.
I tried using the same concept that io.openems.edge.simulator uses, but I’m not sure about it.
Below is one of the States of my State Machine where it decides to change or not to the next state which is turning on or not the engine.
package io.openems.edge.dieselgenerator.statemachine;
import java.io.IOException;
import io.openems.common.exceptions.InvalidValueException;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.edge.common.startstop.StartStop;
import io.openems.edge.common.statemachine.StateHandler;
import io.openems.edge.dieselgenerator.DieselGenerator;
import io.openems.edge.dieselgenerator.statemachine.StateMachine.State;
import io.openems.edge.meter.api.SymmetricMeter;
import io.openems.edge.simulator.forecast.predefined.Config;
public class PredictionCheckHandler extends StateHandler<State,Context>{
private Config config;
// Gets the actual active power
private State predictionCheck(SymmetricMeter meter, CsvUtils data) throws InvalidValueException{
float actualActivePower = meter.getActivePower().getOrError();
//Here I'm trying to get the data from the csv, nonetheless I know that this returns me an array of data and not the specific one I require//
DataContainer forecastedPower = CsvUtils.readCsvFileFromResource(ForecastPredefined.class, this.config.source().filename,
this.config.format(), this.config.factor());
if(actualActivePower < forecastedPower) {
return State.START_ENGINE;
}else {
return State.PREDICTION_MISSMATCH;
}
}
@Override
protected State runAndGetNextState(Context context) throws OpenemsNamedException {
// TODO Auto-generated method stub
return null;
}
}
Any suggestions? I’d appreciate it a lot!
Regards