Modelica示例——离散事件

//50%占空比脉冲生成
within ModelicaByExample.DiscreteBehavior.PulseGenerator;
model PulseGenerator "A model that produces pulses at a fixed interval"
  type Time=Real(unit="s");
  parameter Time width=100e-3;
  Boolean pulse;
initial equation
  pulse = false;
equation
  when sample(width,width) then//形成50%占空比的脉冲
    pulse = not pre(pulse);
  end when;
end PulseGenerator;
 
 
//计数器
within ModelicaByExample.DiscreteBehavior.Counter;
model Counter "Counting samples"
  type Time = Real(unit="s");
  parameter Time interval=100e-3;
  Integer count;
initial equation
  count = 0;
equation
  when sample(interval, interval) then
    count = pre(count)+1;
  end when;
end Counter;
 
  
 
//采样保持
within ModelicaByExample.DiscreteBehavior.SpeedMeasurement;
model SampleAndHold "Measure speed and hold"
  extends BasicEquations.RotationalSMD.SecondOrderSystem;
  parameter Real sample_time(unit="s")=0.125;
  discrete Real omega1_measured;
equation
  when sample(0,sample_time) then
    omega1_measured = omega1;
  end when;
end SampleAndHold;
 
 
 
 
 
 
//Bang-Bang控制
within ModelicaByExample.DiscreteBehavior.Hysteresis;
model HysteresisControl "A control strategy that doesn't 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(start=false) "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;
  heat = false;
equation
  Q = if heat then Qcapacity else 0;
  C*der(T) = Q-h*(T-Tamb);
  when {T>Tbar+1,T<Tbar-1} then
    heat = T<Tbar;
  end when;
end HysteresisControl;

猜你喜欢

转载自blog.csdn.net/bear_miao/article/details/80152939
今日推荐