LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

queued state machine with while loops in state

Hey guys,

 

I am trying to build a queued state machine with user input, adapted from here: https://decibel.ni.com/content/docs/DOC-14169

However I would like to implement also states which run a while loop. For example I want the user to press a button which then runs loop 1 which is a measurement routine where the wavelength of a monochromator is varied while the intensity is recorded... But I still want the user to be able to abort this loop if something goes wrong. What would be the best way to implement this?

 

Of course once measurement loop 1 is running new user input can not switch to a different state, but I want to make sure that once the measurement is started it is only possible to press the stop button.

Or would it be a better way to implement each measurement loop outside of the state machine?

I attached an example where I expanded the adapted example by two new states. My main questions are: is it wise to use the described acrchitecture? And how can I stop this loop by creating a new event with clicking onto the Stop button?

 

Thanks a lot and best regards!

0 Kudos
Message 1 of 4
(3,624 Views)
Check here...

http://www.notatamelion.com/2015/02/23/building-a-proper-labview-state-machine-design-pattern-pt-1/

...and the post following. There are several problems with the default state machine implementation, but IMHO the biggest is that it doesn't play well with events.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 4
(3,612 Views)

Make the state machine loop your while loop.  The state that had the while loop inside it then keeps calling itself until either everything is complete and you call the next state, or the user does something and you go to your shutdown state.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 4
(3,610 Views)

General state machine theory gives you a finite number of states each performing a task, timing for each state, and transition logic to move to the next state.

 

Adding a while loop breaks the second of these.  You've taken away the ability to time each state.  You're no longer using a state machine.  Others have provided the solution here.  You just loop back to the main state designed to look for user input.  In the timeout case, you send it back to handle the task you'd like without needing a loop within any individual state.

0 Kudos
Message 4 of 4
(3,584 Views)