Discussion:
Interactive Controlling of Simulink Model from GUI
(too old to reply)
Jeffry
2005-06-28 15:19:08 UTC
Permalink
I have a GUI that starts a model:

set_param('modelname','simulationstatus','start');

I run into trouble when I need values being outputted to workspace to
be updated in the GUI displays. Do I need to change workspace source
and destination for the simulink model?

In addition, values that run the simulink model need to be changed
interactively by user. How do I make the adequately link between
these two for proper execution?

Thanks for your time and consideration.

Jeffry
Xin Liu
2005-06-28 16:09:18 UTC
Permalink
Jeffry,

If my understanding of your problemy is correct, you are trying to receive signals from a running Simulink model and also trying to update some model parameters (values).

Another way to accomplish this without outputing signals to the workspace (I think this is more flexible and faster) is to get signals directly from the running simulink model. What I would do is to add a output block to each signal that I want to receive and display in my GUI, and use the following two lines in my M-file to get the signal value:

br = get_param(simulink_object, 'RuntimeObject');
myData = get(br.InputPort(1), 'Data');
<< simulink_object can be found using GCB in the command window, or if you are familiar with Simulink object, you can write it out directly.>>

myData is a value (double, int8 etc. depending on your data format setting) that you can manipulate.

I am not sure what "values" you want to change in your Simulink model. But you can always use

set_param(simulink_object, variable_name, value);

to change Simulink parameter values, be it a Simulink block or a masked subsystem.

HTH.
Xin
andrea
2005-06-28 20:39:56 UTC
Permalink
Post by Jeffry
set_param('modelname','simulationstatus','start');
I run into trouble when I need values being outputted to workspace to
be updated in the GUI displays. Do I need to change workspace
source
and destination for the simulink model?
In addition, values that run the simulink model need to be changed
interactively by user. How do I make the adequately link between
these two for proper execution?
Thanks for your time and consideration.
Jeffry
Hi Jeffry,

I've been trying to get answers to the exact same questions for the
GUI/model I'm creating. From the Mathworks support team I got the
following in regards to your second question:

To obtain a model's output without halting its simulation (in order
to adjust its subsequent inputs) please consider the following few
suggestions:

1. Use conditional/switch paths in your model, enabling it to control
its own behavior rather than controlling it externally from a GUI.
For example you could set up a conditional execution in your model
that switches to a different input upon satisfying a specified
condition. Most importantly now that it is a part of the model
itself, you no longer need to halt the simulation. To achieve these
constructs, try using the IF and SWITCH/CASE subsystems or the
MULTIPORT SWITCH block.

For additional information on using the IF block, type 'doc
simulink/if' at the MATLAB command prompt. For additional information
on using the SWITCH/CASE block, type 'doc simulink/switchcase' at the
MATLAB command prompt. For additional information on using the
MULTIPORT SWITCH block, type 'doc simulink/multiportswitch' at the
MATLAB command prompt.

2. Simulate the entire model in smaller pieces and perform the
conditions test to modify the inputs in between these simulations.
This can be achieved using the SIM or the MODEL functions as
mentioned in the following technical solution note :

<http://www.mathworks.com/support/tech-notes/1900/1903.html>

3. Also, please refer to the following technical solution that
provides an example of using a GUI to change Simulink parameters
during simulation:

<http://www.mathworks.com/support/solutions/data/1-1BDEE.html?solution=1-1BDEE>

If you need further assistance regarding this issue, please reply to
this email preserving the THREAD ID listed below. If you have a new
technical support question, please submit a new request here:

<http://www.mathworks.com/contact_TS.html>.

The example GUI from 3. uses
set_param('modelname','simulationcommand','update') to pass a changed
value from the GUI to the model during the simulation. Take a careful
look at their example code to see how they do it.

I am awaiting a reply on the first question from them and will try to
post to here when I get one.

HTH,
Andrea

Loading...