私は01:00 10回のビープ音(1秒に1回)毎朝を生成目覚まし時計モデル化したいと仮定:上記のモデルでは時間イベントの生成を制限するためにModelicaのwhenステートメントをゲートするにはどうすればよいですか?
model DailyBeep
import SI = Modelica.SIunits;
import Modelica.SIunits.Conversions.*;
constant SI.Time oneDay = 86459.17808 "one day in seconds";
parameter SI.Time startTime = from_hour(1) "time to start beeping";
parameter Real numBeeps = 10 "the number of beeps to make";
Boolean beeping "true when we should beep every second";
Real beepsRemaining "the number of beeps remaining";
initial equation
beeping = false;
beepsRemaining = numBeeps;
algorithm
when sample(startTime, oneDay) then
beeping := true;
beepsRemaining := numBeeps;
end when "starts the beeping state";
when beeping and sample(0, 1) then
if beepsRemaining == 0 then
beeping := false;
else
// beep() // makes a sound
beepsRemaining := beepsRemaining - 1;
end if;
end when "beep every second, only when beeping is enabled";
end DailyBeep;
を、私は「ビープ音」を毎秒(生産しますsample(0,1)
)beeping
が真である限りです。数日間シミュレーションを実行すると、毎朝01:00にシミュレーションで10回のイベントが発生することが予想されます。
しかし、OpenModelicaで3600秒に設定してシミュレーションを実行すると、1秒に1回、3600回を超えるイベントが発生します。
### STATISTICS ###
events
3601 time events
アラームクロックを数ヶ月にわたってシミュレートする場合、これはうまくスケールされません。モデムのwhen
ステートメントをゲートする方法はありますか?この場合、when
の代わりに何か別のものを使用すべきですか?
パターン 'を使用することも可能です。サンプル(...)then nextTime:= time + 1.0; numTicks:= 10;終了時。 time> = nextTimeかつnumTicks> 0の場合、numTicks:= pre(numTicks)-1; nextTime:= time + 1.0;いつ終わるか。 Modelicaツールが状態イベントではなくタイムイベントに最適化する可能性があります(または、おそらく 'time> = nextTimeを使用してからnumTicks:= pre(numTicks)-1; nextTime:= numTicks> 0 then time +1.0 else pre(nextTime);終了時; '代わりに)。 –
@Adrian私は時計について読んできました。私が今まで考え出してきた唯一のコンセプトは、単一の時計を持ち、ビープ音の変化として間隔を調整することです。 – watkipet