LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically add state to state machine

Hello all,

 

I'm making a state machine that changes an array of boolean values based on the current state ie. State 1 = [F,F,F,F], State 2 = [F,F,T,F], etc.

 

My problem is that I need to dynamically add/remove stages based on user input (ideally the user would be able to select anywhere from 1 to 20 stages). I would have an "initialize" and "shutdown" stages that would be there regardless.

 

I know from this post that you technichally cannot modify cases in a case structure while the VI is running, so I was wondering if there is some workaround that I could use.

 

Thanks,

Laura

0 Kudos
Message 1 of 8
(3,856 Views)

I would make the maximum number of states you could need and only use those that are required at the time.  Dynamically changing your block diagram architecture isn't possible (as far as I know) and to try seems like a waste of time. Have your code detect the number of stages during the initialization phase and store the number of stages.  Then, only utilize code relevant to those stages present.

 

Better yet, would be to have states for moving a single stage and the code inside determines which stage to move.  This way your architecture is fixed and the code dynamically determines which stage to communicate with.

0 Kudos
Message 2 of 8
(3,850 Views)

I would make the maximum number of states you could need and only use those that are required at the time. 


Ahh, I had considered that but wanted to leave it as a last resort. 

 


Better yet, would be to have states for moving a single stage and the code inside determines which stage to move.  This way your architecture is fixed and the code dynamically determines which stage to communicate with.


What do you mean by "move" a stage?

 

Thanks for your help, it's great to have a second opinion.

0 Kudos
Message 3 of 8
(3,834 Views)

Sorry, your original post mentioned adding/removing stages.  In my field a stage is a device for linear motion.  If this isn't what you meant, ignore me.

0 Kudos
Message 4 of 8
(3,819 Views)

Do you have a VI to post to better explain what you are trying to do? How is user selecting these states?  What structure do you have (or think you will use to) set up?  I would agree you would need to have max number (which seems like 16 if you have a 4 boolean array) of states already coded.  Unless each state does the EXACT same code, then you could get away with one and just handle the inside of the state better.

0 Kudos
Message 5 of 8
(3,775 Views)

lauraalkhoury,

 

You use the term state machine to describe your vi.  It sounds like you are creating a sequencer.  Can you describe your application a little be more?

0 Kudos
Message 6 of 8
(3,751 Views)

have a look at LVOOP

 

you can use dynamic dispatch to dynamically launch states from a queue

 

this is a good introduction to OOP 

 

https://decibel.ni.com/content/docs/DOC-21531

 

 

- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 7 of 8
(3,714 Views)
You either make an interpreter of sorts, or you use an array of states if you want it dynamic. What are you trying toachieve?
/Y
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 8
(3,699 Views)