Value Types at Interfaces
This example shows how you can assign a meaningful name to a set of properties at an interface and reuse that set of properties with value types.
ValueTypesTirePressure project defines a model hierarchy that determines whether the tire pressures of a three-wheeled vehicle are within the intended operating range. Each sensor transmits tire pressure data mapped to a unique sensor ID. Of the four sensors in the model, only three of the sensors measure the tire pressure of the target vehicle. A controller filters out the unrelated sensor and determines whether the vehicle tire pressures are acceptable. When a tire pressure is out of range, the controller enables a warning lamp.
To open the project and top model, open the example. To update the line styles and load the referenced models, compile the model. On the Modeling tab of the Simulink® Toolstrip, click Update Model or Run.
Identify Available Types
The example uses a combination of
Simulink.ValueType objects and a
Simulink.Bus object to define arrays of buses, nonvirtual buses, signals, and instance parameters at component interfaces and Constant blocks.
NoisyDatavalue type defines an array of buses that contains the data transmitted from all four sensors.
FilteredDatavalue type defines an array of buses that contains the filtered data, which excludes data from the unrelated sensor.
SensorTransmissionvalue type specifies the bus object that contains the sensor reading and unique sensor ID.
TirePressurevalue type defines a signal that represents the tire pressure reading from a sensor.
DeviceIDvalue type defines a signal that represents the unique sensor ID.
ValidDeviceIDsvalue type defines a signal that represents the unique sensor IDs for each of the three wheels.
SensorDatabus object defines a bus that contains a sensor reading and unique sensor ID.
To view the types in the Type Editor, on the Modeling tab, in the Design gallery, click Type Editor. Then, set View to
Find Value Types Used for Instance Parameters
To find where a model uses a type, click the type in the Type Editor. In this example, block annotations display which blocks use the value types and bus object.
In the top model, four Model blocks use the
ValidDeviceIDs value type.
To view how these Model blocks use the value type:
On the Modeling tab, in the Design gallery, click Model Data Editor.
In the Model Data Editor, open the Parameters tab.
Sort the Data Type column by clicking the column heading.
Simulink.Parameter object named
ControllerClientIDList uses the value type. Selecting the parameter object highlights the four Model blocks that use the parameter object and value type.
To view how the Model blocks use the
ControllerClientIDList parameter object, in the Model Data Editor, sort the Value column by clicking the column heading.
Simulink.Parameter objects named
LocalDeviceID use the
ControllerClientIDList parameter object.
LocalDeviceID parameter objects are model arguments that the referenced models promote to the parent model. Each instance of a referenced model can specify a different value for these parameters, which are known as instance parameters.
Find Value Types Used for Blocks
ValueTypesTirePressureSensor referenced model.
The referenced model uses three value types:
TirePressurevalue type defines the input signal for an In Bus Element block.
DeviceIDvalue type validates the properties of the constant value for a Constant block.
SensorTransmissionvalue type defines the output bus for an Out Bus Element block. This value type references the
Return to the top model. Then, open the
ValueTypesTirePressureController referenced model.
The referenced model uses one value type at its root level.
NoisyData value type defines the input array of buses for an In Bus Element block. This value type references the
SensorData bus object.
The subsystem uses two value types:
ValidDeviceIDsvalue type validates the properties of the constant value for a Constant block.
FilteredDatavalue type defines the output array of buses for an Outport block. This value type references the
Return to the
ValueTypesTirePressureController referenced model. Then, open the
RangeChecker subsystem. This subsystem is a for-each subsystem that applies an algorithm to each of the buses in the input array of buses.
The subsystem uses one value type. The
SensorTransmission value type defines the input bus for an Inport block. This value type is the same value type that the
ValueTypesTirePressureSensor referenced model uses.
View Simulation Results
Simulate the model. Then, double-click the Scope block.
The Scope block displays the output signal, consisting of zeros and ones. The value indicates whether a tire pressure is out of range at a given simulation time. When a tire pressure is out of range, the controller enables a warning lamp.