Thread Subject: Integrating compiled m-file with compiled simulink (RTW?) model

Subject: Integrating compiled m-file with compiled simulink (RTW?) model

From: Matthew Wade

Date: 8 Jul, 2008 13:31:01

Message: 1 of 7

Hi,

I have a series of Matlab GUIs with different
functionalities (database, visualisation, excel data
transfer). All of these compile straightforwardly with the
Matlab Compiler 4.3.

In one of the GUIs I have a button that initiates the
simulation of a simulink model and as
functions 'sim', 'simset' etc, cannot be compiled in
matlab, I have turned to Real Time Workshop.

However, before I begin to understand how to create stand-
alone applications of simulink models via RTW, I would like
to know if there is a way to integrate the command to run
this model into the compiled GUI executable.

i.e. the code [T,X,Y]=sim('mymodel'...)

will not compile using mcc.

If I manage to get a stand-alone application
for 'mymodel'...how do I replace the above code into the m-
file/executable.

Best regards,

Matt



Subject: Integrating compiled m-file with compiled simulink (RTW?) model

From: Titus

Date: 8 Jul, 2008 13:46:35

Message: 2 of 7


"Matthew Wade" <cosmicspacepig@googlemail.com> schrieb im Newsbeitrag
news:g4vq6l$8lr$1@fred.mathworks.com...
> Hi,
>
> I have a series of Matlab GUIs with different
> functionalities (database, visualisation, excel data
> transfer). All of these compile straightforwardly with the
> Matlab Compiler 4.3.
>
> In one of the GUIs I have a button that initiates the
> simulation of a simulink model and as
> functions 'sim', 'simset' etc, cannot be compiled in
> matlab, I have turned to Real Time Workshop.
>
> However, before I begin to understand how to create stand-
> alone applications of simulink models via RTW, I would like
> to know if there is a way to integrate the command to run
> this model into the compiled GUI executable.
>
> i.e. the code [T,X,Y]=sim('mymodel'...)
>
> will not compile using mcc.
>
> If I manage to get a stand-alone application
> for 'mymodel'...how do I replace the above code into the m-
> file/executable.
>
> Best regards,
>
> Matt
>
>
>

Hi Matt,
you will need to use the Rapid-Simulation target for the Real-Time Workshop
compilation. Take a look at the function rsimgetrtp for collecting the
parameters, and esp. the option "AddTunableParamInfo" . This function itself
is not compilable, but once you have the parameter structure, you can update
it from your code.

The code will be replaced by something like

paramStruct = load('paramfile.mat');
paramStruct.parameters.paramA = 42;
save paramfile paramStruct
system('theCompiledModel.exe -p paramfilein=paramfile');
result = load('output.mat');
plot(result.rt_tout, result.rt_yout)

There are some demos under Real-Time Workshop->Accelerated Simulations which
should give additional help.

Titus


Subject: Integrating compiled m-file with compiled simulink (RTW?) model

From: Matthew Wade

Date: 8 Jul, 2008 14:14:02

Message: 3 of 7

"Titus" <titus.edelhofer@mathworks.de> wrote in message >
Hi Matt,
> you will need to use the Rapid-Simulation target for the
Real-Time Workshop
> compilation. Take a look at the function rsimgetrtp for
collecting the
> parameters, and esp. the option "AddTunableParamInfo" .
This function itself
> is not compilable, but once you have the parameter
structure, you can update
> it from your code.
>
> The code will be replaced by something like
>
> paramStruct = load('paramfile.mat');
> paramStruct.parameters.paramA = 42;
> save paramfile paramStruct
> system('theCompiledModel.exe -p paramfilein=paramfile');
> result = load('output.mat');
> plot(result.rt_tout, result.rt_yout)
>
> There are some demos under Real-Time Workshop-
>Accelerated Simulations which
> should give additional help.
>
> Titus
>
Thanks Titus,

At least I now know it can be done. But I first must learn
RTW before getting to that stage.

Best regards
Matt

Subject: Integrating compiled m-file with compiled simulink (RTW?) model

From: Matthew Wade

Date: 28 Jul, 2008 13:11:22

Message: 4 of 7

Let me describe the problem that I have now:

What I have done:

a). In my m-file code, I have a function that initiates all
the states/parameters in the simulink model. These are
taken from an Excel file, which calculates certain
parameters for the model via a macro.

e.g. for a reactor block I have GENERAL, which is a vector
comprising a number of states (General(1) = initial
(1)...General(n) = initial (n) ), where initial is a column
of calculated initial states from the Excel file.

If the user selects a different option, these states will
change in the excel file and I will get a new General
vector.

b) I called all initial parameters to the workspace, open
the simulink model and selected:

- Inlined Parameters - Configuration (all parameters
selected from the initialising function (e.g. called from
Excel file). I did not change the Storage Class.

- Rapid Simulation System Target and fixed-step solver.
(the model runs on variable-step solver, so this may be a
problem?)

- Build: The Simulink Model is successfully compiled

b). I used the following code on the command line:

rtP = rsimgetrtp('model','AddTunableParamInfo','on');

the rtP.parameters.map is populated with the state vectors
(e.g. GENERAL) etc.

saved myrtp.mat rtP

c). from the command line:

!model.exe - p myrtp.mat -s 0.1

where -s is the simulation time.

Now here are the problems:

1. The simulation time -s, should be 25 (as dictated by the
user), if I use 25, there is a memory error message. I can
only run the model using 0.1 or lower.

2. The output from the model (model.mat) does not
correspond to the output I get when I run the model from
simulink (negative numbers, unstable).

3. in the Parameter file (rtP), I am unsure how to update
the parameters - there is no indication where I replace,
e.g. General(1)_0 with General(1)_1 (or General_0 with
General_1).

I am sure I am missing a few steps here, but as I have not
done this before, I would appreciate any ideas.

Best regards,
Matt

Subject: Integrating compiled m-file with compiled simulink (RTW?) model

From: Titus

Date: 28 Jul, 2008 13:17:04

Message: 5 of 7


"Matthew Wade" <cosmicspacepig@googlemail.com> schrieb im Newsbeitrag
news:g6kghq$4he$1@fred.mathworks.com...
> Let me describe the problem that I have now:
>
> What I have done:
>
> a). In my m-file code, I have a function that initiates all
> the states/parameters in the simulink model. These are
> taken from an Excel file, which calculates certain
> parameters for the model via a macro.
>
> e.g. for a reactor block I have GENERAL, which is a vector
> comprising a number of states (General(1) = initial
> (1)...General(n) = initial (n) ), where initial is a column
> of calculated initial states from the Excel file.
>
> If the user selects a different option, these states will
> change in the excel file and I will get a new General
> vector.
>
> b) I called all initial parameters to the workspace, open
> the simulink model and selected:
>
> - Inlined Parameters - Configuration (all parameters
> selected from the initialising function (e.g. called from
> Excel file). I did not change the Storage Class.
>
> - Rapid Simulation System Target and fixed-step solver.
> (the model runs on variable-step solver, so this may be a
> problem?)
>
> - Build: The Simulink Model is successfully compiled
>
> b). I used the following code on the command line:
>
> rtP = rsimgetrtp('model','AddTunableParamInfo','on');
>
> the rtP.parameters.map is populated with the state vectors
> (e.g. GENERAL) etc.
>
> saved myrtp.mat rtP
>
> c). from the command line:
>
> !model.exe - p myrtp.mat -s 0.1
>
> where -s is the simulation time.
>
> Now here are the problems:
>
> 1. The simulation time -s, should be 25 (as dictated by the
> user), if I use 25, there is a memory error message. I can
> only run the model using 0.1 or lower.
>
> 2. The output from the model (model.mat) does not
> correspond to the output I get when I run the model from
> simulink (negative numbers, unstable).
>
> 3. in the Parameter file (rtP), I am unsure how to update
> the parameters - there is no indication where I replace,
> e.g. General(1)_0 with General(1)_1 (or General_0 with
> General_1).
>
> I am sure I am missing a few steps here, but as I have not
> done this before, I would appreciate any ideas.
>
> Best regards,
> Matt

Hi Matt,

w.r.t. 2): this might correspond to you using the fixed step solver for the
compiled application and the variable step solver (with e.g. Zero-Crossing
detection) in the Simulink program. Try to use the fixed step solver in
Simulink and see, if you get the same results/problems.

Titus


Subject: Integrating compiled m-file with compiled simulink (RTW?) model

From: Matthew Wade

Date: 28 Jul, 2008 13:36:01

Message: 6 of 7

Hi Titus,

The model will not run with a fixed-step solver from
Simulink, I have to use Variable-step.

I have noticed -S option to allow specification of Solver
type, parameters. Maybe this will work.

Cheers
Matt

> Hi Matt,
>
> w.r.t. 2): this might correspond to you using the fixed
step solver for the
> compiled application and the variable step solver (with
e.g. Zero-Crossing
> detection) in the Simulink program. Try to use the fixed
step solver in
> Simulink and see, if you get the same results/problems.
>
> Titus
>
>

Subject: Integrating compiled m-file with compiled simulink (RTW?) model

From: Matthew Wade

Date: 28 Jul, 2008 14:37:02

Message: 7 of 7

the -S option with a solveroptions.mat file does not seem
to do anything, even when I save solveroptions.mat with
nonsense parameters (e.g. solver 'null'). Running the
executable does not seem to take these options into
consideration - the output is still the same.

"Matthew Wade" <cosmicspacepig@googlemail.com> wrote in
message <g6ki01$mle$1@fred.mathworks.com>...
> Hi Titus,
>
> The model will not run with a fixed-step solver from
> Simulink, I have to use Variable-step.
>
> I have noticed -S option to allow specification of Solver
> type, parameters. Maybe this will work.
>
> Cheers
> Matt
>
> > Hi Matt,
> >
> > w.r.t. 2): this might correspond to you using the fixed
> step solver for the
> > compiled application and the variable step solver (with
> e.g. Zero-Crossing
> > detection) in the Simulink program. Try to use the
fixed
> step solver in
> > Simulink and see, if you get the same results/problems.
> >
> > Titus
> >
> >
>

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
tunable parameters Matthew Wade 28 Jul, 2008 09:15:13
rsimgetrtw Matthew Wade 28 Jul, 2008 09:15:13
gui Matthew Wade 8 Jul, 2008 09:35:04
compiler Matthew Wade 8 Jul, 2008 09:35:04
simulink Matthew Wade 8 Jul, 2008 09:35:04
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com