I'm trying to control a grid connected photovoltaic system based on the grid voltage. The idea is this: when the grid voltage rises above VMax, I want to switch off the system for timeOff. When timeOff has passed, i want to switch on again, but only when the grid voltage is lower than VMax.
I currently have two implementations; both are creating many events and i wonder if there's a more efficient way. This is how it is implemented now:
package Foo
model PVControl1 "Generating most events"
parameter Real VMax=253;
parameter Real timeOff=60;
input Real P_init "uncontrolled power";
input Real VGrid;
Real P_final "controlled power";
Boolean switch (start = true) "if true, system is producing";
discrete Real restartTime (start=-1, fixed=true)
"system is off until time>restartTime";
equation
when {VGrid > VMax, time > pre(restartTime)} then
if VGrid > VMax then
switch = false;
restartTime = time + timeOff;
else
switch = true;
restartTime = -1;
end if;
end when;
if pre(switch) then
P_final = P_init;
else
P_final = 0;
end if;
end PVControl1;
model PVControl2;
"Generating less events, but off-time is no multiple of timeOff"
parameter Real VMax=253;
parameter Real timeOff=60;
input Real P_init "uncontrolled power";
input Real VGrid;
Real P_final "controlled power";
discrete Real stopTime( start=-1-timeOff, fixed=true)
"system is off until time > stopTime + timeOff";
equation
when VGrid > VMax then
stopTime=time;
end when;
if noEvent(VGrid > VMax) or noEvent(time < stopTime + timeOff) then
P_final = 0;
else
P_final = P_init;
end if;
end PVControl2;
model TestPVControl;
"Simulate 1000s to get an idea"
PVControl pvControl2(P_init=4000, VGrid = 300*sin(time/100));
end TestPVControl;
end foo;
When run, I get 8 events with PVControl1, and 4 events with PVControl2. Looking at PVControl2, I actually need only an event at the moment where VGrid becomes larger than VMax. This would give only 2 events. The other 2 events are generated when VGrid drops below VMax again.
Is there a way to improve my model further?
Thanks,
Roel