MATLAB Answers

0

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

Asked by Benedikt Staneczek on 13 Jun 2018
Latest activity Edited by Stefanie Schwarz on 23 Apr 2019
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

  0 Comments

Sign in to comment.

Products


Release

R2016b

3 Answers

Answer by Swati Lodha on 26 Jun 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 Comment

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?

Sign in to comment.


Answer by MK
on 6 Feb 2019

Do you found a solution for your question?

  1 Comment

Sign in to comment.


Answer by Stefanie Schwarz on 4 Apr 2019
Edited by Stefanie Schwarz on 23 Apr 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

  1 Comment

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

Sign in to comment.