04-23-2016 09:43 AM
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!
04-23-2016 10:19 AM
04-23-2016 10:19 AM
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.
04-23-2016 02:25 PM
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.