12-14-2017 12:00 AM
I want to implement a state diagram with the following states;
state one - if input is pressed stay in state 1
if 10s has passed or input 2 is pressed for more than 1.5s moved to state 2
state 2- if input 3 is pressed move back to state 1
if 10s has passed moved to state 3
state 3 - if input 3 is pressed moved back to state 1
I having trouble trying to use the time elapsed function as it keeps resetting the timer. I want to find a way to reset the timer when in a certain state rather than when an event occurs (input triggered).
I have used the state diagram toolkit.
12-14-2017 12:06 AM
CFarrelly wrote:I having trouble trying to use the time elapsed function as it keeps resetting the timer. I want to find a way to reset the timer when in a certain state rather than when an event occurs (input triggered).
I have used the state diagram toolkit.
Show us your code.
12-14-2017 12:11 AM
An important feature of a state machine is that you can Abort it any time. So you should not have a state where you just purely wait. Imagine, you have one state where you would get stuck for 10 seconds. You cannot do anything (no abort, no other state transition) during this wait!
Solution: split up the waiting into small chunks! For example, there could be a "Check if time elapsed?" state where you check the elapsed time (Either using the Elapsed time express vi, or you code yourself a FGV Timer).
The trick is that, during a wait, your state machine keep "bouncing" between a "New action or abort requested?" and the ""Check if time elapsed?" states. You can put a Wait function with a small value like 10 msec into the "New action or abort requested?" (here you have different options, you could also put the 10 msec wait function into the "Check if time elapsed?" after time check, or using a timeout at the "New action or abort requested?" state, etc...) state...
If you do so, your state machine will Wait for the requested time target (like 10 seconds), but can be Aborted/moved to other state in 10 msec ANY time!
Right now I do not have time, but later I might put together a small example for you.
12-14-2017 11:26 AM
Check out the JKI state machine. (VIPM can load it)
It has an event loop and timeout case built in. Set your timeout and if it expires do your next action.
mcduff
12-14-2017 04:14 PM
Added my code here.
12-14-2017 05:39 PM - edited 12-14-2017 05:41 PM
That is one of the weirdest block diagrams I've ever seen. Unknown functions with no help, wires that can't be deleted and while loops attached to something else. I've never used the state diagram toolkit, but if that block diagram was created by that I might stay away from it. Seems like it's just going to make things harder in the long run. Look up basic state machines and go from there would be my advice.
12-15-2017 11:08 AM - edited 12-15-2017 02:00 PM
Hard to follow what's going on, but what is the value of the "reset" wire going into some of the elapsed time express VIs. Since the booleans controlling these values are in the outer loop, any changes you do while the inner loop is running will not be read, of course.
Then there are very convoluted code constructs such a the presence of three different elapsed time express VIs stacked and combined into a single blob (picture). I am not ever trying to figure out what this is supposed to do. 😄
12-16-2017 08:47 AM
Hi Farrel,
Checkout the code attached. Is this you need?
12-16-2017 11:20 AM - edited 12-16-2017 11:34 AM
Kannan_Kn wrote:Checkout the code attached. Is this you need?
Blatant over-use of local variables!!! Bad!
See if you can fix it!
12-16-2017 12:45 PM
CFarrelly wrote:state one - if input is pressed stay in state 1
if 10s has passed or input 2 is pressed for more than 1.5s moved to state 2
state 2- if input 3 is pressed move back to state 1
if 10s has passed moved to state 3
state 3 - if input 3 is pressed moved back to state 1
Description seems incomplete. There are missing scenarios: