Problem to pause and resume Simulink simulation.

3 vues (au cours des 30 derniers jours)
Fabio Rossi
Fabio Rossi le 23 Mar 2017
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 commentaire
ganeshan viswanathan
ganeshan viswanathan le 11 Sep 2017
Modifié(e) : ganeshan viswanathan le 11 Sep 2017
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"

Connectez-vous pour commenter.

Réponses (2)

ES
ES le 23 Mar 2017
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 commentaires
Fabio Rossi
Fabio Rossi le 23 Mar 2017
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 le 6 Août 2017
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?

Connectez-vous pour commenter.


ganeshan viswanathan
ganeshan viswanathan le 11 Sep 2017
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"

Catégories

En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by