Design Considerations for Defining the States

www.kxcad.net Home > CAE Software Index > MATLAB Index >


Your Ad Here

When to Use States

Whether or not to use states depends on the control logic you want to implement. Stateflow allows you to model two types of control logic: finite state machines and stateless flow charts. Each is optimized for different applications, as follows:

Control Logic Optimized for Modeling
Finite state machinesPhysical systems that transition between a finite number of operating modes. In Stateflow charts, you represent each mode as a state.
Stateless flow chartAbstract logic patterns — such as if, if-else, and case statements — and iterative loops — such as for, while, and do loops. These logic constructs are represented by connective junctions and transitions in Stateflow charts. No states are required. See Flow Diagram Notation with Connective Junctions in the online Stateflow User's Guide documentation.

The Stateflow Air Controller chart is a system that cools a physical plant by transitioning between several modes of operation and, therefore, can be modeled as a finite state machine. In the following sections, you will design the states that model each mode of operation.

Determining the States to Define

States model modes of operation in a physical system. To determine the number and type of states required for your Air Controller chart, you must identify each mode in which the system can operate. Often, a table or grid is helpful for analyzing each mode and determining dependencies between modes.

Analysis of Operating Modes

For Air Controller, the modes of operation are

Operating ModeDescriptionDependencies
Power OffTurns off all power in the control systemNo fan can operate when power is off.
Power OnTurns on all power in the control systemZero, one, or two fans can operate when power is on.
Fan 1Activates Fan 1Fan 1 can be active at the same time as Fan 2. When activated, Fan 1 can turn on or off.
Fan 1 OnCycles on Fan 1Fan 1 On can be active if Fan 1 is active and power is on.
Fan 1 OffCycles off Fan 1Fan 1 Off can be active if Fan 1 is active, and power is on.
Fan 2Activates Fan 2Fan 2 can be active at the same time as Fan 1. When activated, Fan 2 can turn on or off.
Fan 2 OnCycles on Fan 2Fan 2 On can be active if Fan 2 is active and power is on.
Fan 2 OffCycles off Fan 2Fan 2 Off can be active if Fan 2 is active and power is on.
Calculate airflowCalculates a constant value of 0, 1, or 2 to indicate how fast air is flowing. Outputs this value to the Simulink subsystem for selecting a cooling factor.Calculates the constant value, based on how many fans have cycled on at each time step.

Number of States to Define

The number of states depends on the number of operating modes to be represented. In Analysis of Operating Modes, you learned that the Air Controller chart has nine operating modes. Therefore, you need to define nine states to model each mode. Here are the names you will assign to the states that represent each operating mode in Implementing the States:

State NameOperating Mode
PowerOffPower Off
PowerOnPower On
FAN1Fan 1
FAN2Fan 2
SpeedValueCalculate airflow
FAN1.OnFan 1 On
FAN1.OffFan 1 Off
FAN2.OnFan 2 Off
FAN2.OffFan 2 Off

Determining the Hierarchy of States

Objects in Stateflow can exist in a hierarchy. For example, states can contain other states — referred to as substates — and, in turn, can be contained by other states — referred to as superstates. You need to determine the hierarchical structure of states you will define for the Air Controller chart. Often, dependencies among states imply a hierarchical relationship — such as parent to child — between the states.

Based on the dependencies described in Analysis of Operating Modes, here is an analysis of state hierarchy for the Air Controller chart:

Dependent StatesImplied Hierarchy
FAN1 and FAN2 depend on PowerOn. No fan can operate unless PowerOn is active.FAN1 and FAN2 should be substates of a PowerOn state.
FAN1.On and FAN1.Off depend on Fan1 and PowerOn. FAN1 must be active before it can be cycled on or off.FAN1 should have two substates, On and Off. In this hierarchical relationship, On and Off will inherit from FAN1 the dependency on PowerOn.
FAN2.On and FAN2.Off depend on FAN2 and PowerOn. FAN2 must be active before it can be cycled on or off.FAN2 should have two substates, On and Off. In this hierarchical relationship, On and Off will inherit from FAN2 the dependency on PowerOn.
The state that calculates airflow needs to know how many fans are running at each time step.The state that calculates airflow should be a substate of PowerOn so it can check the status of FAN1 and FAN2 at the same level of hierarchy.

Determining the Decomposition of States

The decomposition of a state dictates whether its substates execute exclusively of each other — as exclusive (OR) states — or can be activated at the same time — as parallel (AND) states. No two exclusive (OR) states can ever be active at the same time, while any number of parallel (AND) states can be activated concurrently.

The Air Controller chart requires both types of states. Here is a breakdown of the exclusive (OR) and parallel (AND) states required for the Stateflow chart:

StateDecompositionRationale
PowerOff, PowerONExclusive (OR) statesThe power can never be on and off at the same time.
FAN1, FAN2Parallel (AND) statesZero, one, or two fans can operate at the same time, depending on how much cooling is required.
FAN1.On, FAN1.OffExclusive (OR) statesFan 1 can never be on and off at the same time.
FAN2.On, FAN2.OffExclusive (OR) statesFan 2 can never be on and off at the same time.
SpeedValueParallel (AND) stateSpeedValue is an observer state that monitors the status of Fan 1 and Fan 2, updating its output based on how many fans are operating at each time step. SpeedValue must be activated at the same time as Fan 1 and Fan 2, but execute last so it can capture the most current status of the fans.

  


© 1984-2007 The MathWorks, Inc. Terms of Use Patents Trademarks Acknowledgments

Your Ad Here