LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I keep a state machine readable when using large amounts of in/outputs

Hello, I am new to Labview,


Read trough the fundamentals and the getting started and a lot of examples.

What I want to do is use a standard state machine from the template, and add some stages, for example orange, apple, banana. At this point I can use numeric controls to put in the amount of oranges, apples, bananas there are. I can even use a led to tell the user which state of the state-machine is active.

The thing is there will be more numeric controls and more leds and it would be nice if the code would still be readable when there are 20 inputs and 20 outputs.


Questions


(1) It would be nice if I could use the typedef to select the right state AND the corresponding numeric controls and leds out of a cluster or an array kind of structure to keep the number of wires low. Is this possible, how can I do this?

(2) I tried to put the numeric controls into a cluster but that way I can't put the numeric control for the apples in the upper right corner and the numeric control for the oranges in the lower left down corner of the front panel.

(3) An example would be really nice, I know that I saw some examples describing this problem but there are so many examples that after a few hours of searching I haven't found the right one yet.


Thanks in advance for the effort.


p.s. I will not use Labview to do calculations on fruit, I am only using this to make the question easier to understand.

0 Kudos
Message 1 of 3
(2,723 Views)

I can only start a proper answer but I might as well start with that.

 

When I am developing State Machines I have to think about what data is used and manipulated in each state. I then have to think about where am i going to keep and manage the data. I list all of the fields that are "touched" in each state and what values are used together and which are independent form the others. After this phase of the analysis, I usually have some data structure defined (cluser array etc).

 

Then I flipp from thinking about the state to thinking about the data (after all this is LabVIEW and the data-flow paradigm is critical). If I see data that is only used by the State machine and is used in many of the states, then the data structure get put in a shift-register for easy access in each state. This maybe enough of an answer for your fruity question.

 

When i see data that is shared or only used in a handful of states then I concider putting the data in an Action Engine. Depending on how you design your AE, you can access each of the fruit totoal by name or increment etc as required.

 

If your app demands many fileds that are all related (can't be broken into distinct data structures) then create a cluster that has all of your values that are used by the AE. Then create an Wrapper VI for each call of the AE but only put the associated fields on the FP of the wrapper and then bundle that value into the cluster and invoke the AE.

 

Ben

 

PS: Sorry about reverting to neBulus mode but this topic could take days to cover in detail.

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 3
(2,716 Views)

Think about the organization of your front panel (user interface) separately from the block diagram (code).

 

The state machine could have many orange states and only a few banana states while the user interface could have controls only for peel and eat for each fruit.

 

My suggestion is to use a tab control to organize the front panel.  The banana numeric and the apple numeric are then completely independent from each other.  If you make the tab control an indicator (and perhaps hide the tabs),  you can write to its terminal on the block diagram so that the state machine controls which tab page and its corresponding controls and indicators is displayed.  This method also allows you to have both controls and indicators for each fruit.  You cannot so easily do that with a cluster.

 

Use the state enum typedef to select the state.  Write to the tab terminal from any state where a tab change is needed.

 

To keep the number of wires passing through all the states manageable, use a cluster (typedef) in a shift register with all the things you change.  I do this often and call the cluster Indicators and Flags.  This cluster is not displayed on the panel.  Give each control in the cluster a unique name and use Bundle and Unbundle by Name in the state machine.  This helps to document which data are being used in any state.  To initialize the shift register without having a huge cluster constant on the block diagram create a VI with only the cluster as indicator.  Set the values to the defaults for your program and save the subVI.  You can even make the icon small to save more diagram space.

 

Lynn 

0 Kudos
Message 3 of 3
(2,713 Views)