Main Content

Update an Existing Model to Use Units

This example shows how to add units to an existing model. You see how to:

  • Use an incremental workflow to add units to components in your model

  • Integrate components that use different unit systems

  • Specify units for individual elements of a bus object

  • Troubleshoot unit mismatch problems

The model in the example is a fuel control system. The controller (Fuel Rate Controller) and plant (Engine Gas Dynamics) components of the model are nonvirtual subsystems. Nonvirtual subsystems have the治疗作为原子单元参数选择。你单位介绍给中国人民解放军nt before introducing units to the controller and connecting signals. You also specify units for the individual elements of a bus object in the model.

Opentheex_units_fuelsysexample model.

For the top model, theAllowed unit systemsconfiguration parameter determines the unit systems the model can use. For each of the plant and controller subsystems, aUnit System Configurationblock determines the allowed unit systems.

Component Allowed Unit Systems
Top model SI
Fuel Rate Controllersubsystem (controller) all
Engine Gas Dynamicssubsystem (plant) all

In the plant subsystem, on theSignal Attributestab of eachInportblock dialog box, set theUnitparameter to a value appropriate for the connected physical signal.

Block Physical Signal Unit Parameter Setting
1 engine speed rad/s(radians per second)
2 throttle angle (degrees)
3 fuel rate g/s(grams per second)

To display units on ports and signals in the model, on theDebugtab, selectInformation Overlays>Port Units.

In the plant subsystem, you see units on theInport块和连接符号als.

Navigate back to the top model. To compile the model, pressCtrl+D, which also performs unit consistency checking.

The model displays a warning to indicate that there is a disallowed unit for thethrottle anglesignal. Clicking the warning icon displays a link to a Model Advisor report that gives you more detail.

The model also displays the warning at the bottom of the model editing window.

In the plant subsystem, you specified a unit of(degrees) for thethrottle anglesignal. However, the warning message indicates that degrees are not in the SI unit system. As determined by theAllowed unit systemsconfiguration parameter,SIis the only unit system that the top model currently allows. To resolve this warning, you have two options:

  • In the plant subsystem, specify a unit for thethrottle anglesignal that theSIunit system supports. For more information about supported unit systems and the units they contain, seeAllowed Units.

  • In the top model, change theAllowed unit systemsconfiguration parameter to expand the set of allowed unit systems.

In this case, a unit offor thethrottle anglesignal is appropriate. Instead, to resolve the warning, expand the set of allowed unit systems for the top model. Set theAllowed unit systemsconfiguration parameter of the top model toall. To recompile the model, pressCtrl+D.

The top model no longer displays warnings.

Now that you have introduced units to the plant and successfully resolved unit inconsistency problems, you can add units to the controller. In theFuel Rate Controllersubsystem, set theUnitparameter of thefuel_rateOutportblock tokg/s(kilograms per second).

Navigate back to the top model. To recompile it, pressCtrl+D.

The top model now shows a warning for mismatched units between the controller and plant. To resolve this error, you can:

  • Explicitly insert aUnit Conversionblock between the two components.

  • Select theAllow automatic unit conversionsconfiguration parameter.

Both options convert units in the same way. A situation in which you might disallow automatic conversions and insert conversion blocks instead is when you are integrating many components in a large system model. In that case, manually inserting conversion blocks can give you an added degree of control of unit conversions in the model. Also, with a conversion block, you can control the data type of the converted signal. This is useful, for instance, when you are modeling for fixed-point precision.

In this case, to enable Simulink®to resolve the unit mismatch automatically, selectAllow automatic unit conversions. To recompile the model, pressCtrl+D.

Simulink automatically converts units between the controller and the plant. An automatic conversion icon replaces the warning.

The top model includes aSimulink.Busobject namedEngSensorsthat passes various sensor signals as a composite signal to the controller. To use the Bus Editor to add units to individual elements of the bus object, on theModelingtab, underDesign, clickBus Editor. Then, specify the units in the table or in theProperty Inspectorpane.

Bus Editor with an element of the EngSensors bus object selected

For theEngSensorsbus object, set theUnitparameter of each element.

Signal Unit Parameter Setting
throttle (degrees)
speed rad/s(radians per second)
ego V(volts)
map bar(bars)

To recompile the model, pressCtrl+D.

The model shows units on the individual elements of the bus object.

You can also see the units in the interface view of your model. On theModelingtab, underDesign, clickModel Interface.

Theairflow_calcblock of the controller subsystem displays units on the individual elements of the bus object, both at the component interface and within the component.

After you introduce units incrementally and resolve inconsistency and mismatch issues, you can simulate the model.

For thefuelsignal that is connected to the scope, the plot window displays the associated units ofkg/sas ay-axis label.

See Also

|||||

Related Topics