[simulink] --- data dictionary

1 The concept of simulink data dictionary

Simply put, the role of the data dictionary is to manage all the data objects used in a model in one place. In Simulink, data objects include signal objects, parameter objects, enumerators, constants, etc. That is to say, the data dictionary is a collection of many data objects.

2 Simple concepts of data objects

To give an example of the simplest data object, create a new Simulink model, in which there are 3 Gain modules, and their amplification parameters are the same, all of which are 2.
insert image description here
If you want to modify it, you must open each module. It will be very troublesome to change 2 to 3. In order to solve the troublesome problem of modification, you can create a constant Gain_Const=2 in the Matlab workspace, and then change the amplification parameter in the Gain module to the Gain_Const constant, as shown in the figure below. When you need to modify it, just change the value to 3. Gain_Const here is a constant data object
insert image description here
insert image description here

3 Management methods of data objects

In the example in the previous section, the Simulink model can be associated with the Gain_Const constant in the Matlab workspace during simulation. But there is a problem with this, that is, when Matlab is restarted next time, the Gain_Const constant in the workspace will be gone, and it must be added again to simulate the Simulinnk model.
Therefore, these data objects should be saved locally, and then loaded into the workspace during simulation. As for how to localize data objects, bloggers have seen three management methods.

3.1 mat file or m file

Right-click to select all data objects in the Matlab workspace (there is only one in the above example), and save them to the local mat file or m file. The path should preferably be under the same path as the Simulink file.
insert image description here
Before opening the demo.slx model, load the demo.mat file into the Matlab workspace.
insert image description here
The blogger thinks that doing so will have some disadvantages. First of all, it's a pain to load the file every time, but it's tolerable. More importantly, it is inconvenient to find and modify data objects. In enterprise-level projects, the models are often very large and contain a lot of data objects. There are many data objects in the workspace, which is very difficult to find.
Because of these disadvantages, many projects do not use this primitive way to manage data dictionaries.

3.2 Excel table & m script

This method is to write all data objects into a table, including the type of data object (signal object, enumerator, constant, etc.), parameters (including dimension, initial value, StorageClass, etc.) Specifications are listed in the table. Then write a Matlab script to write the data object definitions in the table into the workspace.

The essence of this method is still the data object in the workspace, but because of the introduction of the table, the search and lookup of the data object becomes easier. However, the step of manually loading to the workspace is still unavoidable. If you change the content of the form, you have to re-run the script, which is quite troublesome, so bloggers do not recommend it.

3.3 The data dictionary file that comes with Simulink

By creating a data dictionary file (suffixed with sldd) that comes with Simulink and associating it with the Simulink model, the management of data objects can be realized. The blogger strongly recommends that the next chapter will give an example to explain the establishment and association of sldd files.

4 Create a data dictionary and associate models

4.1 Create a data dictionary

1> Open the Model Explorer on the toolbar above the model
insert image description here

2> File–>New–>Data Dictionary Create a data dictionary, name it demo.sldd, and save it in the same path as the Sminulink file
insert image description here
insert image description here

3> Select Design Data under the demo, click Add Matlab Variable above, and then a default constant object named "Var" will be displayed in the data dictionary display column in the middle
insert image description here

4> Change its Name to Gain_Const and Value to 2.
insert image description here

5> Right-click demo–>Save Changes
insert image description here

So far, the data dictionary file is created, and a constant object is added to the data dictionary. The next step is to associate the data dictionary with the model.

4.2 Data dictionary and model association

1> Open the Simulink model–>Model Properties–>Link to Data Dictionary
insert image description here

2> Select Data Dictionary in the pop-up window–>click Browse…–>select the newly created demo.sldd in the pop-up path
insert image description here

3> Click Apply, and a query window will appear, asking if we want to associate the data objects of the Matlab workspace at the same time. If checked, the data objects in the Matlab workspace will not be associated at the same time, and if unchecked, they will be associated at the same time.
insert image description here

Here bloggers prefer to associate at the same time, because it is convenient to debug the model with things in the workspace. However, if there are objects with the same name in the workspace and demo.sldd, the simulation model will report a conflict error.

4> Here, the sldd file is associated, and a line of successful association will appear on the model.
insert image description here

At this point, the associated data dictionary is completed, and then you can simulate the model or generate code
insert image description here

5 Some descriptions of the sldd data dictionary

1> First of all, after establishing the sldd data dictionary and associating the model, turning it off in the Model Explorer can also simulate the Simulink model and generate code normally. This means that the data dictionary file does not need to be loaded before the simulation model, which is better than the previous two methods. The method of loading every time should be convenient.

2> In the sldd data dictionary, you can easily filter or search for data objects, as shown in the figure.
insert image description here

3> The sldd data dictionary must be in the Matlab path list, or under the current path. So it is best to name the sldd data dictionary the same as the model, and put it in the same path as the model. When copying and transferring the model, also bring the sldd file.

Guess you like

Origin blog.csdn.net/weixin_42445727/article/details/129516638