Documentation Center

  • Trial Software
  • Product Updates

Monitor Test Points in Stateflow Charts

About Test Points in Stateflow Charts

A Stateflow® test point is a signal that you can observe during simulation — for example, by using a Floating Scope block. You can designate the following Stateflow objects as test points:

  • Any state

  • Local data with the following characteristics:

    • Can be scalar, one-dimensional, or two-dimensional in size

    • Can be any data type except ml

    • Must be a descendant of a Stateflow chart

You can specify individual data or states as test points by setting their TestPoint property via the Stateflow API or in the Model Explorer (see Set Test Points for Stateflow States and Local Data with the Model Explorer).

You can monitor individual Stateflow test points with a floating scope during model simulation. You can also log test point values into MATLAB® workspace objects.

You can also use active state output to view or log state activity data in Simulink. For more information, see About Active State Output.

Set Test Points for Stateflow States and Local Data with the Model Explorer

You can explicitly set individual states or local data as test points in the Model Explorer. The following procedure shows how to set individual test points for Stateflow states and data.

  1. Create this model:

    The model consists of a Sine Wave block that triggers a Stateflow chart using the input trigger event tic.

  2. Add the following states and transitions to your chart:

    The state A and its substate X are entered on the first tic event. State A and substate X stay active until 10 tic events have occurred, and then state B is entered. On the next event, state A and substate X are entered and the cycle continues.

    The data x belongs to substate X. The entry and during actions for substate X increment x while X is active for 10 tic events. When state B is entered, x reinitializes to zero, and then the cycle repeats.

  3. Save the model with the name myModel.

  4. Open the Model Configuration Parameters dialog box.

  5. In the Solver pane, specify solver options:

    1. Set Type to Fixed-step.

    2. Set Solver to discrete (no continuous states).

    3. Set Fixed-step size (fundamental sample time) to 0.1.

    4. Click OK.

  6. Open the Model Explorer.

  7. In the Model Explorer, expand the myModel node and then the Chart1 node.

  8. Right-click A and select Properties.

  9. In the Logging pane of the properties dialog box, select the Test point check box and then click OK.

    This step creates a test point for the state A.

  10. Repeat the previous step for states A.X and B.

  11. In the Model Explorer, select state X again.

  12. Right-click the local data x and select Properties.

  13. In the properties dialog box, select the Test point check box and then click OK.

  14. Close the Model Explorer and save the model.

You can also log these test points. See Log Multiple Signals At Once for instructions on using the Signal Logging dialog box. See Log Chart Signals Using the Command-Line API for instructions on logging signals at the MATLAB command line.

Monitor Data Values and State Self Activity Using a Floating Scope

In this section, you configure a Floating Scope block to monitor a data value and the self activity of a state.

  1. Create this model:

    The model consists of a Floating Scope block and a Stateflow chart.

  2. Add the following states and transitions to your chart:

    The chart starts by adding an increment of 0.02 for 10 samples to the data x1. For the next 10 samples, x1 increments by 0.2, and then the cycle repeats.

  3. Save the model.

  4. Open the Model Configuration Parameters dialog box.

  5. In the Solver pane, specify solver options:

    1. Set Type to Fixed-step.

    2. Set Solver to discrete (no continuous states).

    3. Set Fixed-step size (fundamental sample time) to 0.1.

    4. Click OK.

  6. Specify states A and B as test points:

    1. In the chart, right-click each state and select Properties.

    2. In the Logging pane of the State properties dialog box, select Test point.

    3. Click OK.

  7. Add x1 as local data:

    1. Select Chart > Add Other Elements > Local Data .

    2. Change the name to x1.

    3. Click OK.

  8. Specify data x1 as a test point:

    1. Open the Model Explorer.

    2. In the Model Hierarchy pane, navigate to the chart.

    3. In the Contents pane, right-click x1 and select Properties.

    4. In the Logging pane of the Data properties dialog box, select Test point.

    5. Click OK.

    6. Close the Model Explorer.

  9. Double-click the Floating Scope block to open the window.

  10. In the Floating Scope window, click the Signal Selection icon .

    The Signal Selector dialog box appears with a hierarchy of Simulink® blocks for the model.

  11. In the Model hierarchy pane, select the chart whose signals you want to monitor and in the List contents pane, select the signals.

  12. Simulate the model.

    You see a signal trace for x1 and the activity of state A.

    When state A is active, the signal value is 1. When that state is inactive, the signal value is 0. Because this value can be very low or high compared to other data, you might want to add a second Floating Scope block to compare the activity signal with other data.

Was this topic helpful?