Fritz_85 Posted September 8, 2010 Report Share Posted September 8, 2010 Hi everybody! I would like to programm a State Machine where Ii can switch the states by pressing buttons on the frontpanel. I found a good example on Ni.com called "State Machine-Revised Coke Machine". I tried to programm it by myself. But right now its only switching the state with one button and I want to make it work with every button. I attached a VI that I made called "Statemachine_incorrect"(Version 2009) which by now is only working with one button, and I also attached the example of th Ni.com website called "State Machine-Revised Coke Machine" Version(2009). I would appreciate if somebody could give me an advice how to make the state machine work with all the buttons. Thank you in advance!!! Fritz_85 Statemachine_incorrect.vi statemachine.zip Quote Link to comment
crossrulz Posted September 8, 2010 Report Share Posted September 8, 2010 Your problem is in where you are trying to figure out when button was pressed. The state tunnel out of the for loop will only output the result from the last button check (Button 3). If you want to keep what you have, change the tunnel to a shift register and feed the previous value through in the false cases. However, polling controls are BAD. You will be much better off with an Event Structure. NI's example is from right when the event structure was coming out and I have a feeling it was simply upgraded from a previous version long ago. Polling uses up lots of CPU unless you have waits in your loops. An event structure will sleep until one of its registered events have occurred. Quote Link to comment
Fritz_85 Posted September 9, 2010 Author Report Share Posted September 9, 2010 Hi, I know what you mean with the shift register. However, I couldnt realize it that way. But I have found another solution for this problem, which is attached below. If you have time you could edit my VI with your solution and post it crossrulz. Thank you for your reply! Quote Link to comment
ShaunR Posted September 9, 2010 Report Share Posted September 9, 2010 (edited) Hi, I know what you mean with the shift register. However, I couldnt realize it that way. But I have found another solution for this problem, which is attached below. If you have time you could edit my VI with your solution and post it crossrulz. Thank you for your reply! What crossrulz. means (I think) is that events are more efficient for user selection than a state machine. Assuming that the goal is to make a selection based on user input. Although it is not a state machine in the classical sense, since the the next state is not dictated by the previous one. Note that I have changed the mechanical action of the booleans too. Edited September 9, 2010 by ShaunR Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.