LabVIEW Statechart Module

Table of Contents

Statechart Module Tutorial Part 4: Adding Regions and Substates

  • Updated2023-02-21
  • 6 minute(s) read

In Parts 2 and 3 of this tutorial, you created a statechart consisting of two states, two pseudostates, and transitions between these objects. You also defined output types and state data types and configured a caller VI.

In Part 4 of this tutorial, you add hierarchical substates to the statechart, create a trigger using the Project Explorer window, and configure static reactions. You also modify statechart data.

  You can complete these exercises in approximately 30 minutes.
Note  You can refer to the labview\examples\Statechart\Tutorial\Synchronous\Getting Started 4.lvsc for a completed version of the statechart you create in this part of the tutorial.

Adding a Region and Two Substates

A region defines an area in which you can place states. You can place regions within states, which means you can use regions to define hierarchical substates. Complete the following steps to add a region and two substates to this statechart.

  1. Display the Statechart Editor window for the My Getting Started Statechart.lvsc statechart that you constructed in Part 3 of this tutorial. You also can navigate to the labview\examples\Statechart\Tutorial\Synchronous directory and open Getting Started 3.lvsc for the completed statechart from Part 3 of this tutorial. You can display the Statechart Editor window by double-clicking the Diagram.vi item in the Project Explorer window for the statechart.
  2. Move the cursor over the bottom of the Watch Running state until resizing handles appear.
  3. Drag the resizing handles down and to the right to increase the size of this state.
  4. Display the Statechart Development palette.
  5. Click the Region icon.
  6. Move the cursor within the Watch Running state. Click and drag to place this region on the statechart diagram.
  7. Notice the region is labeled Region. Enter Display as the new label.
  8. Place two states and an Initial pseudostate in this region.
  9. Label the first state Clock and the second state Timer.
  10. Save the statechart.

The statechart diagram now resembles the following image:

Note  The Watch Running state now contains two substates. Therefore, the Watch Running state now is a superstate.

Creating Another Trigger

The next step is creating a trigger. You will configure a transition to react to this trigger.

Complete the following steps to create this trigger.

  1. Display the Project Explorer window for this statechart.
  2. Double-click the Edit Triggers and Groups item. LabVIEW launches the Edit Triggers and Groups dialog box, which you use to create triggers and groups of triggers.
  3. Click the Create Trigger button to add a trigger to the list.
  4. Enter Mode as the name of this trigger.
  5. Click the OK button to save changes.

Creating and Configuring Transitions in a Region

The next step is creating and configuring two transitions in the Display region. Create and configure the following transitions:

  • From the Initial pseudostate to the Clock substate.
  • From the Clock substate to the Timer substate. Configure this transition to react to the Mode trigger only.
  • From the Timer substate to the Clock substate. Configure this transition to react to the Mode trigger only.

The statechart diagram now resembles the following image:

Configuring the Timer Substate

The next step is configuring the Timer substate by creating a static reaction to modify the Time Display output data you defined in Part 3 of this tutorial. A static reaction defines the behavior of a state while that state is not taking any outgoing transitions.

Complete the following steps to create a static reaction for the Timer substate.

  1. Double-click the border of the Timer substate. LabVIEW launches the Configure State dialog box.
    Note  When you configure a state, a wrench icon appears on the state () in the Statechart Editor window. The state also changes color. You can customize the configuration color for states. The default configuration color is yellow.


    The left side of this dialog box contains the Reactions list. By default, the dialog box displays the Entry Action item in the Reactions list. This selection specifies that you want to define the entry action of the state.

    The right side of this dialog box displays several tabs that correspond to the reaction you select from the Reactions list. By default, the Action tab is selected. This tab displays the block diagram you use to define the entry action.
  2. Click the Create button to add a static reaction to the Reactions listbox. Label the new static reaction Chrono Display.
  3. On the Action tab, notice the Outputs cluster element on the right side of this block diagram. Click this cluster element and select Outputs»Time Display. This element now displays Outputs.Time Display. You now can use this element to write to the value of the Time Display indicator.
  4. Click the Outputs cluster element on the left side of the block diagram and select StateData»Timer.
  5. Place the Convert Timer to Time Stamp VI on the diagram.
    1. On the Functions palette, select Select a VI to display the dialog box you use to select the subVI.
    2. Navigate to the labview\examples\Statechart\Tutorial\Synchronous directory and double-click Convert Timer to Time Stamp.vi.
    3. Place the VI on the block diagram.
    4. Wire the StateData.Timer cluster control to the Timer input of the Convert Timer to Time Stamp VI.
    5. Wire the date/time string output of the Convert Timer to Time Stamp VI to the Outputs.Time Display cluster control. The block diagram resembles the following image:

  6. Click the OK button to save the changes.

Configuring the Clock Substate

The next step is configuring the Clock substate to display the current time. You accomplish this by adding a static reaction to the Clock substate and using action code to display the current time in the Time Display output data.

Complete the following steps to configure the Clock substate.

  1. Double-click the border of the Clock substate to launch the Configure State dialog box.
  2. Create a static reaction. Label the new static reaction Display Time.
  3. On the Action tab, write LabVIEW code that displays the current time in the Time Display control.
    1. Click the Outputs cluster element on the left side of the diagram and select StateData»Clock.
    2. Place the Get Date/Time in Seconds and Format Date/Time String functions on the block diagram.
    3. Wire the current time output of the Get Date/Time in Seconds function to the time stamp input of the Format Date/Time String function.
    4. Right-click the time format string terminal of the Format Date/Time String function and select Create»Constant from the shortcut menu. Enter %I:%M:%S %p for the value of the constant.
    5. Click the Outputs cluster element on the right side of the diagram and select Outputs»Time Display.
    6. Wire the date/time string output of the Format Date/Time String function to the Outputs.Time Display cluster element. The block diagram resembles the following image:

  4. Click the OK button to save the changes.

Running the Caller VI

  1. In the Statechart Editor window, click the Generate Code button.
  2. Open the Getting Started Caller VI Linked VI you created in Part 3 of this tutorial.
  3. Run the caller VI.
  4. Click the Insert Battery front panel button. Notice the watch displays the current time.
  5. Click the Mode button. Notice the watch displays 00.00.00.0.
  6. Click the Quit front panel button.
  7. Save and close the VI and statechart.

Summary

In this tutorial, you learned the following tasks:

  • Creating regions.
  • Creating substates.
  • Creating triggers using the Project Explorer window.
  • Configuring reactions.
  • Modifying statechart data.

Where to Go from Here

In Part 5 of this tutorial, you add orthogonal regions and define the guard for a transition.

Log in to get a better experience