|On this page…|
In this exercise, you will introduce a state inconsistency error in your chart and troubleshoot the problem. Follow these steps:
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')) Stage6Simulate
Save the model as Stage7Debug in your local work folder.
Double-click Air Controller to open the chart.
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:
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.
Locate the offending state in the Air Controller chart, by clicking the link to the state number.
FAN2 appears highlighted in the chart:
Add back the default transition to FAN2.Off.
The default transition provides an unconditional default path to one of the substates of FAN2.
Simulate the model again.
This time, simulation proceeds without any errors.
Save Stage7Debug, and leave the chart open for the next exercise.
In this exercise, you will introduce a data range violation in your chart and use the debugger to troubleshoot the problem. Follow these steps:
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.
Open the Stateflow debugger and make the following changes:
Under Error checking options, make sure that Data Range is selected.
Clear all breakpoints.
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.
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).
Check the limit range for airflow:
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.
Restore the during action to its previous code, and then restart simulation for the model.
The model should simulate with no errors or warnings.