Documentation

Instrument a Tank Model

This example shows how to create a Simulink® Real-Time™ Explorer instrument panel for the xpctank model. The instrument panel contains the following 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).

Prerequisites

This example assumes that you can:

  1. Open Simulink® Real-Time™ Explorer.

  2. Start the target computer.

  3. Connect Explorer to the target computer.

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

  5. Build and download xpctank.

For more information, see Related Topics.

Create Instrument Panel

In this step, create and save an instrument panel for the xpctank model.

To create an instrument panel:

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

  2. Type a name and folder in the Name and Location text boxes. Give the panel a name like xpctank_instr_design.slrtip, and then press Enter .

  3. Click the Save button.

Configure Instrument for Parameter Tuning

In this step, select and configure an instrument to tune a parameter from the xpctank model. You must have previously created the xpctank_instr_design.slrtip instrument panel.

Parameter Characteristics

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 it to an exact value.

The Slider instrument meets the requirements for SetPoint. To set an exact numeric value, use, for example, a NumericEntry instrument.

Configure Slider Instrument

To select and configure the Slider instrument:

  1. Load the instrument panel. In the Panels pane, right-click the Instrument Panels node and select Existing. From the list, select xpctank_instr_design.slrtip.

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

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

  4. Bind the SetPoint parameter to the instrument. Drag the Parameter icon next to parameter SetPoint to the Slider instrument. A small copy of the Parameter icon appears next to the Slider instrument.

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

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

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

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

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

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

  11. Click the Save button.

At the end of this task, Simulink® Real-Time™ Explorer looks like this figure.

Configure Instruments for Signal Display

In this step, select and configure instruments to display two signals from the xpctank model. You must have previously created the xpctank_instr_design.slrtip instrument panel.

Signal Characteristics

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 meets the requirements for TankLevel. To display an exact numeric value, use, for example, a NumericDisplay instrument.

The signal characteristics for ControlValue are:

  • Type — Boolean

  • Range — 1, 0

  • Purpose — Represents the state of the pump (on or off).

The LED instrument meets the requirements for ControlValue.

Configure Instruments

To select and configure each instrument:

  1. Load the instrument panel. In the Panels pane, right-click the Instrument Panels node and select Existing. From the list, select xpctank_instr_design.slrtip.

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

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

  4. 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 to the GaugeFluidLevel instrument. A small copy of the Signal icon appears next to the GaugeFluidLevel instrument.

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

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

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

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

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

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

  11. 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 looks like this figure.

Run Instrumented Model

In this step, run the instrumented xpctank model. You must have previously built and downloaded the xpctank model and configured the xpctank_instr_design.slrtip instrument panel.

  1. Load the instrument panel. In the Panels pane, right-click the Instrument Panels node and select Existing. From the list, select xpctank_instr_design.slrtip.

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

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

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

  5. 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, as shown in this figure.

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

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

See Also

| |

Related Topics

Was this topic helpful?