Thread Subject: Pausing a Simulation run via script

Subject: Pausing a Simulation run via script

From: Dave Lawson

Date: 7 Apr, 2008 21:10:03

Message: 1 of 5

  I seem to be having a tough time making a simulation
pause when certain criteria are met. I've tried two
methods, including using the premade pause block from the
premades sections. My difficulties seem to be particular
to executing my simulation from within a .m script.

  When I run my script, it launches the simulation. Things
work nicely until the condition to pause is it. It then
outputs a debug message in the matlab console instead of
pausing anything at all. If I run the simulation via the
play button in the model viewer, it pauses perfectly.

  Is there anyway to force a simulation to pause, if it is
being run without the model viewer open?

Subject: Pausing a Simulation run via script

From: Dave Lawson

Date: 8 Apr, 2008 00:30:08

Message: 2 of 5

"Dave Lawson" <DaveLawson@Hotmail.com> wrote in message
<fte2jb$13n$1@fred.mathworks.com>...
> I seem to be having a tough time making a simulation
> pause when certain criteria are met. I've tried two
> methods, including using the premade pause block from the
> premades sections. My difficulties seem to be particular
> to executing my simulation from within a .m script.
>
> When I run my script, it launches the simulation.
Things
> work nicely until the condition to pause is it. It then
> outputs a debug message in the matlab console instead of
> pausing anything at all. If I run the simulation via the
> play button in the model viewer, it pauses perfectly.
>
> Is there anyway to force a simulation to pause, if it
is
> being run without the model viewer open?

I have continued digging on this topic, and it seems I'm
only digging a deeper grave.

I've now tried to monitor the values of certain simulation
variables in my script file first matlab sinks in
simulink. Unfortunately, through some sort of quirk, I
have to press CTRL+C during the script's execution, before
ANY of my output values from Simulink are updated. Until I
abort the operation (I assume it is aborting the simulink
simulation when I press that -- I can't honestly tell), my
sinks only show values of 0.

I figured maybe this was because simulink was being greedy
and not releasing any data while the simulation was
ongoing. So, I tried to pause it, and extract the
information while the simulation was pause. This still
gave me only 0's. I then guess that perhaps I had to
terminate the entire simulation (which would in fact defeat
the entire purpose of me doing this), but instead it gives
me a syntax error. I suppose the sinks are no longer in
scope at that point.

Surely someone has tried to monitor a simulation from
within a script! The due date is looming, and I can't find
anything that seems to work for this! Please help!

Subject: Pausing a Simulation run via script

From: Ralph Schleicher

Date: 8 Apr, 2008 20:19:05

Message: 3 of 5

"Dave Lawson" <DaveLawson@Hotmail.com> writes:

> Surely someone has tried to monitor a simulation from
> within a script! The due date is looming, and I can't find
> anything that seems to work for this! Please help!

1. Run the simulation asynchronously from your script:
   set_param(bdroot, 'SimulationCommand', 'start').
2. Log the relevant Simulink signals into a file. The built-in Simulink
   blocks don't work. You have to use something more sophisticated.
3. Read the relevant Simulink signals back and analyze them.
4. Pause/Continue/Stop the simulation as required:
   set_param(bdroot, 'SimulationCommand', COMMAND).

If you do it right, you can manage to control the simulation within a
delay of one major time step.

P.S. The 'SimulationCommand' property is write-only. I don't know of
any way to check the execution status of a simulation from a script.

--
Ralph Schleicher, Freelance Engineer http://ralph-schleicher.de

Development * Consulting * Training
Mathematical Modeling and Simulation
Software Tools

Subject: Pausing a Simulation run via script

From: Ryan

Date: 25 Aug, 2009 23:34:03

Message: 4 of 5

> P.S. The 'SimulationCommand' property is write-only. I don't know of
> any way to check the execution status of a simulation from a script.

To get execution status:
get_param('sys', 'SimulationStatus')

Subject: Pausing a Simulation run via script

From: Ryan

Date: 25 Aug, 2009 23:35:23

Message: 5 of 5

> P.S. The 'SimulationCommand' property is write-only. I don't know of
> any way to check the execution status of a simulation from a script.

To get execution status:
get_param('sys', 'SimulationStatus')

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
pause a simulation Sprinceana 26 Aug, 2009 05:20:36
simulink Sprinceana 26 Aug, 2009 05:20:36
rssFeed for this Thread

Contact us at files@mathworks.com