Hysteresis - ChatteringControl

Gallery
Tutorial
Click on the image to view it full size

The Modelica By Example target code (using 'initial equation') is:


model ChatteringControl "A control strategy that will 'chatter'"
  type HeatCapacitance=Real(unit="J/K");
  type Temperature=Real(unit="K");
  type Heat=Real(unit="W");
  type Mass=Real(unit="kg");
  type HeatTransferCoefficient=Real(unit="W/K");
  Boolean heat "Indicates whether heater is on";
  parameter HeatCapacitance C=1.0;
  parameter HeatTransferCoefficient h=2.0;
  parameter Heat Qcapacity=25.0;
  parameter Temperature Tamb=285;
  parameter Temperature Tbar=295;
  Temperature T;
  Heat Q;
initial equation
  T = Tbar+5;
equation
  heat = T<Tbar;
  Q = if heat then Qcapacity else 0;
  C*der(T) = Q-h*(T-Tamb);
end ChatteringControl;

A HACK was required to get this SysPhS trail version working, because of this limitation:

MagicDraw/Cameo could not handle export of the following expression:


Q = if heat then Qcapacity else 0;

And as throughout this trail, a workaround was used to deal with:

The full exported Modelica code using a full if/then/else statement is:


model ChatteringControl
  ChatteringControl _ChatteringControl;
  model ChatteringControl
    Boolean heat;
    parameter HeatCapacitance c(start=1.0,fixed=true);
    parameter HeatTransferCoefficient h(start=2.0,fixed=true);
    parameter HeatRate qCapacity(start=25.0,fixed=true);
    parameter Temperature tAmb(start=285.0,fixed=true);
    parameter Temperature tBar(start=295.0,fixed=true);
    Temperature t(start=300.0,fixed=true);
    HeatRate q;
  equation
    heat=t<tBar;
    c*der(t)=q-h*(t-tAmb);
    if heat then
q=qCapacity;
else
q=0;
end if;
  end ChatteringControl;
  type HeatCapacitance=Real(unit="J/K");
  type HeatTransferCoefficient=Real(unit="W/K");
  type HeatRate=Real(unit="W");
  type Temperature=Real(unit="K");
end ChatteringControl;

Note the pedantic re-naming of Heat to HeatTransferRate, noting that 'heat' usually just refers to an energy.

It certainly does "chatter" when it runs, it takes ages in Wolfram SystemModeler's Simulation Center (grinds to a near halt) and it's hard to even zoom in on the plot. And zoom in, and zoom in, until you can finally see the "chatter" resolved as shown in the lower plot.


All of the rest of the Modelica By Example cases on the same Hysteresis page involve Modelica 'when/then' statements, which are not supported by MagicDraw+SysPhS-1.1, so they are skipped here.


Likewise, the examples under Synchronous Systems are skipped here because of lack of 'when/then' support.

Up next
Notes
Snippets (quotes/extracts)
Visit also
Visit also (backlinks)
Related slides (includes other tutorials)
Related slides (backlinks, includes other tutorials)
External links