Home Download Register Become an Affiliate Contact
Tutorials Submenu
My Second LabHSM Project
Up
My First LabHSM Project
My Second LabHSM Project
My Third LabHSM Project
My Fourth LabHSM Project

 
 

by

Where's the Action?

The boss complained that the first project didn't DO anything. That's a fair complaint. Would you watch a western with no action? (Of course, we SAID we weren't including any actions.)

OK, what now. He suggested a traffic light. Sounds like a good idea. In fact, isn't our first project almost a traffic light? Compare Figures 1 and 2.

Old ABC state chart.
Figure 1:  A Simple State Chart

      

State chart with A, B, and C in red, green, and yellow respectively.
Figure 2: A Traffic Light State Chart

You certainly don't want to go directly from green to red without passing through yellow; that would really cause a pile-up! Would you ever want to go from red to yellow? I have seen a red-yellow-green progression in a downtown area (I think in Colorado), apparently to move traffic through an intersection as fast as possible. And, of course, there is always the Christmas tree at the drag races! You can decide whether to add a yellow-green transition or remove the red-yellow one; I'll just leave it as is.

Defining and Implementing the Actions

What actions do we need? We need to turn on and turn off each of the three colored lights. As the project is defined at the moment, we could define three compound actions: a Turn on Green that also turned the others off, and its equivalents for the other colors. But if we define six simple actions instead (turn off and turn on for each of the three colors), we will have the flexibility to implement the red and yellow pedestrian light used in Boston and the two-color traffic light that I saw a long while ago in Upstate New York, where the role of the yellow light was filled by turning on red and green simultaneously. More important for the tutorial, we'll get to specify both Entry and Exit Actions for our states.

This project builds on the first project, so go back and do that, if you haven't already. Then...

Open Demo_ABC.vi, so we'll have access to all the LabVIEW and LabHSM capabilities;

Save it as Demo_TrafficLight.vi, to start the new project and disconnect from the old;

Open the block diagram and scroll so that the case label of the Actions Case Structure is visible (Figure 3).

Open the LabHSM Editor... from the Tools menu.

Click the OPEN button,

Open Demo_ABC.hsm.

SAVE AS Demo_TrafficLight.hsm, to connect it with the VI in memory.

Click the Actions List button to open the Actions List Editor.

Push the LabHSM Editor mostly off screen and position the Actions List Editor as in Figure 3.

Click Add New After.

Type Turn on Green in the dialog box (Figure 3).

Click the OK button or hit the return key to close the dialog.

"Whamo!" The screen flashes and you have a new action case as well as a new action in the list (Figure 4).

Actions List Editor with "Run State Machine" case in background.
Figure 3:  Actions List Editor

      

"Turn on Green" case is generated automatically.
Figure 4:  New "Turn on Green" Action and Case

This new case looks empty but, if you scroll down, you'll find that it is not. The FSM Frequently Used Data cluster is wired across the bottom of the case. This wiring was needed to keep the VI from breaking when we added the new case. When you ask for a New action, you get a copy of the Do Nothing action. In fact, although the action itself has been added where we asked, you'll find the case listed immediately after the Do Nothing case. To avoid confusion, I'd suggest reordering the cases using the pop-up Rearrange...>>Sort. We'll do that later, so you can skip it for now if you'd like.

Now add the code to actually turn the green light on. First, we need a green light. If necessary, scroll back to the top of the case near the Turn on Green label.

Place a Classic Round Light on the front panel and label it Green.

The terminal should appear near the top of the Turn on Green case in the diagram.

Pop-up on the terminal and create a constant.

Click the constant to TRUE, since this is a "turn on" action (Figure 5).

Turn on Green case with terminal and constant.
Figure 5:  "Turn on Green" Case

      

Turn off Red case showing all actions.
Figure 6:  Create All Action Cases

To get the other lights,

Click Add Copy After;

Type over Green with Yellow;

Click OK or hit return;

Repeat, replacing Yellow with Red.

It doesn't look like anything happened on the block diagram this time, but it did! Click the increment button of the case label (or use the drop down list) and you'll move to the Turn on Yellow case, right after the Turn on Green, as you directed.

Relabel the Green 2 terminal Yellow and the Green 3 terminal Red.

If you've been following exactly, the Turn on Red action is still highlighted in the Actions List Editor. Let's create the corresponding Turn off Red action.

Click Add Copy After.

Type over on with off.

Hit return.

Select the Turn off Red case. The following operations change it to match Figure 6, above.

Pop-up on Red 2 and create a local variable.

Click the Red 2 local variable and set it to Red, so it controls the correct light.

Delete the Red 2 indicator; we don't need it.

Wire the constant to the local variable.

Change the constant to FALSE.

Now the Red actions are correct. Duplicate this last action to finish the Yellow and Green.

Click Add Copy Before.

Type over Red with Yellow.

Hit return.

Click Add Copy Before.

Type over Yellow with Green.

Hit return.

Once again, the action cases are not in the order of the actions list.

Select the Turn off Yellow action and set its local variable to Yellow.

Select the Turn off Green action and set its local variable to Green.

Drag the Actions around the actions list to match Figure 6, above, or some other reasonable order.

Pop-up on the case label and Rearrange...>>Sort to get the case order to match the list.

With all the actions now defined, we need to assign them to their logical places as Entry and Exit Actions. In the LabHSM Editor:

Select state A in the lefthand window;

Click Rename, and rename it Red (Figure 7).

(The righthand window automatically updates to the new name.)

Click the first Entry Actions for Selected State.

Select the new Turn on Red action from the pop-up.

Click the first Exit Actions for Selected State.

Select Turn off Red from the pop-up.

(Note how intuitive all this is. Very little chance for errors and very few surprises for the next programmer to access the project.)

Renaming the Red state and assigning its actions.
Figure 7:  Actions for the Red State

Repeat this procedure to turn B into Green and C into Yellow.

Click SAVE.

The Traffic Light Itself

At the moment, the indicators on the front panel don't look much like a traffic light. Only the Green one is even the right color.

Temporarily drop a Classic Round LED on the panel.

Use the eyedropper to copy the on-state and off-state colors (separately) from the LED.

Apply each to the Red traffic light with the paint brush (Figure 8).

Delete the LED.

For the Yellow light,

Click on the paint brush's background color chip;

Choose the More Colors... palette option (Figure 8);

Match the red intensities to the green (Figure 9).

Now that the lights are colored, you can

Hide their labels;

Stack them with Red, on top;

Align them horizontally;

Distribute them vertical compressed (Figure 8).

(In a project for a client, I would have created some appropriate background artwork, but this is only a demo and that would not have taught you anything useful.)

Coloring lights on the panel.
Figure 8:  The Traffic Light

      

Mixing the yellow light's OFF color.
Figure 9: Setting the Yellow Color

Save the VI and the .hsm file then run the VI to prove you have a real working traffic light demo.

Paul F. Sullivan

Paul@SULLutions.com
http://www.SULLutions.com
      Back Next  
Universal HSM Template | LabHSM Editor | Getting Started | Tutorials | Included Examples | Links/References
2004-2005 H View Labs, Inc. All rights reserved.