Problem to pause and resume Simulink simulation.

3 次查看(过去 30 天)
hi guys! I have a trouble with simulink. I want to run a simulation and after some time it pauses, runs a script to calculate some values, updates these as new parameters of Simulink blocks and then resume the simulation. This process must be done several times. Reading in the page https://it.mathworks.com/help/simulink/ug/controlling-execution-of-a-simulation.html i am able to create a pause using assertion block. In the field "Simulation callback when assertion fails" of this block i put the code: * set_param(bdroot,'SimulationCommand','pause'); * run('myscript.m'); * set_param(bdroot,'SimulationCommand','continue'); so when the pause time is reached this block pauses the simulation, launches myscript.m but doesn't resume the simulation after the last command. It is very strange because if I use set_param function with 'SimulationCommand' options 'start', 'pause' or 'stop' it works fine. Only the 'continue' option isn't "accepted". So i tried to change the code to include set_param functions in myscript.m but nothing has changed. Another doubt regarding the command set_param(bdroot,'SimulationCommand','continue') is that if this is launched from command window works correctly. So given that the syntax is correct, I can't understand why the simulation doesn't resume again. Some idea? Thanks for the attention, Fabio
  1 个评论
ganeshan viswanathan
编辑:ganeshan viswanathan 2017-9-11
set_param('model name','StopTime','time_delay10') sim modelname "Do the calculations here" set_param('model name','SimulationCommand','update') "create the delay time according to when you need to stop it"

请先登录,再进行评论。

回答(2 个)

ES
ES 2017-3-23
1. Any chance your script changes bdroot?
2. Also, do you remember to update the value of the constant block after the assertion failure?
3. Once you have updated workspace with values, be sure to update the model because the workspace values are updated to the model only on Model update
set_param(bdroot, 'SimulationCommand', 'update')
  2 个评论
Fabio Rossi
Fabio Rossi 2017-3-23
Thanks for your answer.
  1. no. the problem isn't related to bdroot. I also tried to use the command set_param('mymodel', 'SimulationCommand', 'continue') but it isn't obtained any difference.
  2. yes. I update the "time value" of the constant block connected to the relational operation block to allow the subsequent pause.
  3. I didn't use the update command. I'm trying right now but I do not get a different result. Maybe I'm not using it in the correct way:
*%myscript.m*
set_param('mymodel','SimulationCommand','pause')
...
%some math operations
...
%update new values of constant blocks
set_param('mymodel/constantblock','Value','variable')
...
%Restart simulation
set_param('mymodel','SimulationCommand','continue')
set_param('mymodel', 'SimulationCommand', 'update')
%exit from myscript.m
or
set_param('mymodel','SimulationCommand','update')
set_param('mymodel', 'SimulationCommand', 'continue')
%exit from myscript.m
?
Thank you.
Fabio
X W
X W 2017-8-6
Hi Fabio, I am trying to address this same issue, any updates on how(if) you were able to get this resolved? Or did you try some other way?

请先登录,再进行评论。


ganeshan viswanathan
set_param('model name','StopTime','time_delay10') sim modelname "Do the calculations here" set_param('model name','SimulationCommand','update') "create the delay time according to when you need to stop it"

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by