| Stateflow® | ![]() |
| On this page… |
|---|
Overview of the "fuel rate controller" Model |
The modeling of a fault-tolerant fuel control system demonstrates how a Stateflow® chart in a Simulink® model can be used to model hybrid systems that contain both continuous dynamics and complex control logic.
Simulink blocks model behavior based on a given sample time. Each loop of its block diagram is assigned an increment of sample time. Stateflow chart execution does not consider sample time. Internally, the chart can take many cycles of execution, which are assumed to take place during the sample time assigned in a Simulink model.
The model described represents a fuel control system for a gasoline engine. This robust control system reacts to the detection of individual sensor failures and is dynamically reconfigured for uninterrupted operation. The mass flow rate of air pumped from the intake manifold, divided by the fuel rate, which is injected at the valves, gives the air/fuel ratio. The ideal mixture ratio provides a good compromise between power, fuel economy, and emissions. A target air/fuel ratio of 14.6 is assumed in this system.
A sensor (EGO) determines the amount of residual oxygen present in the exhaust gas. This sensor gives a good indication of the air/fuel ratio and provides a feedback measurement for closed-loop control. If the sensor indicates a high oxygen level, the controller increases the fuel rate. If the sensor detects a fuel-rich mixture (corresponding to a very low level of residual oxygen), the controller decreases the fuel rate.
The following figure shows the top level of the Simulink model (fuelsys.mdl). The model consists of a fuel rate controller and a subsystem to simulate engine gas dynamics.

The fuel rate controller uses signals from the system sensors to determine the fuel rate that gives an ideal mixture. The fuel rate combines with the actual air flow in the engine gas dynamics model to determine the resulting mixture ratio as sensed at the exhaust.
To simulate failures in the system, you can selectively disable each of the four sensors: throttle angle, speed, exhaust gas (EGO), and manifold absolute pressure (MAP). These sensors appear in the Simulink model as Manual Switch blocks. You can toggle the position of a switch by double-clicking the icon prior to or during a simulation. Similarly, you can force the failure condition of a high engine speed by toggling the switch on the far left.
The controller uses the sensor input and feedback signals to adjust the fuel rate to provide an ideal ratio. The model uses four subsystems to implement this strategy: control logic, sensor correction, airflow calculation, and fuel calculation. Under normal operation, the model estimates the airflow rate and multiplies the estimate by the reciprocal of the desired ratio to give the fuel rate. Feedback from the oxygen sensor provides a closed-loop adjustment of the rate estimation to maintain the ideal mixture ratio.

A detailed explanation of the Simulink blocks of the fault-tolerant control system is given in Using Simulink and Stateflow in Automotive Applications, a Simulink-Stateflow Technical Examples booklet published by The MathWorks, Inc. This section concentrates on the control logic implemented in a chart, but these key points are crucial to the interaction between Simulink models and Stateflow charts:
The control logic monitors the input data readings from the sensors.
The logic determines from these readings the sensors that have failed and outputs a failure state Boolean array as fail_state.
Given the current failure state, the logic determines in which fueling mode the engine should run.
The fueling mode can be one of these options:
Low emissions mode is the normal mode of operation where no sensors have failed.
Rich mixture mode occurs when a sensor has failed, to ensure smooth running of the engine.
Shutdown mode occurs when more than one sensor has failed, rendering the engine inoperable.
The Stateflow chart outputs fueling mode and failure state as fuel_mode and fail_state, respectively, to the rest of the model, which determines the fueling calculations.
The Stateflow chart that implements control logic for the fuelsys model looks like this:

The chart contains six parallel states with dashed boundaries that represent concurrent modes of operation.
The four parallel states at the top of the chart correspond to four individual sensors. Each of these states has a substate that represents the normal or failing status of that sensor. These substates are mutually exclusive. For example, if the throttle sensor fails then the active substate of the Throttle state is fail.
Transitions determine how states can change and can be guarded by conditions. For example, the active state can change from the normal state to the fail state when the measurement from the throttle sensor exceeds max_throt or is below min_throt.
The two parallel states at the bottom consider the status of the four sensors simultaneously and determine the overall system operating mode. The Fail superstate stores the total number of sensor failures. This state is polled by the Fueling_Mode state that determines the fueling mode of the engine. If a single sensor fails, operation continues but the air/fuel mixture is richer to allow smoother running at the cost of higher emissions. If more than one sensor has failed, the engine shuts down as a safety measure, because the air/fuel ratio cannot be controlled reliably.
Although you can run Stateflow charts asynchronously by injecting events from a Simulink model, the fueling control logic is polled synchronously at a rate of 100 Hz. Therefore, the sensors are checked every 1/100 second to see if they have changed status, and the fueling mode is adjusted accordingly.
On starting the simulation, and assuming no sensors have failed, the Stateflow chart initializes in the Warmup mode in which the oxygen sensor is in a warm-up phase.
If you animate the Stateflow chart, you can see the current state of the system highlighted on the chart.

After a given time period, defined by o2_t_thresh, the sensor reaches 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 wakes up 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 chart.
For example, you can force a transition by switching a sensor to a failure value on the top-level Simulink model. The system detects throttle and pressure sensor failures when their measured values fall outside 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 the oxygen level exceeds the upper limit.
Flip the Simulink switch for the manifold air pressure (MAP) sensor to the off position to see this sequence of transitions.
Switching the Simulink MAP sensor switch causes a value of zero to be read by the fuel rate controller.
When the chart next wakes up, the transition in the Pressure state from the normal substate to the fail substate occurs as the reading is now out of bounds.
When a sensor fails, the chart always broadcasts the event Fail.INC, which makes triggering of global sensor failure logic independent of the sensor.
This event causes a second transition from None to One in the Fail superstate.
With the Fail superstate 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. Therefore, the transition occurs.
After the transitions in the preceding steps occur, the chart appears as follows.

A second sensor failure causes the Fail superstate to enter the Multi state, broadcasting an implicit event that 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.

The preceding example shows how you can represent control logic clearly. For example, conditions such as in(Fail.None) make the chart easy to read and the generated code more efficient.
To illustrate how to modify the model, consider the Warmup state in the Fueling_Mode superstate. By default, fueling is set to the low emissions mode.

Suppose that changing the warm-up fueling mode to a rich mixture is beneficial. To modify the model, follow these steps:
In the Stateflow chart, enlarge the Rich_Mixture state.
Move the Warmup state from the Low_Emissions state to the Rich_Mixture state.
The modified Fueling_Mode superstate should look something like this:

You can see the results of this change by observing the air/fuel mixture ratio for the first few seconds of engine operation. The left graph shows the air/fuel ratio for the original system. The right graph shows how the air/fuel ratio stays low during warm-up, indicating a rich mixture for the modified system.

![]() | Stateflow® Hierarchy of Objects | Stateflow® Chart Notation | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |