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

27 vues (au cours des 30 derniers jours)
Benedikt Staneczek
Benedikt Staneczek le 13 Juin 2018
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

Réponses (5)

Inuit88
Inuit88 le 17 Sep 2020
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 commentaire
Ben Krämer
Ben Krämer le 28 Nov 2020
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".

Connectez-vous pour commenter.


Swati Lodha
Swati Lodha le 26 Juin 2018
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 commentaire
Osama Al-Najjar
Osama Al-Najjar le 16 Oct 2018
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?

Connectez-vous pour commenter.


MK
MK le 6 Fév 2019
Do you found a solution for your question?

Stefanie Schwarz
Stefanie Schwarz le 4 Avr 2019
Modifié(e) : Stefanie Schwarz le 23 Avr 2019
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 commentaires
Frederik Elskamp
Frederik Elskamp le 23 Avr 2019
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 le 13 Juin 2020
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.

Connectez-vous pour commenter.


Claudio Rey
Claudio Rey le 30 Nov 2021
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

Catégories

En savoir plus sur Model, Block, and Port Callbacks dans Help Center et File Exchange

Produits


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by