Problem with non tunable parameters of embedded matlab function

24 views (last 30 days)
I'm using Matlab/Simulink R2011b with the 'Embedded Coder'. In my Simulink model is an embedded matlab function that runs with inputs and outputs and several parameters such as data fields. If I use 'Simulink.Parameter' as parameters for the embedded matlab function, it works fine and the option 'inline parameters' in embedded coder works properly. If I look the generated C code, I see the function prototype with the parameters that were replaced by numerical values and they are const, because I do not want to change them, so I unchecked the tunable checkbox, they shall stay untunable. All the 'Simulink.Parameters' are in my base workspace and defined for storage class as 'Auto'. This constellation works fine, no warnigs or errors at all.
I want to group my parameters in my workspace, so I create a structure with all the data fields. These fields are my parameters, but it is a normal structure. Then I create a 'Simulink.Parameter' and assign the structure to the 'Value' of a 'Simulink.Parameter'. Now, I have only one parameter for my embedded matlab function that defined as Simulink.Parameter. Everything works fine, no warnigs or errors at all. If I look into the generated C code I see that the function prototype looks different. It seems that the option 'Inline parameters' does not work in that case. The data fields are now a structure referenced by a pointer. The name of the structure is generated by Embedded Coder. I choosed the same options for 'Simulink.Parameter'. How can I resolve that problem? I want only group my parameters with the advantage of inlining. Does the option 'Inline Parameters' not work with structures? I have a workaround with a script, but it is not a good solution. Is it an issue of Embedded Coder or there is now other solution for that?
Best regards, Daniel.

Answers (3)

TAB
TAB on 31 Jan 2013
I tried same thing and found that it is working properly.
Refer this doc and check whether you have followed the requirements for structure parameter.
  2 Comments
Daniel Wolkow
Daniel Wolkow on 1 Feb 2013
Thank you. In the documentation is following mentioned: "By default, the MATLAB structure does not appear in generated code because numeric values are inlined. Code generation requires Simulink Coder™."
But why it is not working in my model? I use my structure in that way:
param_model = Simulink.Parameter;
param_model.Value = param_model_struct;
param_model.CoderInfo.StorageClass='Auto';
The structure(param_model_struct) was created in the same way as in the documentation showed. In the docu is also showed, how to make them tunable and appear in code as structure, but I want the opposite of that. The struct should be not tunalbe and inlining, replaced by numerical values.
Best regards, Daniel.
TAB
TAB on 2 Feb 2013
Edited: TAB on 2 Feb 2013
Can you post part of some generated c code which have structure parameter.

Sign in to comment.


Daniel Wolkow
Daniel Wolkow on 4 Feb 2013
I will discribe you simply the behaviour in code. The structure is declared with several data fields, like this:
typedef struct blablabla
{
int16_T dataf1[42];
real32_T dataf2[60];
...
} blablabla_mod
... and this:
typedef struct {
blablabla_mod exp_tmp;
...
} D_Work_Model
Data fields are in code this way:
static int16_T b_data[42] = { 59, 61, 63, 65, 67, 69, 71, 73,
75, 77, 79, 81, 83, 85, 86, 89,
...
}
Initialization of the data fields:
for (mid_i_0 = 0; mid_i_0 < 42; mid_i_0++) {
DWork_Model.exp_tmp.dataf1[mid_i_0] =
b_data[mid_i_0];
}
Declaration of the function:
static void my_func(const blablabla_mod *b_model, real32_T vu[256],
real32_T vl[256], ...)
Finally the function call:
my_func(&DWork_Model.exp_tmp, vu, vl, 3.0, 0.0, rtb_sb_0, gr);
What I expect instead:
static int16_T tmp_f1[110] = { 11, 12, 13, 56, 89, ... }
static int16_T tmp_f2[56] = { 89, 78, 86, 83, 54, ... }
Expected function call:
my_func(tmp_f1, tmp_f2, ...);
You see, that the fields are already in the function call integrated, no initialization needed.
Thank you for help.
Greets.

Daniel Wolkow
Daniel Wolkow on 6 Mar 2013
I have found the solution for my problem. It was a configuration issue. First, I've changed the parameter setting in embedded matlab function from "non tunable" to "tunable". After that I've set the storage class for simulink.parameter object to "custom" and then to "const". Now, all the parameters are constants in generated C code, so it was not an issue of inlining, ist was just only the wrong configuration.
One thing I do not understand. Why it is called tunable to set the parameters to constants. Non tunable seems more logical.

Community Treasure Hunt

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

Start Hunting!