Data variants in Simulink Data Dictionary
41 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (7 件)
Jonas
2020 年 4 月 22 日
編集済み: Jonas
2020 年 4 月 22 日
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 件のコメント
Jonas
2020 年 4 月 22 日
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.
Sudha Dhoorjaty
2022 年 6 月 6 日
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 件のコメント
Tamas Rozsa
2022 年 7 月 5 日
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.
Jesús Zambrano
2020 年 4 月 21 日
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 件のコメント
Jesús Zambrano
2020 年 4 月 22 日
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).
Donn Shull
2020 年 4 月 24 日
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 件のコメント
Donn Shull
2020 年 4 月 28 日
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.
Tamas Rozsa
2020 年 9 月 30 日
編集済み: Tamas Rozsa
2020 年 10 月 1 日
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.
0 件のコメント
Tamas Rozsa
2020 年 10 月 14 日
編集済み: Tamas Rozsa
2020 年 10 月 14 日
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.
0 件のコメント
Kirk Rudolph
2020 年 12 月 15 日
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!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Manage Variant Modeling Components についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!