06-09-2013 05:38 PM
Hello,
I have a fully functional State machine program to control a stepper motor.
However, I face a problem where I am not able to break the program inbetween execution by clicking the stop button for while loop MANUALLY.
I dont know why it cannot exit upon User input.
Solved! Go to Solution.
06-09-2013 05:57 PM
You shouldn't have an event structure buried inside of a case structure. Especially when you have some of thoe event cases set to Lock the Front Panel until This Event Case completes. Even if the event structure is not in the path of execution, it is still capturing events. If cases are set to lock the front panel, you can't do anything. But if you need to click a button to get into the correct case structure that has the event structure, you are stuck.
Read Caveats and Recommendations when Using Events in LabVIEW and then rearchitect your VI to get the event structure to be the top level of code inside the loop.
06-09-2013 06:42 PM
So in any state machine archictecture an Event Structure shoukd be after the while loop ??
The examples show that a while loop followed by a case structure is a State machine architecture. Am I getting it wrong somewhere ?
06-09-2013 07:55 PM
06-09-2013 08:23 PM
Often it is best for the event structure and the state machine to be in parallel loops rather than in the same loop. Look at the Producer/Consumer (Events) Design Pattern. The state machine would be in the Consumer loop.
(Some simple systems can manage to have the state machine case structure inside the Timeout case of the event structure in a single loop architecture, but this design tends to be hard to manage as requirements change and it is not easy to assure that it will work correctly. I do not recommend this to someone who is new to both event structures and state machines.)
By having its own loop the event structure never gets into a condition where it cannot execute. That is cause of the locking problems your VIs are having as has been pointed out by others.
Lynn
06-09-2013 08:45 PM
06-10-2013 02:59 PM
Uggh. I typed a response here to your note but NI website timeout kicked me out and I lost everything I typed.
What RavensFan mentioned is shown in attached image, you have to unclick that option on every case of your events structure so that it doesn't lock up the front-panel.
But more importantly as Lynn and other folks mentioned, you have a bigger problem with your design implementation. My previous example was to show how a state-machine based design can be made clean/small/efficient/etc. I have two 30" monitors on my Mac and your block diagram extends well into my second monitor!! 🙂 (I'm a bit of a neat-freak so I like making things look nice/wires laid out properly/into straight lines, no unnecessary wires crossing/etc - all that makes it easier for yourself and others to see the design.)
Sorry, back to the main point - you should definitely follow Lynn's advice on using Consumer/Producer (events) model - a simpler start would be to separate out your events structure into its own while loop that runs parallel to your existing loop. With that, at least you will execute events structure at a regular interval. Another strong advice is to simplify your design so that you don't use nested (one-inside-another) state-machine design. I have decades of LabVIEW experience yet I stay away from that kind of complication because it only causes more problems as you grow your design. Why not just add more cases to your existing state-machine design rather than adding a nested state-machine structure inside it?
-DP