Saturday, July 27, 2024
HomeMatlabIdeas for Working with Simulink Libraries and Knowledge Dictionaries » Man on...

Ideas for Working with Simulink Libraries and Knowledge Dictionaries » Man on Simulink


I got here throughout an attention-grabbing characteristic lately for Simulink® libraries that may very well be useful when working with buses and different varieties related to them.

The Drawback

As an instance we’ve got a library with a number of blocks that use a selected bus on their interfaces, for instance, myBus. When producing code for our fashions I like to recommend utilizing non-virtual bus definitions so we will have strict management over how these buses seem within the code. This bus has 3 parts, a boolean, sel, and two uint32 values, a1 and a2. As a selected instance, one of many blocks from our library makes use of this bus for a range operation.

myLibBlock.png

Once we need to use these library blocks in certainly one of our fashions, we’ll have to have myBus outlined someplace within the scope of this mannequin. Which means that every mannequin that makes use of blocks from this library should have a setup script or be related to a Simulink information dictionary. Conceptually, our setup would seem like this diagram:

Within the above determine, the yellow arrows point out library block utilization and the blue arrows present information dictionary hyperlinks.

The Desired Scenario

This setup works, however it might be higher if we may have the definition of myBus come together with the library as a substitute. This may save our library customers time and streamline their workflows. Conceptually, we need to observe the tenet that the interface for a reusable part is saved with that part. With this in thoughts, our diagram ought to seem like this:

Right here the dictionary containing myBus will mechanically be included in any mannequin that makes use of blocks from the library. We’ll present how to do that within the following part.

Associating a Dictionary with a Library

Let’s begin by creating the required bus definition in a knowledge dictionary. From the Mannequin Explorer, we select File->New Knowledge Dictionary and supply a file identify. We’ll name it myLibDict.sldd. Subsequent, we’ll choose the Design Knowledge part of the dictionary and select Add->Simulink Bus, and rename the bus to myBus.

We’ll add the weather to this bus utilizing the brand new Kind Editor interface:
typeEditor.png

On this interface, we will arrange the aspect names, information kind, and many others. for our bus parts. As soon as we’re carried out, we will see the bus definition within the dictionary within the Mannequin Explorer:

myBusDef.png

Now that we’ve got this definition, we affiliate myLibDict.sldd with myLib.slx. Begin by deciding on myLib within the left panel of Mannequin Explorer and selecting the Exterior Knowledge tab in the proper panel. Within the Knowledge Dictionary Subject, enter myLibDict.sldd and press apply. Right here I’ve cropped and zoomed in on the related panels.

AssocLibLeft.pngAssocLibRight.png

As soon as we have carried out this, we will see this affiliation within the Exterior Knowledge discipline within the Mannequin Explorer:

myLibConf.png

Any mannequin that makes use of the library will now mechanically have entry the bus definition. Particularly, myModel.slx, which makes use of the library block, can use the bus definition. On this case, the enter is outlined to be of kind myBus. That is clear once we replace the diagram for myModel.

myModel.png

Housekeeping for Library Dictionaries

Instance 1: Reorganizing our Recordsdata

Now for example we need to reorganize our venture and transfer our library to a listing known as “Libraries”. Initially the information are all within the root folder of the venture:

preMoveFolder.png

We create the listing “Libraries” and transfer myLib.slx and myLibDict.sldd to this listing and add it to our path:

postMoveFolder.png

After this transfer, we get an error once we attempt to simulate our mannequin:

simError.png

Simulink.information.dictionary.closeAll()

Simulink.LibraryDictionary.refresh(‘./Libraries’)

It will replace the cached dictionary dependency evaluation and permit us to simulate myModel.

Instance 2: Sharing an Archive

As a closing instance, for example we need to share our venture with a colleague through an archive, let’s name it myProject.mlproj. We will forestall the above error when our colleague opens this venture and makes an attempt to simulate myModel by including the next line to a venture startup script. Right here we will see the script myStartupScript.m in our venture and the code within the editor. Be aware that the Run At Startup icon is ready within the Standing column (circled in crimson). We get this by right-clicking on myStartupScript.m within the venture window and deciding on Run At Startup from the menu.

StartupScript.png

It will enable our colleague to simulate and generate code from the mannequin.

Now It is Your Flip

How do you retailer your buses and interfaces? Do you discover this characteristic helpful? Please tell us within the feedback beneath.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments