LabVIEW 2010 Statechart Module Help
»View Product Info
In Part 4 of this tutorial, you learned how to create and configure regions and substates. In Part 5 of this tutorial, you add orthogonal regions.
|| You can complete these exercises in approximately 35 minutes.
||Note You can refer to the labview\examples\Statechart\Tutorial\Synchronous\Getting Started 5.lvsc for a completed version of the statechart you create in this part of the tutorial.
Creating the Orthogonal Region
Orthogonal regions are multiple regions in the same state. Substates in orthogonal regions execute concurrently, which means these states both execute during a single iteration of the statechart. Complete the following steps to add orthogonal regions to the statechart.
- Display the Statechart Editor window for the My Getting Started Statechart.lvsc statechart that you constructed in Part 4 of this tutorial. You also can navigate to the labview\examples\Statechart\Tutorial\Synchronous directory and open Getting Started 4.lvsc for the completed statechart from Part 4 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.
- Click and drag to increase the size of the Watch Running superstate.
- Place a second region inside the Watch Running superstate below the Display region.
- Label this new region Timer.
- Place two states inside this region.
- Label the substates Idle and Running.
- Place an Initial pseudostate in the Timer region.
- Create the following transitions:
- From the Initial pseudostate to the Idle substate.
- From the Idle substate to the Running substate. Configure this transition to react to a Start trigger only.
- From the Running substate to the Idle substate. Configure this transition to react to a Stop/Reset trigger only.
The statechart diagram now resembles the following image:
Defining a Transition Guard
The next step is specifying that the statechart transitions from the Idle to the Running state only when the statechart also is executing the Timer substate. To specify this behavior, you use a transition guard. A transition guard is LabVIEW block diagram code that determines whether the statechart takes the associated transition. The guard code must return either TRUE or FALSE. If the guard returns TRUE, the statechart takes the transition. If the guard returns FALSE, the statechart does not take the transition.
Complete the following steps to define this guard.
- Double-click the transition node from the Idle state to the Running state to display the Configure Transition dialog box.
- Click the Guard tab.
- Click the Inputs cluster control on the left-side of the block diagram and select StatechartState.
- Use the IsIn function on the Statechart Communication palette to return TRUE if the Timer state is active.
- Place the IsIn function on the block diagram.
- Wire the StatechartState cluster control to the Statechart States input of the IsIn function.
- Wire the IsIn? output to the Execute? cluster element.
- Right-click the IsIn function and select Select State from the shortcut menu. LabVIEW displays the Select State dialog box. You use this dialog box to specify the state vector, which is the path of states and regions that contain the state.
- Select Watch Running»Display»Timer. The Current Selection text box displays Watch Running\Display\Timer.
- Click the OK button. The block diagram resembles the following image:
- Click the OK button to return to the statechart diagram.
- Repeat steps 1-4 to create a transition guard from the Running state to the Idle state.
- Save the statechart.
With this configuration, the statechart checks the guard code every time the caller VI sends the Start or Stop/Reset trigger. The guard code returns FALSE if the Timer substate is not active.
Modifying State Data
The next step is to modify state data while the Running and Idle states run. You do this by creating static reactions to modify the state data controls. Complete the following steps to modify the Timer and Clock state data controls.
- Define a static reaction in the Running state called Increment.
- On the Action tab, click the Outputs cluster element on the left side of the diagram and select StateData»Timer.
- Place the Add function on the block diagram.
- Wire the StateData.Timer cluster element to the x input of the Add function.
- Right-click the y input of the Add function and select Create»Constant from the shortcut menu.
- Enter 50 for the value of the constant.
- Click the Outputs cluster element on the right side of the diagram and select StateData»Timer.
- Wire the x+y output of the Add function to the StateData.Timer cluster element on the right side of the diagram. The action code for the Increment static reaction resembles the following image:
- Configure the Increment static reaction to react to all triggers.
- Navigate to the Triggers/Groups tab.
- Click the Select All Triggers button.
- Define a static reaction in the Idle state called Reset. You configure the Reset reaction to reset the Timer state data control to 0.
- On the Action tab, click the Outputs cluster control on the left side of the diagram and select StateData»Timer.
- Click the Outputs cluster control on the right side of the diagram and select StateData»Timer.
- Right-click the StateData.Timer cluster element on the right side of the block diagram and select Create»Constant from the shortcut menu. Leave the default value 0 for the constant.
- On the Triggers/Groups tab, specify the Reset static reaction only reacts to the Stop/Reset trigger.
- Click the OK button to close the Configure State dialog box.
- Save the statechart.
- Close the Statechart Editor window.
Enabling Debugging for the Statechart
If you want to use the debugging tools for a statechart, you first must enable debugging for the statechart.
Complete the following steps to enable debugging for the statechart.
- Right-click the My Getting Started Statechart.lvsc item in the Project Explorer window and select Properties from the shortcut menu. LabVIEW launches the Properties dialog box.
- Select the Statechart Code Generation item from the Category list. LabVIEW displays options relating to statechart code generation.
- Select Enabled from the Debugging pull-down menu to specify that debugging is enabled for the statechart. The default value is Enabled.
||Note Debugging is only available on Desktop, Real-Time, and FPGA targets.
- Click the OK button to save changes and return to the Project Explorer window.
- Right-click the My Getting Started Statechart.lvsc item and select Generate Code from the shortcut menu to generate code for the statechart.
Running the Caller VI Again
- Run the caller VI and watch the state data.
- Click the Insert Battery button. The Time Display indicator displays the current time.
- Click the Mode front panel button. The Time Display indicator displays 00.00.00.0, which means the statechart is in the Timer substate.
- Click the Start front panel button to start the timer.
- Click the Mode front panel button to switch the statechart to the Clock substate.
- Click the Mode front panel button again to switch back to the Timer substate. Notice the Time Display indicator continued to increment while the statechart was in the Clock substate.
- Click the Quit front panel button to stop the caller VI.
- Save the caller VI.
In this tutorial, you learned the following tasks:
- Creating orthogonal regions.
- Defining regions that execute concurrently.
- Defining the guard of a transition.
- Generating code for the statechart from the Project Explorer window.
Where to Go from Here
- Documentation related to the LabVIEW Statechart Module.
- The Getting Started with LabVIEW manual contains an in-depth introduction to LabVIEW, including several tutorials that showcase LabVIEW features.
- The LabVIEW Fundamentals book provides information about LabVIEW programming concepts, techniques, features, VIs, and functions you can use to create many types of applications.
- Refer to the National Instruments Web site for additional developer resources, training, technical support, and so on.
|(Windows) To view topics related to the Statechart Module, click the Locate button, shown at left, in the toolbar at the top of this window. The LabVIEW Help highlights this topic in the Contents tab so you can navigate the related topics.