Configure the parameters as arguments of the step function

8 views (last 30 days)
Hello,
I'm trying to generate code where the model parameters are passed as arguments to the step function. I'm not able to find the configuration which enables this.
The step function looks like this:
extern void MODEL_step(MODEL_T *const MODEL_M, Input_Type *arg_In,Output_Type *arg_Out);
But i need something like this:
extern void MODEL_step(MODEL_T *const MODEL_M, Input_Type *arg_In,Output_Type *arg_Out, const Parameters_Type *MODEL_Parameters);
I've already tryed changing the storage clases, editing the storage clases. The closests i get is using the storage class "ImportedExternPointer". Where i get a declaration like this inj the header file:
extern Parameters_Type *MODEL_Parameters;
But this means that if i want to reuse this code N times to represent this model N times, all the N times i use the same parameters, which i don't want.
Any suggestions will be appreciated,

Answers (1)

Jesús Zambrano
Jesús Zambrano on 9 Jan 2020
Hi Rodrigo,
When the step function looks like:
extern void MODEL_step(MODEL_T *const MODEL_M, Input_Type *arg_In,Output_Type *arg_Out);
means that you generate re-entrant multi-instance code from a model. Looking at the code you will see how parameters and states are packed in the MODEL_M structure, which is passed directly to the function interface. Therefore, multiple instances of the model_step function can run simultaneously when the step function has that prototype.
You get the above function prototype via: Code Generation > Interface > Code Interface Packaging option > set option to "Reusable function code".
Hope this answer can help you.
  3 Comments
Jesús Zambrano
Jesús Zambrano on 16 Jan 2020
Hi Rodrigo,
What you could try is to use referenced models. You create a child model with a set of parameters in its model workkspace that can be tunable (go to the Model Explorer and check the box under Arguments for those parameters). Then, in the parent, bring as many copies of your child model, then go to each call and set the value of the arguments. When generating code, each call of the child will use its own parameters.
Hope this workflow can help you.
Best,
Jesús
Rodrigo Estrella
Rodrigo Estrella on 20 Jan 2020
Hi Jesús,
Thanks for the answer. That works. Nevertheless i think it is not very clean. It would be great not having to create empty top models calling reference models. This could be a great improvement for future releases.
Best,
Rodrigo

Sign in to comment.

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!