02-11-2018 03:27 AM
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.
02-11-2018 03:47 AM
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.
02-11-2018 04:06 AM
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.
02-11-2018 12:24 PM - edited 02-11-2018 12:26 PM
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.
02-11-2018 03:20 PM
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.
02-11-2018 04:06 PM
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
02-11-2018 09:11 PM
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.
02-11-2018 10:29 PM - edited 02-11-2018 10:30 PM
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....
02-12-2018 09:45 PM
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
02-12-2018 10:29 PM
Sir,
Actually I want my flow of the program like this: State1- state9-state2-state 9-state 3- state 9 and so on ....