In phase 7 of this workflow, you debug the chart.
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 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 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
troubleshoot the problem. To enable data range violation checking, set
Simulation range checking in the Diagnostics:
Data Validity pane of the Configuration Parameters dialog box to
error
.
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.
Start simulation.
Simulation pauses 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 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 airflow
:
Hover your cursor over airflow
to view the
value.
airflow
= 3
This value exceeds the upper limit of 2.
Stop simulation.
Restore the during
action to its previous code, and
then restart simulation for the model.
The model should simulate with no errors or warnings.