Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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 Treat as atomic unit parameter selected. You introduce units to the plant before introducing units to the controller and connecting signals. You also specify units for the individual elements of a bus object in the model.

Open the ex_units_fuelsys example model.

For the top model, the Allowed unit systems configuration parameter determines the unit systems the model can use. For each of the plant and controller subsystems, a Unit System Configuration block determines the allowed unit systems.

ComponentAllowed Unit Systems
Top modelSI
Fuel Rate Controller subsystem (controller)all
Engine Gas Dynamics subsystem (plant)all

In the plant subsystem, on the Signal Attributes tab of each inport block dialog box, set the Unit parameter to a value appropriate for the connected physical signal.

BlockPhysical SignalUnit Parameter Setting
1engine speedrad/s (radians per second)
2throttle angledeg (degrees)
3fuel rateg/s (grams per second)

To display units on ports and signals in the model, select Display > Signals & Ports > Port Units.

In the plant subsystem, you see units on the inport blocks and connected signals.

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

The model displays a warning to indicate that there is a disallowed unit for the throttle angle signal. 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 deg (degrees) for the throttle angle signal. However, the warning message indicates that degrees are not in the SI unit system. As determined by the Allowed unit systems configuration parameter, SI is 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 the throttle angle signal that the SI unit system supports. For more information about supported unit systems and the units they contain, see Allowed Units.

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

In this case, a unit of deg for the throttle angle signal is appropriate. Instead, to resolve the warning, expand the set of allowed unit systems for the top model. Set the Allowed unit systems configuration parameter of the top model to all. To recompile the model, press Ctrl+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 the Fuel Rate Controller subsystem, set the Unit parameter of the fuel_rate outport block to kg/s (kilograms per second).

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

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

  • Explicitly insert a Unit Conversion block between the two components.

  • Select the Allow automatic unit conversions configuration 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, select Allow automatic unit conversions. To recompile the model, press Ctrl+D.

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

The top model includes a EngSensors bus object that 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, select Edit > Bus Editor.

For the EngSensors bus object, set the Unit parameter of each element.

SignalUnit Parameter Setting
throttledeg (degrees)
speedrad/s (radians per second)
egoV (volts)
mapbar (bars)

To recompile the model, press Ctrl+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. Select Display > Interface.

The airflow_calc block 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 the fuel signal that is connected to the scope, the plot window displays the associated units of kg/s as a y-axis label.

See Also

| | |

Related Topics

Was this topic helpful?