LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State machine, sub and main vi concepts

Hi, I am trying to build a state machine for the first time. I believe based on my fair understanding of event /case structures and while loops, I should be able to handle the sequencing, but there are some other concepts I do not understand. Now I have a single large VI that contains all my code( this is so because I started this project with zero Labview experience) , I am now splitting this up into subvis so I can conveniently place them into my events/ case structures. So I will end up with this main vi ( now consisting of subvis) plus each of the resulting subvis. The third one will be a "state machine vi". This is what I am thinking as an inexperienced person ( so correct me wherever I am wrong ). So my question is how does this additional "state machine vi link with the main and subvis. ? Or would the state machine code be placed in the main vi? Please explain in as much detail as possible as I am very new to these concepts

[BADGE NAME]

0 Kudos
Message 1 of 15
(4,476 Views)

Hi blessedk,

 

I think you should put the state machine in your main VI: here's the place to put the "main" part of the code (aka "the statemachine") and to call any subVIs…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 15
(4,468 Views)
OK. So if I understood correctly, the state machine is actually the main VI?

[BADGE NAME]

0 Kudos
Message 3 of 15
(4,464 Views)
It is still confusing to me: are the subvis automatically linked? Or is there a way to link them? The reason I am asking is that the state machine would be running sections of the main code ( subvis) but don't the subvis need to be interconnected somehow? Where is this connection done

[BADGE NAME]

0 Kudos
Message 4 of 15
(4,462 Views)

I do not know what you mean by "interconnected" here.  But your state machine will call the needed subVIs based on what state (case) it is in.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 15
(4,439 Views)

What i like to do is create a sub-vi for each state, with all needed inputs and outputs. That way the state machine is in the main VI, but each state is a separate VI which makes the main VI smaller, the code segmented and easily changed and reused.

 

Start a new project from Template, Producer/Consumer or State machine, and in each state needed, create a sub-vi.

I hope i make sense, it can be hard to explain sometimes. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 15
(4,425 Views)

Your assumptions are correct.

 

Create subvi for each state of your machine, put it in the proper case (state) and every time the machine call the case, the subvi will be executed.

 

For passing data bethween subvi there are different solutions:

 

1) global and/or local variable

2) shift registers in main subvi

3) functional global vi https://decibel.ni.com/content/docs/DOC-2143

0 Kudos
Message 7 of 15
(4,405 Views)

Hi esodar,

 

in state machines you should only use option 2…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 15
(4,396 Views)
Hello Esodar. What do you mean by "Main SubVi " in option 2 .

All, I still have a number of questions.

1. What becomes the use of the initial large block diagram from which I made a number of subvis

2. When the program runs how does it determine its main level vi. Which is this main level vi, is it the state machine vi or the large block diagram I started off with?

3. Is the state machine just a simple vi with case ( and event structure, the subvis and shift register and does not contain the initial large block diagram where all subvis were initially connected.

[BADGE NAME]

0 Kudos
Message 9 of 15
(4,389 Views)
Also when you talk about "passing data from each case to another, my project can only pass data in a forward direction. In order words you can pass data from state 1 to 2 but not from state 2 to 1. How ever you still need to be able to change case/ state from 2 to 1 without passing data. So what's your opinion on this one ?

[BADGE NAME]

0 Kudos
Message 10 of 15
(4,381 Views)