Skip to Main Content Skip to Search
Product Documentation

Monitoring 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:

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 Setting 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.

Setting 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 as myModel.mdl.

  4. Open the 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 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 Logging Multiple Signals At Once for instructions on using the Signal Logging dialog box. See Logging Chart Signals Using the Command-Line API for instructions on logging signals at the MATLAB command line.

Using a Floating Scope to Monitor Data Values and State Activity

In this section, you configure a Floating Scope block to monitor a data value and the 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 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 State properties dialog box, select Test point.

    3. Click OK.

  7. 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 Data properties dialog box, select Test point.

    5. Click OK.

    6. Close the Model Explorer.

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

  9. 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.

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

  11. 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.

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS