LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in changing states in state machine

I am using state machine to change in between states. I have got 10 states. From states 1-8, after each state, the program move to 9th state. By using shift register, we can get the previous state. But I am facing problem with how to go to the next state.

 

Say Ex: I complete the 1 state, after that it goes to he intermediate state i.e. 9 state. Now I want to go back to 2 stage. Similarly, after second state, again 9 state and then state 3 and so on.

0 Kudos
Message 1 of 11
(3,953 Views)

Did you look at the state machine templates?

 

A shift registers is a place where you can read on the left and write on the right side. Whatever you write on the right will be in the shift register at the beginning of the next iteration.  You just need to work out the logic to feed it the desired next state.

 

You probably should attach a simplified version of your code so we can see what you are trying to do and can give more specific advice.

0 Kudos
Message 2 of 11
(3,945 Views)

As I have already written, I am using state machine to change in between states. I have got 10 states (10 different condition to run).

 

After each and every state my program goes to 9th state. After executing 9th state, I want to return to my previous state +1. 

0 Kudos
Message 3 of 11
(3,935 Views)

wrote:

As I have already written,...


As I have already written, we cannot tell you what you are doing wrong unless you show us your code.

 

Any other state can follow the current state, you just need to make the appropriate decision at the end of each state. That's the beauty of a state machine! You can expand the shift register on the left if you need a deeper history.

0 Kudos
Message 4 of 11
(3,907 Views)

Use an integer queue to queue up multiple states. Enqueue state 1 before going into your loop. Use the dequeue function to pop off each state. Within each state 1 through 8, you enqueue the 9 state then the next state, which is current + 1. I'm not sure what you want to happen once you get to state 8. I assume you want to quit at state 10, so I enqueue that as well.

 

Changing States in State Machine - 001.pngChanging States in State Machine - 002.pngChanging States in State Machine - 003.pngChanging States in State Machine - 004.png

Feel free. Contact me for anything more,
    Pang

You too can be LabVIEW Awesome!
0 Kudos
Message 5 of 11
(3,893 Views)

Have a Shift Register that you put "The State to do After State 9" (so in State 1, you'd put 2, in 2 you'd put 3, etc.).  You may need to[ think about what to put in State 8 and 10 ...

 

You have a second Shift Register that holds "Next State".  When you finish State 1, 2, ...8, you put "9" into "Next State".  When your State Machine comes around to "next state", it gets the Next State from the "Next State" shift register.

 

What about State 9?  Well, State 9 puts "The State to do After State 9" on "Next State".  And that solves your problem in probably the simplest possible way (feel free to argue with me ...).

 

Bob Schor

0 Kudos
Message 6 of 11
(3,885 Views)

wrote:

Use an integer queue

 


DO NOT USE AN INTEGER FOR YOUR STATE MACHINE STATES!!!!!  I have inherited code that did that and it is next to impossible to follow.  Use (type defined) Enums with descriptive items.  This makes the readability so much better.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 11
(3,872 Views)

 

Untitled.png

I am not using the numbers, the second tab is eo, after eo loop completes, the program comes to report tab, after the report tab completes, i want to go to ec tab which is the third tab comes after eo... and so on....

0 Kudos
Message 8 of 11
(3,862 Views)

I think I told you how to do this a few Replies ago.  Since I don't know the names you gave your States, I called them "State 1", "State 2", etc.  Simply substitute the names you use in your Enum (I gather State 9 is called "Report") ...

 

Bob Schor

0 Kudos
Message 9 of 11
(3,827 Views)

Sir, 

Actually I want my flow of the program like this: State1- state9-state2-state 9-state 3- state 9 and so on ....

0 Kudos
Message 10 of 11
(3,823 Views)