LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

variable number of states in standard state machine

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

0 Kudos
Message 1 of 4
(2,545 Views)

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

0 Kudos
Message 2 of 4
(2,542 Views)

THen make one with 5 states and simply use only some of them on occasion. 😄

0 Kudos
Message 3 of 4
(2,541 Views)

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:

 

QMH_Template.jpg

 

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,

 

 

Rik Prins, CLA, CLED
Software Development Engineer
0 Kudos
Message 4 of 4
(2,523 Views)