Data variants in Simulink Data Dictionary

41 views (last 30 days)
Is there any possibility to create data variants in the Simulink DataDictionary?
I have the need of varying the value of some (but not all) the parameters used by a simulink model depending on the value of another parameter. However, the model is always the same (no need of subsystem variants).
For example, the simulink model could represent the model of an electric fan. With this model, varying the parameter of the fan (length, blades inclination, etc.) I can represent the behaviour of different types of fans.
Is there a smart way to do it?

Answers (7)

Jonas
Jonas on 22 Apr 2020
Edited: Jonas on 22 Apr 2020
I would suggest to put the Simulink.Parameter variables inside a separate Data Dictionary. Then, create two seperate files of this Data Dictionary, one with the one parameter set, and another with the exact same variables but with different variables (fan_parameters_A.sldd and fan_parameters_B.sldd). Then, you can reference either one of these two Data Dictionaries inside your main Data Dictionary (global.sldd references fan_parameters_A.sldd). If you want to simulate with the other data set, you can change the reference (global.sldd references fan_parameters_B.sldd), this is possible manually, but also programmaticaly I believe.
  3 Comments
Jonas
Jonas on 22 Apr 2020
I think I understand your issue. So after generating code, you want to be able to switch parameters from one set value to another set, by controlling one single control value.
I guess you now defined in your Data Dictionary a Simulink.Parameter called propeller_length which you use all over inside your model. The Embedded Coder will use the name 'propeller_length' all over your generated code. You now need a mechanism that can on-the-fly change the value from 2,3 to 2,5 for example.
But how are you going to define the other possible values for this same Simulink.Parameter? Because a Simulink.Parameter only accepts one 'Value' in its field... I think you will need to define the same parameter multiple times inside your Data Dictionary unfortunately. Then the parameter switching can be done in Simulink itself maybe, using Multiport Switches or something like this.
I don't know on what kind of hardware platform your embedded code runs, but I would solve this inside the HAL. For example that you push new values for propellor_length through Ethernet. This way you generate code using the parameters defined in the Data Dictionary which are default values, and then you overwrite them using an external communication command.
Just brainstorming here, it might trigger your mind.
Davide Benvenuti
Davide Benvenuti on 22 Apr 2020
Yes, exactly! I need my generated code to be suitable for multiple fans (just as example).
Unfortunately I can't modify the parameters after the code has been generated, otherwise it would have been a great idea.
I just don't understand why model variants are managed in simulink and integrated with the embedded coder and data variant are not (as far as I know).

Sign in to comment.


Sudha Dhoorjaty
Sudha Dhoorjaty on 6 Jun 2022
You can use variant parameters (Simulink.VariantVariable) to change values of parameters for simulation and code-generation workflows in a Simulink data dictionary. See Use Variant Parameters to Reuse Block Parameters with Different Values, Create Models with Parameter Value Variations .
  1 Comment
Tamas Rozsa
Tamas Rozsa on 5 Jul 2022
Nice, thanks a lot for sharing this new alternative. I think that solution was long-awaited by sooo many people in the past years or even decades.
That's a pity that it came only in R2021a and everyone out there in the industry needed to develop their own solutions for the same purpose.

Sign in to comment.


Jesús Zambrano
Jesús Zambrano on 21 Apr 2020
You can add a Simulink Variant to a Data Dictionary (see picture below).
For example, programmatically V_LINEAR_CONTROLLER=Simulink.Variant('CTRL==1') creates a SImulink variant object V_LINEAR_CONTROLLER; where the argument ('CTRL==1') defines the condition when the variant is active.
  3 Comments
Jesús Zambrano
Jesús Zambrano on 22 Apr 2020
We need more information: where are these parameters living?, model workspace?, mask?, base workspace?, inside a S-function?
Note that variant models cannot switch during simulation time (if you are thinking of some switching when the model is running).
Davide Benvenuti
Davide Benvenuti on 22 Apr 2020
The variables are stored in the Simulink DataDictionary as Simulink.Parameter. The variables then can be used in simple blocks in the model.
I don't want to switch between variants during simulations. The final result that I want to achieve is the code generation of the model using embedded coder for the different variants.

Sign in to comment.


Donn Shull
Donn Shull on 24 Apr 2020
If you are using embedded coder you can set the Simulink.Paramater's CoderInfo.StorageClass to 'ImportedExtern', and thed store your variants in header files.
  2 Comments
Davide Benvenuti
Davide Benvenuti on 27 Apr 2020
Please, can you tell me something more about this strategy? How can I store different values for a parameter contained in more than one variant?
Donn Shull
Donn Shull on 28 Apr 2020
There example ex_defn_decl provides detailed information for the storage class ExportToFile. You can follow that example and choose ImportFromFile or ImportedExtern and look at the results. The ImportFromFile storage class allows you to specify the header file containing your paramater definitions.

Sign in to comment.


Tamas Rozsa
Tamas Rozsa on 30 Sep 2020
Edited: Tamas Rozsa on 1 Oct 2020
Besides hard-coded values, it is also possible to define expressions for Simulink.Parameter objects in data dictionaries, like:
Check out the Set Variable Value by Using a Mathematical Expression section in the documentation for further details. (The image above also comes from there.)
You can also control the behavior for code generation; see Code Generation of Parameter Objects With Expression Values in the documentation for further details.
Note that this feature seems to be available only since MATLAB R2018a.
Hope this helps.

Tamas Rozsa
Tamas Rozsa on 14 Oct 2020
Edited: Tamas Rozsa on 14 Oct 2020
Additionally to my previous answer above, it is also worth looking at Simulink Variant Manager.
Besides managing variant subsystems, variant models, variant sinks and sources, it is also possible to define different parameter sets ("control variables"), and you can select which parameter set you would like to use for a particular simulation or a particular code generation.
You can find the documentation here: Variant Manager Overview (The image above also comes from there.)
There is a useful starting page as well about variants: Variant System Design
This latter one also contains video links, like Variant Configuration Management in Simulink and Managing Design Variants.
The main parts of the corresponding API can be found here: Simulink.VariantConfigurationData class.
However, I suspect that the answer to the original question (i.e., defining variables that depend on each other) still lies in my other mentioned post.

Kirk Rudolph
Kirk Rudolph on 15 Dec 2020
I had the same problem of having a common model that requires many parameterizations. I found a very useful example of a Simulink data dictionary (.sldd) that enables switching variant parameters/datatypes during sim and code execution here: Switch Between Sets of Parameter Values During Simulation and Code Execution. Hope this helps!

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!