Jump to content


Photo
- - - - -

Switch states in a State Machine with Buttons


  • Please log in to reply
3 replies to this topic

#1 Fritz_85

Fritz_85

    2 more posts to go.

  • Members
  • 8 posts
  • Version:LabVIEW 8.6
  • Since:2009

Posted 08 September 2010 - 09:02 PM

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

Attached Files



#2 crossrulz

crossrulz

    Extremely Active

  • Members
  • PipPipPipPip
  • 307 posts
  • Location:Cincinnati, OH
  • Version:LabVIEW 2012
  • Since:2004

Posted 08 September 2010 - 09:53 PM

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.

#3 Fritz_85

Fritz_85

    2 more posts to go.

  • Members
  • 8 posts
  • Version:LabVIEW 8.6
  • Since:2009

Posted 09 September 2010 - 08:31 AM

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!

Attached Thumbnails

  • State Machine Solution.JPG


#4 ShaunR

ShaunR

    LabVIEW Archetype

  • Members
  • PipPipPipPipPipPip
  • 2,630 posts
  • Version:LabVIEW 2009
  • Since:1994

Posted 09 September 2010 - 09:21 AM

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, 09 September 2010 - 09:25 AM.

A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort. (Herm Albright 1876-1944).

Founder and general mischief maker on www.lvs-tools.co.uk.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!