MATLAB Examples

Add Instrument Panel to Tank Model

This example shows how to create an instrument panel in Simulink® Real-Time™ Explorer for the Simulink Real-Time application built from the xpctank model. The instrument panel contains these instruments:

  • Slider — To tune the required tank level (SetPoint).
  • GaugeFluidLevel — To display the actual tank level (TankLevel).
  • LED — To display the pump control status (ControlValue).

This example also shows how to update the real-time application by adding a signal with enum data type in the model and rebuilding the application. After downloading the updated real-time application to the target, you can add an instrument to display the enumerated states as the instrument units.

Contents

Prerequisites

This example assumes knowledge of how to complete these operations:

  • Open Simulink Real-Time Explorer, slrtexplr.
  • Start the target computer.
  • Connect slrtexplr to the target computer.
  • Build the xpctank model and download the real-time application to the target computer.
  • Open the parameter and signal panels for the xpctank model in slrtexplr.

Create Instrument Panel

To provide an interactive instrument panel display for simulation, create and save an instrument panel for the xpctank real-time application.

To create an instrument panel in slrtexplr:

1. In the Panels pane, right-click the Instrument Panels node, then click New.

2. In the Name field, type a xpctank_instr_design.slrtip for the name.

3. In the Location field, select the folder for the panel file.

4. Press Enter and click the Save button.

Configure Instrument for Parameter Tuning

To tune a parameter from the xpctank real-time application, select and configure an instrument in the xpctank_instr_design.slrtip instrument panel.

Parameter Characteristics

Before binding a parameter to an instrument, examine the characteristics of the parameter for compatibility with the instrument.

The parameter characteristics for the SetPoint block parameter are:

  • Type — Numeric
  • Range — 0–10 units
  • Purpose — Represents the level at which the controller maintains the tank fluid level. You do not have to set the level to an exact value.

The Slider instrument is compatible with the characteristics of SetPoint. To set an exact numeric value, use a NumericEntry instrument, for example.

Configure Slider Instrument for SetPoint Tuning

To select and configure the Slider instrument from the xpctank_instr_design.slrtip instrument panel:

1. Select the instrument. From the Palette pane, drag a Slider instrument to the xpctank_instr_design.slrtip instrument panel.

2. Access the block parameter list. In the Applications pane, right-click xpctank and select View Block Parameters.

3. Bind the SetPoint parameter to the instrument. Drag the Parameter icon next to the parameter SetPoint and drop it into the Slider instrument. Next to the Slider instrument, a small copy of the Parameter icon appears.

4. Set the instrument range. Click the Slider instrument, and then click the Tasks button in the top right corner.

5. In the Slider Tasks dialog box, set property Min to 0 and property Span to 10.

6. Select a label. From the Palette pane, drag a Label layout item to underneath the Slider instrument.

7. Configure the label. Click the Label element. In the lower right corner, select the Properties pane.

8. Scroll down to the Appearance node. Set the Text property to Set Point, and then press Enter.

9. Scroll down to the TextAlign property. Click the down arrow and click the center block of the nine blocks presented. The TextAlign property becomes MiddleCenter.

10. Click the Save button.

At the end of this task, Simulink Real-Time Explorer displays the instrument panel, model signals panel, and model parameters panel.

Configure Instruments for Signal Display

To display two signals from the xpctank model, select and configure instruments in the xpctank_instr_design.slrtip instrument panel.

Signal Characteristics

Before binding a signal to an instrument, examine the characteristics of the signal for compatibility with the instrument.

The signal characteristics for the TankLevel signal are:

  • Type — Numeric
  • Range — 0–10 units
  • Purpose — Represents the current tank fluid level. You do not have to display an exact value.

The GaugeFluidLevel instrument is compatible with the characteristics of TankLevel. To display an exact numeric value, use a NumericDisplay instrument, for example.

The signal characteristics for ControlValue are:

  • Type — Boolean
  • Range — 1, 0
  • Purpose — Represents the state of the pump (on or off).

The LED instrument is compatible with the characteristics of ControlValue.

Configure Instruments for TankLevel and ControlValue Display

To select and configure instruments from the xpctank_instr_design.slrtip instrument panel:

1. Select the instrument. From the Palette pane, drag a GaugeFluidLevel instrument to the xpctank_instr_design.slrtip instrument panel.

2. Access the signal list. In the Applications pane, right-click xpctank and select View Signals.

3. Bind the signal to the instrument. To bind the TankLevel signal to the GaugeFluidLevel instrument, in the Applications pane, right-click xpctank and select View Signals. Drag the Signal icon next to signal TankLevel and drop it into the GaugeFluidLevel instrument. Next to the GaugeFluidLevel instrument, a small copy of the Signal icon appears.

4. Set the instrument range as required. Select the GaugeFluidLevel instrument, and then click the Tasks button in the top right corner.

5. In the GaugeFluidLevel Tasks dialog box, set property Min to 0 and property Span to 10.

6. Select a label. From the Palette pane, drag a Label layout item to underneath the GaugeFluidLevel instrument.

7. Configure the label. Click the Label element. In the lower right corner, select the Properties pane.

8. Scroll down to the Appearance node. Set the Text property to Tank Level, and then press Enter.

9. Scroll down to the TextAlign property. Click the down arrow and click the center block of the nine blocks presented. The TextAlign property becomes MiddleCenter.

10. Click the Save button.

Using a similar procedure, add an LED instrument to the instrument panel and bind signal ControlValue to it. Label the LED Control Value. At the end of this task, Simulink Real-Time Explorer displays the SetPoint, TankLevel, and ControlValue on the instrument panel.

Run the Model and Instrument Panel

You have built and downloaded the xpctank model and configured the xpctank_instr_design.slrtip instrument panel for the model. You can now run the model and instrument panel.

1. In the Applications pane, set property Stop time to inf.

2. To start model execution, in the Applications pane, click the real-time application, and then click the Start button.

3. To start the instrument panel, in the xpctank_instr_design.slrtip instrument panel, click the Run button.

4. Using the Slider instrument, set the tank level to the required value, such as 5. The tank level rises to and oscillates around the set point.

To stop model execution, in the Applications pane, click the real-time application, and then click the Stop button.

To stop the instruments, in the xpctank_instr_design.slrtip instrument panel, click the Stop button.

Add Signal of enum Type and Display with Instrument

For some signals or parameters in the model, it is helpful to define their data as type enum and use the enumerated values as the scale of the instrument display.

The instruments that support enumerated values as scales for signals are:

  • GaugeAngular
  • GaugeLinear
  • GaugeFluidLevel

The instruments that support enumerated values as scales for parameters are:

  • Knob
  • Slider

The LED on the instrument panel indicates the open or closed state of the valve that fills the tank.

Using a signal with enum data type, a more informative display for the state of the valve is available with a GaugeAngular instrument.

1. Open the xpctank model. open_system(docpath(fullfile(matlabroot,'toolbox','rtw','targets','xpc','xpcdemos','xpctank')))

2. In MATLAB, define the enum data type with this class definition with a function call, for example: run('../myEnumTypeDefinition.m')

This function defines the class as:

Simulink.defineIntEnumType('ControlValueState', ...
   {'Closed', 'Open'}, ...
   [0;10], ...
   'Description', 'Control value state', ...
   'DefaultValue', 'Closed', ...
   'HeaderFile', 'mycontrolvaluestate.h', ...
   'DataScope', 'Exported', ...
   'AddClassNameToEnumNames', true, ...
   'StorageType', 'int8');

3. In Simulink, update the xpctank model, by adding:

  • A Data Type Conversion block (DataTypeConversionToInt8) to convert the ControlValue signal data type to int8; set the block properties as shown:

  • A Data Type Conversion block (DataTypeConversionToEnum) to convert the int8 signal data type to enum; set the block properties as shown:

  • A Target Scope block to display the output

The updated model appears as shown:

4. Build the xpctank model and download the real-time application to the target computer.

5. Open the xpctank_instr_design.slrtip instrument panel in slrtexplr, and open the parameter and signal panels for the xpctank model as described in Configure Instruments for Signal Display.

6. Add a GaugeAngular instrument to the instrument panel.

7. Bind the DataTypeConversionToEnum signal to the GaugeAngular instrument.

8. Run the model and run the instrument panel as described in Run the Model and Instrument Panel.

The GaugeAngular instrument displays the state of the fill valve as Open or Closed.