Stateflow | ![]() ![]() |
Simulating the "fuel rate controller" Model
On starting the simulation, and assuming no sensors have failed, the Stateflow diagram initializes in the Warmup
mode in which the oxygen sensor is deemed to be in a warmup phase. If Stateflow is placed into animation mode, the current state of the system can clearly be seen highlighted on the Stateflow diagram, as shown.
After a given time period, defined by o2_t_thresh
, the sensor is deemed to have reached operating temperature and the system settles into the normal mode of operation, shown above, in which the fueling mode is set to NORMAL
.
As the simulation progresses, the chart is woken up synchronously every 0.01 second. The events and conditions that guard the transitions are evaluated and if a transition is valid, it is taken and animated on the Stateflow diagram.
To illustrate this, you can provoke a transition by switching one of the sensors to a failure value on the top-level Simulink model. The system detects throttle and pressure sensor failures when their measured values fall outside their nominal ranges. A manifold vacuum in the absence of a speed signal indicates a speed sensor failure. The oxygen sensor also has a nominal range for failure conditions but, because zero is both the minimum signal level and the bottom of the range, failure can be detected only when it exceeds the upper limit.
Switch the Simulink switch for the manifold air pressure sensor to the off position to witness the following sequence of transitions (note the diagram that follows).
press_norm
state becomes valid as the reading is now out of bounds and the transition is taken to the press_fail
state, as shown.
Sens_Failure_Counter.INC
, which makes the triggering of the universal sensor failure logic independent of the sensor.
FL0
to FL1
in the Sens_Failure_Counter
superstate. Both transitions are animated on the Stateflow diagram.
Sens_Failure_Counter
state showing one failure, the condition that guards the transition from the Low_Emissions.Normal
state to the Rich_Mixture.Single_Failure
state is now valid and is therefore taken.
Fuel_Disabled
state is entered, the data fuel_mode
is set to RICH
, as shown.
The transitions taken in the preceding steps are depicted in the following simulation diagram. Step numbers appear next to the dashed indicator line.
A second sensor failure causes the Sens_Failure_Counter
to enter the Multifail
state, broadcasting an implicit event that immediately triggers the transition from the Running
state to the Shutdown
state. On entering the Fuel_Disabled
superstate the Stateflow data fuel_mode
is set to DISABLED
.
Implicit Event Broadcasts
The preceding example shows how the control logic can be represented in a clear and intuitive manner. The Stateflow diagram (or chart) has been developed in a way that allows the user, or a reviewer, to easily understand how the logic is structured. Implicit event broadcasts (such as enter(multifail)
) and implicit conditions (in(FL0)
) make the diagram easy to read and the generated code more efficient.
Modifying the Model
To illustrate how easy it is to modify the model, consider the Warmup
fueling state in the fuel control logic. At the moment the fueling is set to the low emissions mode (note the highlighted default transition at the bottom).
You might decide that when the oxygen sensor is warming up, changing the warmup fueling mode to a rich mixture would be beneficial. In the Stateflow chart you can easily achieve this by changing the parent of the Warmup
state to the Rich_Mixture
state. This is accomplished by enlarging the Rich_Mixture
state and moving the Warmup
state into it from the Low_Emissions
state. This alteration is obvious to all who need to inspect or maintain the code as shown in the following result (note the highlighted default transition at the bottom):
The results of changing the algorithm can be seen in the following graphs of air/fuel mixture ratio for the first few seconds of engine operation after startup. The left graph shows the air/fuel ratio for the unaltered system. The right graph for the altered system shows how the air/fuel ratio stays low in the warming up phase indicating a rich mixture.
![]() | Control Logic of the "fuel rate controller" Model | Using Stateflow | ![]() |