Stateflow User's Guide Previous page   Next Page

Adding a Sensor Event

To take advantage of sensors monitoring a physical plant, you need to check the sensor value at regular intervals. Proper control of a physical plant can be maintained only if a sensor measurement reports at regular intervals. For example, a controlling application might need to monitor the temperature or pressure of a device every second. If it waits for an hour before the next measurement is taken, undesired consequences can result.

You can simulate a sensor reading in Simulink with a regularly occurring sensor event and sensor data representing the value reported by the sensor. In Simulink, you use a regularly changing source to output a trigger event for determining times during which you read the sensor value.

Use a sine wave source in Simulink to add a sensor event to trigger a Stateflow block in the following procedure:

  1. If not already loaded, load the Simulink model SFcontrol2 you save at the end of Modifying Output Data with Actions and save it as SFcontrol3.

  2. In the Stateflow diagram editor, from the Add menu, select Event and add an event named temp_event on port 3 with the scope Input from Simulink, and a Rising trigger type.
  1. A port for the new event temp_event does not appear in the Simulink model because all input events are grouped into the trigger port at the top of the Controller block.

  1. Double-click the Mux block and change its Number of inputs to 3.
  2. Click-drag the top and bottom ends of the Mux block bar to show all three ports clearly, as shown.

  3. In the Simulink library browser, in the Sources library, click-drag a Sine Wave block to a position under the Constant blocks that feed the Manual Switch.
  4. Connect the Sine Wave block output to the bottom input of the Mux block.

  5. Double-click the Sine Wave block and change the Frequency to 2*pi.
  1. Because the event temp_event is a rising edge trigger, it is triggered (broadcast) every time its input signal crosses zero while rising. Because the Sine Wave block now outputs a complete sine wave every second, temp_event is broadcast to the Stateflow diagram every second, as shown.


Previous page  Adding a Sensor to the Model Adding Sensor Data Next page

© 1994-2005 The MathWorks, Inc.