Documentation Center

  • Trial Software
  • Product Updates

Debugging Common Modeling Errors

Debugging State Inconsistencies

In this exercise, you will introduce a state inconsistency error in your chart and troubleshoot the problem. Follow these steps:

  1. Open the model Stage6Simulate — either the one you created in the previous exercises or the supplied model for stage 6.

    To open the supplied model, enter the following command at the MATLAB® prompt:

    addpath(fullfile(docroot, 'toolbox', 'stateflow', 'gs', 'examples'))
  2. Save the model as Stage7Debug in your local work folder.

  3. Double-click Air Controller to open the chart.

  4. Delete the default transition to FAN2.Off by selecting it and pressing the Delete key.

    Removing the default transition will cause a state inconsistency error. (Recall from Checking That Your Chart Conforms to Best Practices that there must be a default transition at every level of the Stateflow® hierarchy that has exclusive [OR] decomposition.)

    Your chart should look like this:

  5. Save the chart, and start simulation.

    An error appears in the Diagnostic Viewer. The error indicates that a state (identified by number) has no default paths to a substate.

      Note:   The state number in your dialog display can differ from the one pictured above.

  6. Locate the offending state in the Air Controller chart, by clicking the link to the state number.

    FAN2 appears highlighted in the chart:

  7. Add back the default transition to FAN2.Off.

    The default transition provides an unconditional default path to one of the substates of FAN2.

  8. Simulate the model again.

    This time, simulation proceeds without any errors.

  9. Save Stage7Debug, and leave the chart open for the next exercise.

Debugging Data Range Violations

In this exercise, you will introduce a data range violation in your chart and use the debugger to troubleshoot the problem. Follow these steps:

  1. In the Air Controller chart, modify the during action in the SpeedValue state by adding 1 to the computed value, as follows:

    during: airflow = in(FAN1.On) + in(FAN2.On) + 1;

    Recall that in Defining the Inputs and Outputs, you set a limit range of 0 to 2 for airflow. By adding 1 to the computation, the value of airflow will exceed the upper limit of this range when two fans are running.

  2. Open the Stateflow debugger and make the following changes:

    • Under Error checking options, make sure that Data Range is selected.

    • Clear all breakpoints.

  3. Start simulation.

    Simulation pauses after 350 seconds because of an out-of-range data error:

    As expected, the error occurs in the during action of SpeedValue because the value of airflow is out of range.

  4. To isolate the problem, double-click the last line in the status panel at the bottom of the dialog box:

    Data '#439 (0:0:0)': 'airflow'

    The Model Explorer opens on your desktop, allowing you to view the properties of airflow in the right, read-only pane (read-only because simulation is running).

      Note:   The ID number of the data that appears in the debugger can vary from the value shown.

  5. Check the limit range for airflow:

  6. Back in the debugger, check the value of airflow by clicking Browse Data > Watched Data (Current Chart).

    airflow = 3

    This value exceeds the upper limit of 2.

  7. Stop simulation.

  8. Restore the during action to its previous code, and then restart simulation for the model.

    The model should simulate with no errors or warnings.

Was this topic helpful?