Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Hybrid Modeling - Control Electric Switch by Local Parameter

Hybrid Modeling - Control Electric Switch by Local Parameter

I have a small electric model of a solar panel charging a battery and want to extend it by a rule to stop charging when the state of charge hits 80% and to restart charging when the state of charge falls below 20%.
For this i introduced a local variable representing whether the battery shall charge or not. Using when and reinit() I can flip the variable, but I don't see a way to use this variable as input to an electric switch. A boolean expression only delivers the static value at compilation time. See below the code of my model.

My question is: how can i realize this switch?

Code:


model SolarBatteryChargeSwitch "Ein einfacher Schaltkreis mit einem Solarpanel und einer Batterie."
  parameter Real irradianceParam = 500;
  Modelica.Electrical.Analog.Basic.Ground ground annotation(
    Placement(visible = true, transformation(origin = {-32, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  PhotoVoltaics.Components.SimplePhotoVoltaics.SimpleModule module(moduleData = moduleData, useConstantIrradiance = false)  annotation(
    Placement(visible = true, transformation(origin = {0, 10}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
  parameter PhotoVoltaics.Records.ModuleData moduleData(nb = 1, ns = 20)  annotation(
    Placement(visible = true, transformation(origin = {20, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor resistor(R = 20)  annotation(
    Placement(visible = true, transformation(origin = {42, -30}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Sensors.PowerSensor powerSensor annotation(
    Placement(visible = true, transformation(origin = {42, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  parameter Modelica.Electrical.Batteries.ParameterRecords.CellData cellData1(Idis = 0.3,OCVmax = 4.2, OCVmin = 2.5, Qnom (displayUnit = "C") = 18000, Ri = cellData1.OCVmax / 1200) annotation(
    Placement(visible = true, transformation(extent = {{36, 34}, {56, 54}}, rotation = 0)));
  Modelica.Blocks.Sources.CombiTimeTable combiTimeTable(fileName = "C:/dev/git/sig-energy-mobility/Examples/testdata.txt", tableName = "tab1", tableOnFile = true, verboseRead = true)  annotation(
    Placement(visible = true, transformation(origin = {-28, 48}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Real charge = 1;
  Modelica.Electrical.Batteries.BatteryStacksWithSensors.Cell cell(SOC0 = 0.5, cellData = cellData1)  annotation(
    Placement(visible = true, transformation(origin = {-14, -30}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
equation
  connect(ground.p, module.n) annotation(
    Line(points = {{-32, 10}, {-10, 10}}, color = {0, 0, 255}));
  connect(module.p, powerSensor.pv) annotation(
    Line(points = {{10, 10}, {42, 10}}, color = {0, 0, 255}));
  connect(powerSensor.nc, resistor.p) annotation(
    Line(points = {{52, 0}, {52, -30}}, color = {0, 0, 255}));
  connect(powerSensor.nv, ground.p) annotation(
    Line(points = {{42, -10}, {-32, -10}, {-32, 10}}, color = {0, 0, 255}));
  connect(powerSensor.pv, powerSensor.pc) annotation(
    Line(points = {{42, 10}, {32, 10}, {32, 0}}, color = {0, 0, 255}));
  connect(combiTimeTable.y[1], module.variableIrradiance) annotation(
    Line(points = {{-16, 48}, {0, 48}, {0, 22}}, color = {0, 0, 127}));
  when cell.SOC > 0.8 and charge == 1 then
    reinit(charge, 0);
  end when;
  when cell.SOC < 0.2 and charge == 0 then
    reinit(charge, 1);
  end when;
  connect(resistor.n, cell.p) annotation(
    Line(points = {{32, -30}, {-4, -30}}, color = {0, 0, 255}));
  connect(cell.n, ground.p) annotation(
    Line(points = {{-24, -30}, {-32, -30}, {-32, 10}}, color = {0, 0, 255}));
  annotation(
    uses(Modelica(version = "4.0.0"), PhotoVoltaics(version = "2.0.0")),
    Documentation(info="<html>
    <p>Ein einfacher Schaltkreis der ein Solarpanel mit einer Batterie verbindet und den Lade- und Entladevorgang analysiert.</p>
    <p>Solar Irradiance modelled as sinc+abs.</p>
    <p>Panel has 20 cells and 1 diode. Every else left default.</p>
    <p>Battery has 5Ah and self-discharges with 0.3A.</p>
    <p>Contact: <a href='mailto:sebastian.goetz1@tu-dresden.de'>Dr. Sebastian Götz</a></html>"),
    experiment(StopTime=25200,
      Interval=10,
      Tolerance=1e-06),
  __OpenModelica_simulationFlags(lv = "LOG_STATS", s = "dassl"));
end SolarBatteryChargeSwitch;

I'm using the PhotoVoltaics library from Christian Kral: https://github.com/christiankral/PhotoVoltaics

Re: Hybrid Modeling - Control Electric Switch by Local Parameter

I found a way, but aren't really satisfied.
My solution is:
- subclass Battery (Cell) and add the state of charge as RealOutput.
- subclass IdealSwitch and add state of charge as RealInput.
- use these subclasses and connect them accordingly.

See the code for the details: Code.zip

My problem with the solution is that it does not realize stateful behavior. Once the battery hits 80% SOC the battery shall stop charging until it falls below 20% due to discharging. Currently it simply stays at 80% and if you add a consumer the simulation runs forever as the switch flips at every crossing of 80%.

Attachments:

Re: Hybrid Modeling - Control Electric Switch by Local Parameter

Hey there,

You could use the hysteresis block from the Modelica Standard Library:

https://doc.modelica.org/Modelica%203.2 … resis.html

You also have the 'on/off controller':

https://doc.modelica.org/Modelica%203.2 … oller.html

There are 0 guests and 0 other users also viewing this topic
You are here: