Data variants in Simulink Data Dictionary

39 visualizaciones (últimos 30 días)
Davide Benvenuti
Davide Benvenuti el 9 de Abr. de 2020
Comentada: Tamas Rozsa el 5 de Jul. de 2022
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?

Respuestas (7)

Jonas
Jonas el 22 de Abr. de 2020
Editada: Jonas el 22 de Abr. de 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 comentarios
Jonas
Jonas el 22 de Abr. de 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 el 22 de Abr. de 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).

Iniciar sesión para comentar.


Sudha Dhoorjaty
Sudha Dhoorjaty el 6 de Jun. de 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 comentario
Tamas Rozsa
Tamas Rozsa el 5 de Jul. de 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.

Iniciar sesión para comentar.


Jesús Zambrano
Jesús Zambrano el 21 de Abr. de 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 comentarios
Jesús Zambrano
Jesús Zambrano el 22 de Abr. de 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 el 22 de Abr. de 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.

Iniciar sesión para comentar.


Donn Shull
Donn Shull el 24 de Abr. de 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 comentarios
Davide Benvenuti
Davide Benvenuti el 27 de Abr. de 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 el 28 de Abr. de 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.

Iniciar sesión para comentar.


Tamas Rozsa
Tamas Rozsa el 30 de Sept. de 2020
Editada: Tamas Rozsa el 1 de Oct. de 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 el 14 de Oct. de 2020
Editada: Tamas Rozsa el 14 de Oct. de 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 el 15 de Dic. de 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!

Categorías

Más información sobre Manage Variant Modeling Components en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by