Jump to content

Switch states in a State Machine with Buttons


Fritz_85

Recommended Posts

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

Link to comment

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.

Link to comment

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 by ShaunR
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.