11-24-2012 10:23 AM
Hi
I want to make a standard state machine with. a variable number of states.
One of the inputs is an array of clusters and I want to have the same number of states as the size of the array. The maximum size of the array is 5.
What's the best way to realize this?
Thanks in advance
11-24-2012 10:39 AM
I do not know how you would do that. Further I cannot think of any reason why you would want to do so. A state machine does not need to use all its states every time, nor do they need to be used in any particular order. Some states may be used many times while others not at all or only once. Initialization and shutdown states typically only run once. Wait or idle states may run thousands of times. Ideally the error state never runs.
Create a state machine with the maximum number of states you will ever need. Then only call the ones required for a given situation. If you know it will never have more than 5 states, create 5. When the array only has three elements just use the three states called by the array.
Lynn
11-24-2012 10:40 AM
THen make one with 5 states and simply use only some of them on occasion. 😄
11-26-2012 04:04 AM
Hi Tom,
Like the two other contributors mentioned you will need the states pre-defined since there is no way (at least not an easy one) that you can create states programmatic. So either use a standard state machine with your 5 states pre-defined and determine based on the array which states to execute and in which order, or use a queued state machine (also revered to as Queued Massage Handler). Maybe in this case the last one is the most flexible since it gives you precise control over which states should be executed and the order in which they are executed. In a standard sate machine you will have to add a lot of functionality to make the discussions which state should be executed. In a queued state machine this is already part of the design. There a multiple ways to implement a Queued State Machine. The most basic one can be found as a template within LabVIEW. Click one File >> New and browse the tree as follows:
Some other implementations (some more complex then others):
https://decibel.ni.com/content/docs/DOC-14169
https://decibel.ni.com/content/docs/DOC-1992
http://www.ni.com/white-paper/14119/en
I hope this helps.
Best regards,