Configure the parameters as arguments of the step function
8 views (last 30 days)
Show older comments
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,
0 Comments
Answers (1)
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
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
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!