Stateflow    

Create a Stateflow Diagram

The following steps describe how to create a simple Stateflow diagram using the graphics editor:

  1. Double-click the Stateflow block in the Simulink model window to invoke the graphics editor window.

  2. Select the State button in the toolbar (see preceding graphic).
  3. Move the cursor into the drawing area and left-click to place the state.
  4. Position the cursor over that state, click the right mouse button, and drag to another location in the drawing area to make a copy of the state. Release the right mouse button to drop the state at that location.
  5. Click the ? character within each state to enter each state label.
  1. Label the states with the titles Power_on and Power_off.

  1. Deselect the state to exit the edit.
  1. To deselect a state, click anywhere outside the state or press the Esc key. Your Stateflow diagram should look similar to the following:

  1. Draw a transition starting from Power_on and ending at Power_off by first placing the cursor at a straight portion of the border of the Power_on state. When the cursor changes to crosshairs, click-drag the mouse to the border of the Power_off state. When the transition snaps to the border of the Power_off state, release the mouse button.
  1. The crosshairs do not appear if you place the cursor on a corner, since corners are used for resizing.

  1. Draw another transition starting from Power_off and ending on Power_on.
  1. Your Stateflow diagram should look similar to this sample.

  1. Label the transition from Power_on to Power_off by first clicking the transition to select it. Click the ? character that appears alongside the transition and enter the label Switch. Press the Escape key to deselect the transition label and exit edit mode for this label.
  2. Label the transition from Power_off to Power_on with the same text, Switch.
  1. Your Stateflow diagram should look similar to this sample.

  1. Add a default transition by selecting the Default Transition tool (see preceding graphic in step 1) in the toolbar and dragging the mouse to a straight portion on the border of the Power_off state. Click and release the mouse when the arrowhead snaps to the border of the Power_off state. Your Stateflow diagram should look similar to this sample.


  Create a Simulink Model Define Input Events