Decompose and Reuse Components - MATLAB & Simulink (original) (raw)

Every component in an architecture model can have its own design, or even several design alternatives. These designs can be architectures modeled in System Composer™ or behaviors modeled in Simulink®. Engineering systems often use the same component design in multiple places. A common component, such as power switch, can be part of all electrical components. You can reuse a component in System Composer within the same model as well as across architecture models.

Architecture Reference How to Use More Information
System Composer model reference Define component hierarchy with a linked architecture model to easily reuse these definitions across architectural components. Create Architecture Model Reference
System Composer subsystem reference Define component hierarchy with a linked architecture subsystem to easily reuse these definitions across architectural components.Subsystems support root-level physical ports to use with Simscape™ physical behaviors. Create Architecture Subsystem Reference

Decompose Component

A component can have its own architecture. Double-click a component to view or edit its architecture. When you view the component at this level, its ports appear as architecture ports. Use the Model Browser to view component hierarchy.

Two components named GPS and Gyro within the Sensor component.

You can add components, ports, and connections at this level to define the architecture.

You can also make a new Component block from a group of components.

  1. Select the components. Either click and drag a rectangle, or select multiple components by holding the Shift button down.
    Selected components are surrounded by a light blue highlight.
  2. Create a component from the selected elements by right-clicking and selecting Create Component from Selection.

Selected component surrounded by light blue highlight.

As a result, the new component has the selected components, their ports, and connections as part of its architecture. Any unconnected ports and connections to components outside of the selection become ports on the new component.

Any component that has its own architecture displays a preview of its contents.

Create Architecture Reference

An architecture reference provides a structure to create a hierarchical architectural system and further define subsystems using the component, port, connector paradigm in System Composer. Some projects use the same, detailed component in multiple places. The design of such a component must be tightly managed. You can create an architecture reference to reuse the architectural definition of a component in the same architecture model or across several architecture models.

Create Architecture Model Reference

Create an architecture reference model using this procedure:

  1. Right-click the Sensor component and select . Then, from the Type list, select Model Reference.
  2. Provide a name for the model. By default, the referenced architecture model is saved in the same folder as the architecture model. Browse for or enter the full path if you want to save the referenced model in a different folder.
    Save component as architecture model or subsystem dialog with new model name SensorRef.
  3. The software creates an architecture model with the provided name, and links the component to the new model. The linked model is indicated in the name of the component between the <> signs.
    Model with component named Sensor with the referenced model Sensor Ref between the chevrons.
    All architecture models can reference this new architecture model through linked components.

Create Architecture Subsystem Reference

You can link architecture subsystem references to components. Unlike a model reference, a subsystem reference supports top-level physical ports. Subsystems improve top-down editing workflows because inherited ports are flexible. An architecture subsystem reference contains sharable architecture models with optional Simscape behaviors. For more information about implementing Simscape behaviors, see Implement Component Behavior Using Simscape.

Note

To type ports on architecture subsystems with interfaces, you must link an external interface data dictionary. Architecture subsystems do not contain a model workspace. For more information, see Manage Interfaces with Data Dictionaries.

Create an architecture subsystem reference by linking an existing System Composer architecture subsystem file to a component or saving a new architecture subsystem from the converted component. The subsystem reference is saved in a separate file from the parent System Composer architecture model. Save a new architecture subsystem from the converted component using this procedure:

  1. Right-click the Motor component and select . Then, from the Type list, select Subsystem Reference.
  2. Provide a name for the subsystem. By default, the referenced architecture subsystem is saved in the same folder as the architecture model. Browse for or type the full path if you want to save the referenced subsystem in a different folder.
    Save component as architecture model or subsystem dialog with new subsystem name MotorRef.
  3. System Composer creates an architecture subsystem with the provided name, and links the component to the new model. The linked subsystem is indicated in the name of the component between the <> signs, and the component has a subsystem icon on the upper right.
    Model with component named Sensor with the referenced model Sensor Ref between the chevrons.
    All architecture models can reference this new architecture subsystem through linked components.

An architecture subsystem reference component can be implemented as a reference to a separate System Composer subsystem file and reused multiple times in the architecture model. Each component linked to an architecture subsystem is unique, so when a physical port is set to inherited, each instance of a physical port can use a different physical domain.

Architecture subsystem references support physical ports with physical interfaces. You can add Simscape behaviors to child components that become Simulink subsystem references or Simulink subsystem components. For more information, see Implement Component Behavior Using Simscape.

Drag to Add Reference Components to Architecture Models

You can drag to add a reference component linked to a model or subsystem into a System Composer model. Drag a model or subsystem file from the file explorer to add a reference component to the architecture model canvas.

For example, dragging a model SLX file into the architecture model canvas adds a Reference Component block that references the model in the SLX file.

Animation of an mWheel component file being dragged from the file explorer and added to the canvas to create a linked reference to a model

Files that you drag to add must be on the MATLAB® path. Creating reference components by dragging files from the MATLAB Editor into the model canvas is not supported.

Use Architecture Reference

You can use an architecture model reference, saved in a separate file, by linking to it from a component. Right-click the component and select Link to Model. You can also use the Create Reference option in the element palette directly to create a component that uses a reference architecture.

To link a selected component to an existing architecture model, right-click the Trajectory Planning component and select Link to Model.

Provide the full path to the referenced architecture model. If the linked component has its own ports and components, this content is deleted during linking and is replaced by that of the referenced architecture. The ports of the linked component become the architecture ports in the referenced architecture.

After linking the model, a referenced model appears between the chevrons called 'planning algorithm'.

Any change made in an architecture model reference is immediately reflected in the models that link to it. If you move or rename the referenced architecture, the link becomes invalid and the linked component displays an error. Link the component to a valid architecture model reference.

Remove Architecture Reference

In some cases, you have to deviate from the architecture model reference for a single component. For example, a comprehensive sensor model, referenced from a local component, may include too many features for the motion control architecture at hand and require simplification for that architecture only. In this case, you can remove the reference architecture to make local changes possible. Right-click a linked component and select Inline Model.

The referenced model Trajectory Planning with a right-click menu option selected 'Inline Model'.

This operation provides two options:

Once the architecture model reference is removed, you can make changes without affecting other architectures. However, you cannot propagate local changes to the architecture model reference. If you link to the referenced architecture again, local changes are lost.

Create Software Architecture from Component

You can create a software architecture model from a component in a System Composer architecture model and reference the software architecture model from the component. You can use software architectures to link Simulink export-function, rate-based, or JMAAB models to components in your architecture model to simulate and generate code. For more information, see Export Architecture to Software Architecture.

Create AUTOSAR Architecture from Component

You can create an AUTOSAR architecture model from a component in a System Composer architecture or software architecture model and reference the AUTOSAR architecture model from the component. For more information, see Create AUTOSAR Architecture from System Composer Model (AUTOSAR Blockset).

See Also

Functions

Blocks

Topics