Have you ever noticed the same block constructs occurring repeatedly in your model? Simulink libraries provide you with a way to capture the template for an algorithm, and then reuse that template all over your model. For this post, I will to introduce the basic concepts of libraries, library blocks, and library links.
Creating a library
To create a Simulink library, you have to create a new Simulink library from the File> New > Library menu, or using the new_system function.
Libraries are special MDL-files. When you look at a library, you will notice that it does not have the simulation controls a normal model has. The library is not a functional model; it is a palette of components. Here is an example library that contains a block for doing variable saturation of a signal.
The library can be constructed in the same way a model is constructed, by dragging blocks into the library canvas and connecting signals. The Saturation Dynamic block is just a subsystem that contains the algorithm for dynamic saturation of the signal u:
Locking the library
When a library is first created, it is unlocked.
This allows you to edit and build the components. Once you save the library and close it, the library is locked.
No changes are allowed without unlocking the library. This can be done from Edit > Unlock Library. Most people just drag a block a few pixels to trigger Simulink to prompt you to unlock the library.
Reference blocks and algorithm reuse
Just like the blocks from the Simulink libraries, you can add the library blocks to any model you are working on. There is some terminology that goes along with library blocks. When you add the library block to your model, you are creating a reference block.
The reference block is an instance of the library block, but the contents are not stored in the model. A model using the reference block stores only a library link, which holds the path to the library block.
>> get_param('satModel/Saturation Dynamic','ReferenceBlock')
Set the Format > Library Link Display to User to see which blocks in your model are actually library links. This setting adds a library link icon to the corner of your block.
Adding your library to the browser
At this point, you might be asking how to add the library to the library browser. The short answer is: >> doc slblocks. I provided an example of this in the historical tour of the library browser.
What do you do with libraries?
Do you maintain your own libraries? How many components does a typical library contain? Do you share your work with other modelers? Post your library to the file exchange, or leave a comment here.
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.