I'm writing a controller for a heatingSystem that responds on the state of the electric grid in which the house of the heatingsystem is placed. I'm trying several controllers but the one that is giving me problems is the next.
I'm trying to write a model that takes into account the amount of renewable energy that is produced in the grid. When a certain treshold for the amount of energy going externally is met the heatingsystems should switch on (as to use the energy locally). It is a form of demand side management. The problem I'm having is that the moment the treshold the heatingsytems switches on. Which in turn means that the treshold isn't met anymore because the energy is used locally. The controller is represented by a boolean. If the treshold is met it is true otherwise false.
This is the part of the code I think is problematic:
algorithm
if CurrentGoingExternal > 5 then SwitchOn :=true;
elseif CurrentGoingExternal < 5 and pre(SwitchOn) then SwitchOn :=true;
elseif CurrentGoingExternal < 1 then SwitchOn :=false;
else SwitchOn :=false;
end if;
When simulating I get the error that the boolean can't figured out because meeting the treshold ensures heating switches on which ensures that the boolean becomes false within the same timeperiod. So I'm looking for a way to 'set or lock or whatever' the boolean to true from the moment the treshold is met untill the beginning of the next time period when it should be checked again. Even if within that timeperiod the treshold wouldn't be met because of the heatingsystems switched on at the beginnning.
I tried things like noEvent but that doesn't seem to work for continous problems.
Thankk for your help.
If I understand your question correctly, I think what you really want is hysteresis. You can see a detailed discussion in this chapter of Modelica by Example.