In this exercise, you will introduce a state inconsistency error in your chart and troubleshoot the problem. Follow these steps:
Open the model
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
your local work folder.
Double-click Air Controller to open the chart.
Delete the default transition to
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 the state
FAN2 has no default
paths to a substate.
Note: The state number in your dialog display can differ from the one pictured above.
Locate the offending state in the Air Controller chart, by clicking the link to the state name.
FAN2 appears highlighted
in the chart:
Add back the default transition to
The default transition provides an unconditional default path
to one of the substates of
Simulate the model again.
This time, simulation proceeds without any errors.
Stage7Debug, and leave the
chart open for the next exercise.
In this exercise, you will introduce a data range violation
in your chart and troubleshoot the problem. To enable data range violation
checking, set Simulation range checking in the Diagnostics:
Data Validity pane of the Configuration Parameters dialog
Follow these steps:
In the Air Controller chart, modify 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.
Simulation pauses because of an out-of-range data error:
As expected, the error
occurs in the
during action of
the value of
airflow is out of range.
To isolate the problem, double-click the last line in the error message:
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 error message can vary from the value shown.
Check the limit range for
Hover your cursor over
view the value.
airflow = 3
This value exceeds the upper limit of 2.
during action to its
previous code, and then restart simulation for the model.
The model should simulate with no errors or warnings.