From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with State Machine with Sequentail User Events

Solved!
Go to solution

I am trying to create a program using state machine which include user genreated events to jump between states. Also, I want the program to require a sequence of events to be genreted before entering certain states.

 

For example:

 

States: Init, Idle, A-1, A-2, A-3, B-1, and Stop

If state A-1 is selected, user must input parameter then select state A-2.
User may not directly jump to A-2 without having to enter state A-1
If user selects state A-1, he should have the ability to not input paramter and jump to another state such as B-1 or Stop

State A-3 can only be entered automatically by state A-2.

 

How do I program the state machine to do what I want? I have updated a sample program. I am unsure if I impleted the program correctly. The user panel locks up if I enter State A-1 then press the Stop button. It doens't allow me to exit State A-1 and forces me to go to State A-2.

 

Few other questions:

- How do I initialize all the boleean values to 0 during my Init state?

- Why do I need a value for Timeout?

Download All
0 Kudos
Message 1 of 7
(3,036 Views)

Aab-ufl,

 

I attached some sample code that meets your requirements.  It doesn't look amazing (or good, really) but I think it does what you want so it might give you some ideas about what you can do.  And yes I didn't use type-defs for enums then I forgot to add the Idle state so some enums don't have Idle because I was lazy.

 

I did have some questions about what happens in certain cases.

 

1. What are we doing in A3 and B1?  I ended up going right back to Idle.

2. In the Idle state, which states can we get to?  I assumed we could only get to A1 and Stop because it was easiest.

3. What is the point of having A2 and A3 as seperate steps if we can only get from A3 from A2 and we can't go from A2 to any other state?

 

To answer your questions, you can use the Reinitialize to Default Values invoke node to reset all front panel controls to their default values in the init state.  I did this in the example, but if you only want to make the booleans false you could always use local variables.  Also you don't technically need a timeout for your event structure but if you never trigger an event the VI will just wait until you do.

Matt J | National Instruments | CLA
0 Kudos
Message 2 of 7
(3,015 Views)

Jacobson,


Thanks for sharing your example with me.

 

I have attached a simple state machine diagram. The state machine reacts to user events (clicking of a button). Although there are multiple states, notice how certain states can be categorized or grouped (color). I want the build the program such that there is flexibility of exiting a certain state (ex: click on QUIT button). In a addition, I want to design the program if requested to input parameter (ex: how far to walk?), the user has to click a button after inputting the parameter to continue onto the next state (click START WALKING).

 

0 Kudos
Message 3 of 7
(2,987 Views)
Solution
Accepted by topic author aab-ufl

hey there, I've expanded a little on Jacobson's example here to demonstrate the "Idle, How far to walk, Walk" cases of your state machine diagram.

 

Pressing certain buttons on the front panel when you are in the wrong state will not do anything, as you can see, because I am only checking for the buttons I want to respond to in each state. For example, pressing "Start Walking" when in the walk state will not do anything because that is not a valid button, but pressing "Quit" will bring you back to Idle. Implementing the rest of the state machine is up to you!

Daniel C.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 7
(2,945 Views)

dnchen,

If you don't mind, can you please provide me with your example VI that is compabitible with LabVIEW 2013. I wasn't able to open it because I don't have labVIEW 2014.

0 Kudos
Message 5 of 7
(2,925 Views)

sure, here ya go

Daniel C.
Applications Engineer
National Instruments
0 Kudos
Message 6 of 7
(2,894 Views)

dnchen,

 

Thanks for the your clever solution. I was able to implement this method into my program. It worked great!

0 Kudos
Message 7 of 7
(2,815 Views)