如何在Modelica中延迟布尔信号?

时间:2013-06-25 10:33:55

标签: boolean delay modelica

似乎延迟块只接受真实的输入/输出。我在布尔延迟上找不到任何东西。或者我需要做一个布尔到真正的转换吗?

我对Modelica很新,但这对我来说似乎是一个明显的内置障碍......

谢谢!

1 个答案:

答案 0 :(得分:0)

如果使用delay()对其进行建模,请注意可以插补信号。因此,您必须确定0.5true还是false

然而,您可以实现自己的(效率稍低)延迟缓冲区(在OpenModelica和Dymola中测试):

model M
  parameter Integer bufferSize = 10;
  parameter Real delayTime = 0.1;
  discrete Real nextTime[bufferSize](each start = 0);
  Boolean delayBuffer[bufferSize](each start = false);
  Boolean signal,delayed;
  Integer n(start = 0), m(start = 1), prem;
equation
  when change(signal) then
    n = if pre(n)==10 then 1 else pre(n)+1;
    nextTime = {if i<>n then pre(nextTime[i]) else time + delayTime for i in 1:bufferSize};
    delayBuffer = {if i<>n then pre(delayBuffer[i]) else signal for i in 1:bufferSize};
  end when;
equation
  prem = pre(m);
  when time > nextTime[pre(m)] then
    delayed = delayBuffer[pre(m)];
    m = if pre(m)==10 then 1 else pre(m)+1;
  end when;
  if time < 0.1 then
    signal = true;
  elseif time < 0.2 then
    signal = false;
  elseif time < 0.7 then
    signal = true;
  elseif time < 0.71 then
    signal = false;
  elseif time < 0.72 then
    signal = true;
  elseif time < 0.73 then
    signal = false;
  elseif time < 0.74 then
    signal = true;
  elseif time < 0.75 then
    signal = false;
  else
    signal = true;
  end if;
end M;

结果是错误的,直到第一个信号被延迟,但它可能会得到改善。 signal的if语句只是用于测试的示例信号。