Pausing a Simulink Simulation with an Assertion Block, continue does not work

36 ビュー (過去 30 日間)
Benedikt Staneczek
Benedikt Staneczek 2018 年 6 月 13 日
回答済み: Claudio Rey 2021 年 11 月 30 日
Hello, I paused a simulation in Simulink with the Assertion-Block. In the model callbacks I call a function for some calculations. After that I want to continue the simulation with:
set_param(bdroot,'SimulationCommand','continue')
But doesn't work. Do you have any idea?
regards
Benedikt

回答 (5 件)

Inuit88
Inuit88 2020 年 9 月 17 日
I found (on another site) a workaround to continue the simulation from the 'PauseFcn' callback. It works properly for me on the 2019b version:
xx = timer('ExecutionMode','singleShot','StartDelay',0.1,'TimerFcn','set_param(bdroot, ''SimulationCommand'', ''continue'')');
start(xx);
In summary, one creates a timer object and attaches the "continue" function, and then start the timer which will then continue the simulation after the "PauseFcn" callback is exited.
  1 件のコメント
Ben Krämer
Ben Krämer 2020 年 11 月 28 日
I am also running this on R2019b and it's working.
Additionaly I want to write simulation output from Simulink to the Matlab workspace and use in the m-file that I am running in every pause.
Although it is stated in the description of the "To Workspace" block that data will be available when simulation pauses, the variable is not available to use in my script during pause.
"Data is not avaiable until the Simulation is stopped or paused"
Does this have anything to do with the behaviour of the timer function?
I attached a simple example. Just run "init_loop". To see the problem uncomment line 8 in script "set_param_testskript".

サインインしてコメントする。


Swati Lodha
Swati Lodha 2018 年 6 月 26 日
Hello
I tried to reproduce the same and it's working fine at my end. You might want to consider the following:
  • Clear Stop simulation when assertion fails check box in the Assertion block dialog box.
  • Pause the simulation by entering this command as the value of Simulation callback when assertion fails:
set_param(bdroot,'SimulationCommand','pause'),
disp(sprintf('\nSimulation paused.'))
  • Perform your calculation in the PauseFcn callback.
  • Use the following command to Continue
set_param(bdroot,'SimulationCommand','continue')
Refer the documentation for more information: Hello
I tried to reproduce the same and it's working fine at my end. You might want to consider the following: 1) Clear Stop simulation when assertion fails check box in the Assertion block dialog box. 2) Pause the simulation by entering this command as the value of Simulation callback when assertion fails: set_param(bdroot,'SimulationCommand','pause'), disp(sprintf('\nSimulation paused.')) 3) Perform your calculation in the PauseFcn callback. 4) Use the following command to Continue set_param(bdroot,'SimulationCommand','continue')
  1 件のコメント
Osama Al-Najjar
Osama Al-Najjar 2018 年 10 月 16 日
MR. Lodha,
I'm facing a similar behavior. I'm pausing the simulation using the assertion block which does pause the simulation, but what does not work is the continue simulation command in the Pausefcn callback window to resume the simulation
set_param(bdroot,'SimulationCommand','continue')
While it works if entered manually in the command window. Any idea why?

サインインしてコメントする。


MK
MK 2019 年 2 月 6 日
Do you found a solution for your question?

Stefanie Schwarz
Stefanie Schwarz 2019 年 4 月 4 日
編集済み: Stefanie Schwarz 2019 年 4 月 23 日
Hello Benedikt, Osama and MK,
after further investigation, we can confirm that since MATLAB Release 2016a, it is not possible to continue a simulation using 'PauseFcn' callback anymore.
We disallowed calling "set_param(gcs,'SimulationCommand','continue')" from the 'PauseFcn' callback, as this is the kind of thing that can easily end up in an infinite recursion if not done properly.
There is currently no workaround to achieve the old behavior; so the best way to move things forward would be to look into other alternate workflows that would be more robust to achieve what you really need.
For example, if you perform co-simulation, an S-Function could do something similar to what the 'PauseFcn' callback is doing. You would not need to pause, the S-Function would call the external environment, wait for it to do its thing and when it is done, it would keep moving forward. That would be a lot more robust and would probably be faster too.
HTH,
Stefanie
  2 件のコメント
Frederik Elskamp
Frederik Elskamp 2019 年 4 月 23 日
Hello Stefanie and all the others,
I have a similar problem. My aim is to automatically save the actual workspace (at least parts of it) after an event occurs. The simulation should run further after saving.
When I do not pause or stop the simulation, it is not the actual workspace. Stopping would not make sense as I want to continue the simulation. So I have to automatically pause, save and continue the simulation. Besides pausing it with the assertion block, I tried to open a m-file (with pause, save and continue) with the assertion block and also a block function with the similar commands. In all cases it pause after executing the commands without continuing.
How would this work with a S-function or is there another easier solution?
Regards,
Frederik
Aly Elhefny
Aly Elhefny 2020 年 6 月 13 日
I have the same question as Frederik Elskamp, does the newer versions of matlab give us the ability to continue after pause from assertation block ?
If not, it is not clear for me how would you use s-function to do the same thing.

サインインしてコメントする。


Claudio Rey
Claudio Rey 2021 年 11 月 30 日
One thing I do is to have the simulink clock compare with a specific time at which time it triggers a matlab function to do what I need even pause using a debug point

カテゴリ

Help Center および File ExchangeModel, Block, and Port Callbacks についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by