Pausing a Simulink Simulation with an Assertion Block, continue does not work
22 次查看(过去 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
0 个评论
回答(5 个)
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
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
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')
You can refer to the documentation for more information: https://www.mathworks.com/help/simulink/ug/controlling-execution-of-a-simulation.html#bq0ht63
1 个评论
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?
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
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
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!