06-27-2010 11:12 PM
I think you need to search the forums for "state machine" again and search the example finder. What you have now is definitely not a state machine. Now it is just a huge pyramid of case structures and while loops.
A true state machine generally has 1 while loop that has 1 case structure inside. The case selector is attached to an enum that comes from a shift register. Each case can determine what case gets run next by whatever enum is wired into the right hand side of the shift register.
Also, you are still forced to use the abort button because your one tiny while loop has a False wired to the stop conditional terminal.
@kristofparedis wrote:
- secondly if you run the VI you can see the 'data' and 'output array' in the front panel. By clicking the index next to that, you can browse through all the previous values of this array. Why is this? When I check in the block value it says it should be a 1D array, yet I see 'n' 1D arrays in the front panel
I don't understand this comment. Both arrays seem to show the same 1-D array. I don't know what you mean by "n 1D arrays"
06-27-2010 11:29 PM
a state machine is basically a case structure in a while loop, right? that is what the labview forums tell me. it should not matter whether the input is an enum or a boolean or an index, right?
now i got several of them embedded, yes, but i don't see any other option to control my operations... if I want to perform operation 2 after operation 1, I need to put them in a sequence or in such a case-while structure, otherwise labview will execute them both at the same time... or how would you do that?
and what i mean with 'n' 1D arrays is this: run the VI then go to the front panel and click on the index next to 'data arra' which is initially zero, you'll see that there are more than 1 data array.
thanks
06-28-2010 12:08 AM - edited 06-28-2010 12:09 AM
No. A state machine is just a bit more than that. But certainly not as much as a case structure in a while loop, in a case structure, in a while loop, in a case structure, in a while loop .....
It is a single case structure in a while loop. The case structure might have several states, we'll call them
Init
Step 1
Step 2
Step 3
Close
The best option is to make those steps an enum, and typedef it. That way if later you need to add a state (such as state 4), all constants of that enum will get updated automatically.
In step 1, you would have an enum constant set for step 2 going into the right hand shift register. That tells the next iteration of the loop to run step 2 once step 1 is done. Step 2 might have an enum to tell it to run step 3. In step 3, you might have a case statement or selector that tells it to either go back to step 1, or perhaps go to Close (such as if the stop button is True.)
Often times, you might have an idle state that sits there and does nothing except return to the idle state waiting for something to happen (such as your start button being pressed) to tell it to do something else.
Go to File / New..... and search for Standard State Machine under design patterns.
I still don't understand yor N 1D arrays issue. But I suspect that it is caused by your current design pattern. When I start your VI, your data array is initially empty. When I hit your run button, it is filled with 32 elements that appear to be identical to the elements in the output array. Hit the run button again, and it temporarily goes empty, fills up with 32 elements again, and the output array is updated to match.
What do you mean by "click on the index next to 'data array' which is initially zero, you'll see that there are more than 1 data array"? The array index is just a control to determine what element is shown in the top most position of the array. Element 0, element 1, element 28 ..... Put in index 100, and the array will show all empty elements. No matter what the index is, the array will still contain 32 elements whether they are shown or not shown.
Have you taken the online LabVIEW tutorials?
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours
06-28-2010 12:21 AM
Thanks, and I do get the point of a state machine. Quote
but when I have for instance a run state, it should execute some operations in a specific order (say 'get some parameter', do a for loop (adjusting/measuring), switch a parameter, and do another for loop), now how do I efficiently get that order in my operations if I am not supposed to use sequences (or the embedded while-case structures)? I'm not supposed to write a specific state for each of them, right?
So I'm not netirely sure if these state machines will serve my purpose efficiently, because there is only a single path to follow in my program when I hit run. I'm just having problems in having the order of operation correct.
and nevermind the index, it is indeed the first element shown, (my bad, it's getting late") and yes I have read a whole bunch of tutorials... but it is mostly practice and your help that will teach me how to do it best !
thanks
06-28-2010 09:19 AM
Actually it might be a good idea to write cases/states for each of them, then they'll be small, fast and easily maintained. If you run into the issue of "But i need to activate several states at once/in a row!" then you're a prime canditate for a Queued State machine! 🙂
Basically the same thing, but you add your commands/states into a queue instead which the state machine handles. One beauty of the queue is that it like Events waits silently if the queue is empty.
/Y
06-28-2010 11:11 AM - edited 06-28-2010 11:17 AM
Here is an example of a queued state machine to help you get started.
06-28-2010 11:16 AM
Is it possible to save it for Labview 8.5.1? I should have mentioned that before.
Thanks a lot.
06-28-2010 11:19 AM
Sorry, I only have 2009. Save it and post it to the Downconvert VI Request thread. Someone there will downconvert it for you. Just specify that you need to convert from 2009 to 8.5.1.
06-28-2010 12:24 PM
Tbob,
You can save that back to 8.5 from 2009.
Here is the file.
06-28-2010 01:27 PM
@Ravens Fan wrote:
Tbob,
You can save that back to 8.5 from 2009.
Here is the file.
WOW!!! I just now see that I can save 2009 to any version from 8.0 on up!!!!!! I just assumed I could only back one version (8.6) like it is in previous versions. Thanks Ravens Fan.