Products & Services Solutions Academia Support User Community Company

Learn more about xPC Target   

Monitoring Signals

Introduction

Signal monitoring is the process for acquiring signal data during a real-time run without time information. The advantage with signal monitoring is that there is no additional load on the real-time tasks. Use signal monitoring to acquire signal data without creating scopes that run on the target PC.

In addition to signal monitoring, the xPC Target software enables you to monitor Stateflow® states as test points through the xPC Target Explorer and MATLAB command-line interfaces. You designate data or a state in a Stateflow diagram as a test point. This makes it observable during execution. See the Stateflow and Stateflow Coder User's Guide for details. You can work with Stateflow states as you do with xPC Target signals, such as monitoring or plotting Stateflow states.

After you start running a target application, you can use signal monitoring to get signal data.

Signal Monitoring with xPC Target Explorer

This procedure uses the model xpcosc.mdl as an example, and assumes you created and downloaded the target application to the target PC. For meaningful values, the target application should be running.

  1. If xPC Target Explorer is not started, start it now. In xPC Target Explorer, select the node of the running target application in which you are interested, for example, xpcosc.

    The target PC Target Application Properties pane appears.

  2. In the Solver pane, change the Stop time parameter to inf (infinity). Click Apply.

  3. To get the list of signals in the target application, expand the target application node, then expand the Model Hierarchy node under the target application node.

    The model hierarchy expands to show the Simulink objects (signals and parameters) in the Simulink model.

    The Model Hierarchy node can have the following types of nodes:

    IconsNodes
    Subsystems, including their signals and parameter
    Referenced models, including their signals set as test points
    Parameters
    Signals
    Stateflow states set as test points

    Only xPC Target tunable parameters and signals of the application, as represented in the Simulink model, appear in the Model Hierarchy node.

      Note   This example currently has only parameters and signals. If a block has a name that consists of only spaces, xPC Target Explorer does not display a node for that block. To monitor a signal from that block, provide an alphanumeric name for that block and rebuild and download that block.

    If you make changes (such as adding an xPC Target scope) to the model associated with the downloaded application, then rebuild that model and download it again to the target PC, you should reconnect to the target PC to refresh the Model Hierarchy node.

  4. To view only labeled signals (the xPC Target software refers to Simulink signal names as signal labels) ,:

    1. Open the xpcosc.mdl file.

    2. Right-click a signal line and name that signal. For example, right-click the output of the Signal Generator block and name it SignalG.

    3. Build and download the updated model.

    4. When the updated model is displayed in xPC Target Explorer, right-click the Model Hierarchy node and select View Only Labeled Signals. This command assumes that you have labeled one or more signals in your model.

    5. Re-expand the Model Hierarchy node to see the labeled signals.

      To view the block path for a labeled signal, hover over the labeled signal. For example,

      To display all the model signals again, right-click the Model Hierarchy node and select View All Signals. You can still view the signal label by hovering over the labeled signal. For example,

    6. Return to the model, remove the signal name you added, and rebuild and download the target application. The remaining examples in this section assume that you do not have any labelled signals in your model.

  5. To go to the corresponding Simulink model subsystem, right-click the application node and select Go to Simulink subsystem or block.

  6. To get the value of a signal, select the signal in the Model Hierarchy node.

    The value of the signal is shown in the right pane.

  7. Right-click the target application and select Start.

    The application starts running.

  8. To change the numeric format display of the signal, right-click the Model Hierarchy node and select Edit Signals Format String.

    The Display Format String dialog box is displayed.

  9. Enter the signal format. Use one of the following. By default, the format is %0.25g.

    Type

    Description

    %e or %E

    Exponential format using e or E

    %f

    Floating point

    %g

    Signed value printed in f or e format depending on which is smaller

    %G

    Signed value printed in f or E format depending on which is smaller

Monitoring Signals from Referenced Models

You can monitor signals from referenced models the same way that you do any other signal, with the exception that you must set the test point for the signal in the referenced model before you can monitor it.

Signal Monitoring with the MATLAB Interface

This procedure uses the model xpc_osc3.mdl as an example, and assumes you created and downloaded the target application to the target PC. It also assumes that you have assigned tg to the appropriate target PC.

  1. To get a list of signals, type either

    set(tg, 'ShowSignals', 'On') 

    or

    tg.ShowSignals='On'

    The latter command causes the MATLAB window to display a list of the target object properties for the available signals. For example, the signals for the model xpc_osc3.mdl are shown below. Note that the Label column is empty because there are no labelled signals in the model. If your signal has a label, its label is displayed in this column.

    ShowSignals = on
       Signals = INDEX  VALUE            BLOCK NAME          LABEL
                 0      0.000000         Signal Generator
                 1      0.000000         Transfer Fcn
  2. To get the value of a signal, use the getsignal method. In the MATLAB Command Window, type

    tg.getsignal(0)

    where 0 is the signal index. the MATLABinterface displays the value of signal 1.

    ans= 
    		3.731

See also Signal Tracing with the MATLAB Interface.

Monitoring Stateflow States

This procedure uses the model old_sf_car.mdl as an example. It describes one way to set Stateflow states as test points for monitoring.

  1. In the MATLAB window, type

    old_sf_car
  2. In the Simulink window, click Simulation > Configuration Parameters.

    The Configuration Parameters dialog box is displayed for the model.

  3. Click the Real-Time Workshop node.

    The Real-Time Workshop pane opens.

  4. To build a basic target application, in the Target selection section, click the Browse button at the System target file list. Click xpctarget.tlc, then click OK.

  5. As necessary, you can click the xPC Target options node and continue to make changes.

  6. When you are done, click OK.

  7. In the old_sf_car model, double-click the shift_logic chart.

    The shift_logic chart is displayed.

  8. In the chart, click Tools > Explore.

    The Model Explorer is displayed.

  9. In the Model Explorer, expand sf_car.

  10. Expand shift_logic.

  11. Expand gear_state, then select first.

  12. In the rightmost pane, State first, select the Test point check box. This creates a test point for the first state.

  13. Click Apply.

  14. Build and download the sf_car target application to the target PC.

You can now view the states with xPC Target Explorer or the MATLAB interface.

Monitoring Stateflow States with xPC Target Explorer

This topic assumes that you have already set Stateflow states as test points (see Monitoring Stateflow States if you have not).

  1. If the xPC Target Explorer is not yet started, start it now and connect it to the target PC that has the downloaded sf_car target application.

  2. To view the test point in the xPC Target Explorer, expand the Model Hierarchy node and navigate to shift_logic. The test point gear_state.first appears like any other signal in the hierarchy, as follows:

  3. Choose the state as you do a signal to monitor.

Monitoring Stateflow States with the MATLAB Interface

This topic assumes that you have already set Stateflow states as test points (see Monitoring Stateflow States if you have not).

  1. To get a list of signals in the MATLAB Command Window, type

    tg=xpc
  2. To display the signals in the target application, type either

    set(tg, 'ShowSignals', 'On'); tg

    or

    tg.ShowSignals='On'

    The latter causes the MATLAB window to display a list of the target object properties for the available signals.

    For Stateflow states that you have set as test points, the state appears in the BLOCK NAME column like any signal. For example, if you set a test point for the first state of gear_state in the shift_logic chart of the sf_car model, the state of interest is first. This state appears as follows in the list of signals in the MATLAB interface:

    shift_logic:gear_state.first
    

    shift_logic is the path to the Stateflow chart and gear_state.first is the path to the specific state.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS