New in R2019b: Subsystem Reference
Today I want to introduce my favorite new feature in MATLAB R2019b: Subsystem Reference
Let's see what is it, how it works, and when you should be using it.
Creating a Subsystem File
In R2019b, we are introducing a new type of block diagram. In addition to model files and library files, it is now possible to create subsystem files:
In the Current Folder window, you can differentiate models, subsystems and libraries by their icon and type:
From the command-line, if the subsystem is open you can determine what type of block diagram it is using get_param:
If you need to determine which type of block diagram an slx-file is without opening it or even loading it in memory, you can also use Simulink.MDLInfo:
Referencing a Subsystem File
The first important thing to realize is that a subsystem file cannot be simulated by itself. If you want to simulate or generate code for the block diagram stored in a subsystem file, you need to reference it in a model.
To reference a subsystem file, you start with a Subsystem block. In R2019b, you will notice that the Subsystem block has a new tab named Subsystem Reference. For convenience, we also added to the Simulink Library a block named Subsystem Reference, which is simply a Subsystem block pre-configured to reference a subsystem file.
Here is an animation where I configure and edit a referenced subsystem. As you can see, entering the subsystem and editing it is as simple and easy as editing a standard subsystem.
Converting an Existing Subsystem
If you have an existing model and would like to convert existing subsystems to referenced subsystems, you can simply right-click on the existing subsystem to do the conversion.
Instance Specific Context Awareness
In a way similar to library blocks, it is possible to use multiple instances of the same subsystem in a model, and each instance adapts to its context. The next image shows a model with 3 instances of the same subsystem, one receiving a complex scalar double, one receiving a matrix of 2x3 and the third instance receiving a vector of two integers.
Masking
If you want multiple instances of a referenced subsystem to take different parameter values, you can create a mask for the subsystem. This is done from the Modeling tab:
This will allow you to pass different parameter values to different instances of the subsystem. The next image shows 3 instances of the same subsystem. The two first take different values for a Gain block, and the last one takes a vector of 2 as input.
When To Use Subsystem Reference?
Now the big question: When to use subsystem reference?
The official answer to this question is to read the documentation section Component-Based Modeling Guidelines. In this section of the documentation, you will find this flow chart:
Here is my condensed version of how I make this decision. To componentize a model, you need to choose between 3 technologies: libraries, model reference and subsystem reference:
- Library: To create a blockset. A blockset is a collection of blocks, distributed to a large audience and rarely changes. To facilitate this use case, libraries provide features like forwarding tables and link management.
- Model Reference: To create standalone components with a well-defined rigid interface. Model reference offers many powerful features like accelerator mode, Software-in-the-Loop, Processor-in-the-Loop and protection. If you plan to create large models, model reference will help you scale in a robust and efficient manner.
- Subsystem Reference: The simplest way to save part of a model to a separate file. Sometimes I like to describe the subsystem reference as a library that would contain only one subsystem, and stripped down of all the features useful to manage a blockset that are not really needed if you simply want to save the content of a subsystem in a separate file.
We also put together this table that provides more details on the specifics of those three technologies.
Now it's your turn
As mentioned above, I strongly recommend that you go through the Component-Based Modeling Guidelines to see all the options available to componentize a model and their implications.
Give subsystem reference a try and let us know what you think in the comments below.
- 범주:
- What's new?
댓글
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.