Main Content

Custom Components

Write Simscape™ files to represent custom components

The Simscape language lets you define custom components as textual files, complete with parameterization, physical connections, and underlying equations. Topics on this page provide detailed information on declaring component parameters, variables, and connections. For other aspects of defining custom components, see Equations, Discrete Events and Mode Charts, and Composite Components.

To get started with writing custom components, see Creating Custom Components, which provides an overview of the general workflow. At the bottom of this page, topics listed under Reference Application Components provide complete component examples with detailed explanations that illustrate the techniques used in each case.

Language Syntax

annotationsControl appearance of Simscape block based on the component
branchesEstablish relationship between component Through variables and nodes
componentComponent model keywords
FaultsFaults interface annotation for custom component (Since R2024b)
inputsDefine component inputs, that is, physical signal input ports of block
nodesDefine component nodes, that is, conserving ports of block
outputsDefine component outputs, that is, physical signal output ports of block
parametersDeclare domain or component parameters
variablesDeclare domain or component variables

Topics

Basic Techniques

Declarations and Branches

  • Declaring Domains and Components
    Declaration section of domain and component files: purpose, definitions, rules, member summaries.
  • Declare a Spring Component
    The following diagram shows a network representation of a mass-spring-damper system, consisting of four components (mass, spring, damper, and reference) in a mechanical rotational domain.
  • Declare Component Parameters
    Component parameters let you specify adjustable parameters for the Simscape block generated from the component file.
  • Declare Component Nodes
    Component nodes define the conserving ports of a Simscape block generated from the component file.
  • Declare Component Inputs and Outputs
    In addition to conserving ports, Simscape blocks can contain physical signal input and output ports, directional ports that carry signals with associated units.
  • Declare Component Variables
    When you declare Through and Across variables in a component, you are essentially creating instances of domain Through and Across variables.
  • Define Relationship Between Component Variables and Nodes
    How to connect Through and Across variables declared in a component file to the domain Through and Across variables.
  • Declaration Functions
    Use MATLAB® functions to compute derived parameter values or initialize variables.

Component Variants

Advanced Techniques

  • Enumerations
    Specify a discrete set of acceptable values for parameters and event variables.
  • Subclassing and Inheritance
    Subclassing allows you to build component models based on other component models by extension.
  • Fault Annotations
    Use the annotations section of a component file to model faults in a custom component.

Reference Application Components