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

조회 수: 4 (최근 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 CenterFile Exchange에서 Model, 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