LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

state machine

I have modified a state machine example. What I want to do is let the first frame run i.e. init, default followed by my choice. I want to be able to choose nickel, dime or quarter. I seem to run into some problems. Can someone help. The LV attached is in 6.0.
0 Kudos
Message 1 of 18
(4,685 Views)
I took a look at your vi. I am missing the "Next State.vi" but it looks like there is a problem in the "No Event" case. You are writing "false" to the boolean property nodes as you are checking whether a button was pressed. There is no data flow dependency between those operations, so I would expect irregular issues depending on which section of code gets executed first. You do not need the property nodes there at all. If your intention is to "unclick" the button after it is pressed, just change the mechanical action of the button by right-clicking on the button on the front panel, and selecting Mechanical Action > Latch When Released. Then delete the property nodes from that state. The buttons will depress until their values are read, and then they will automatically release.

You might also look into an event structure instead of polling the "No Event" case, but that's just a suggestion.

Good luck!
Chris
Message 2 of 18
(4,669 Views)
You did not include the Next State.vi in the .llb and that is likely where your problem is. I noticed that the enum in the array constant fed into Next State.vi and the Enum on the FP have values for which no state exists in the state machine (Return Change, for example). If a value is selected for which no state exists the default case (Init in your VI) will execute. I do not recall when the feature was added, so you may not have it in LV 6, but you can pop up on the border of the case structure and select "Add Case for every value." This will automatically create a case for every value defined on the Enum.

Lynn
Message 3 of 18
(4,667 Views)
First of all, you have a race condition in the No Event case.  The booleans are getting written to and read at the same time.  Which will happen first?  There is no guarantee.  Remove the property nodes that get written to and go to the init state to perform this action.  I did not have the subvi in the No Event case so I can't tell if this is where you are waiting for a selection.  I would guess the output of the missing subvi is the next state enum.  Another thing is the way you exit.  You should delete the check for exit wired to the loop stop sign.  Instead, use your Exit state.  Wire the true output from your message dialog function to the stop sign.  This way, your pop-up must be acknowledged before the vi can quit.  You need some condition to force the next state to the Exit case in order to quit.
 
Wow, I'm too slow.  Got beat by two people.

Message Edited by tbob on 08-15-2005 11:05 AM

- tbob

Inventor of the WORM Global
Message 4 of 18
(4,661 Views)
I have put in the new state.vi . Hope it helps. I want to run the init, default frame followed by the frame of my choice.
0 Kudos
Message 5 of 18
(4,652 Views)
Problem 1:  In your subvi, you have two arrays going into a For loop, and one array is bigger than the other.  The loop will only run up to the last element of the smallest array, which is your boolean array.  The enum array element, "Return", will never be processed so you might as well delete it.
Problem 2:  You still have the property nodes being written to in the No Event case.  Get rid of these.  As someone suggested, change the mechanical action of your controls to Latch When Pressed (right click, Mechanical Action).
Problem 3:  Change the way you exit.  Delete the equal sign and the exit enum.  Wire the true output from the dialog box in the Exit case to the top sign.
Do these, add code to the other states, then ask for help if you still need it.
- tbob

Inventor of the WORM Global
Message 6 of 18
(4,646 Views)
I had to add a constant into the nickel, dime, quarter case states to the right hand tunnel. I set this constant to "No Event" in each case. As it stands, you have no way to get to the exit state.
0 Kudos
Message 7 of 18
(4,646 Views)
I followed up on your advice. However I created a new problem. Hope someone can help. Here is the new LV.
0 Kudos
Message 8 of 18
(4,639 Views)
Since you have LV 6, I am attaching a picture of what your vi should look like.  Cases for Dime and Quarter are like the one for Nickel.  Notice that I don't use any subvi's, they are not necessary here.  Using a string for the next state is easier than using an enum.  I hope this works for you.
 
One more thing, in the No Event case, the smaller case structure has the next state.  When Nickel is selected, the next state is "Nickel" instead of "No event" as seen.  Dime's next state is "Dime", Quarter is "Quarter". and Stop is "Exit".  Case values for No Event, Nickel, Dime, Quarter, and stop are in order: 0, 1, 2, 4, 8.

Message Edited by tbob on 08-15-2005 02:19 PM

Message Edited by tbob on 08-15-2005 02:21 PM

- tbob

Inventor of the WORM Global
Message 9 of 18
(4,606 Views)
"Notice that I don't use any subvi's, they are not necessary here. Using a string for the next state is easier than using an enum." I am still a novice with labview. I find subvi's and enum easier to understand. Can you do the LV with subvi's and enum. Thanks.
0 Kudos
Message 10 of 18
(4,577 Views)