LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Two button selector in statemachine

Hey all,

 

Im just starting out in Labview and am currently messing around with state machines.

I am trying to find a way to do the following:

 

The state machine should stay in the "waiting" state untill one of two buttons is pressed, then it needs to hop to the state that belongs with the button pressed.
But I do not know how to hook this up to the final shift register since it can only have one signal going in.

 

Here is an image to give you a bit of an idea to what I am trying to accomplish.

 

Is there anyone who wants to help a noobie out on this one? I know that it might be a stupid question to ask around here but I can't seem to find anything on the subject and don't know where to go..

Knipsel.PNG

0 Kudos
Message 1 of 8
(4,622 Views)

A wire can only have one source. Try to wire the output of the first select node to one of the inputs of the second select node. You'll figure it out.

Message 2 of 8
(4,610 Views)

You could do the same thing with a Event Structure within that "Wait" case. Look that up too.

Message 3 of 8
(4,589 Views)

Or use a radio button with 2 (or 3) options instead of separate buttons…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 8
(4,580 Views)

@altenbach Yeah I get that now, was really confused at first because they were of the same type and I thought it didn't matter!

0 Kudos
Message 5 of 8
(4,566 Views)

@Eric1977 only just heard of that, figuring it out now! And @GerdW Thanks! Don't know why I didn't think of that option, good call!

0 Kudos
Message 6 of 8
(4,562 Views)

@TheAlPaca wrote:

@altenbach Yeah I get that now, was really confused at first because they were of the same type and I thought it didn't matter!


Think about it from a conceptual standpoint rather than specifically in your code.

 

If the case has only one output, but two things feeding that output, how could you know which one is actually being sent as the output?  The best way I can think to describe this is to think of two people, Harry and Jim.  Harry and Jim both have the phone number (123) 456-7890.  You pick up your phone and dial that number.  Who will you get?  Each time you dial, you won't know.  That is something that will break your code.  As such, the environment SHOULD throw an error.

 

Let's look at your code.  Let's say the first button always manages to win, just for ease in understanding.  If the first button always wins, it will look like your program is working when you push that button because it will behave as expected.  If you push the second button, it will never respond.  It will just go back to wait. 

 

As it stands, we really don't know which would reach.  If LabVIEW allowed you to wire things like that, you could potentially lose one button if both were pressed at the same time.  Beyond that, are you wanting the response to one cup to repeat until the button is pressed again or do you want it to happen once?  Is the button set up as a switch or a latch?  If you're looking for a state machine to respond to user input, you probably want to spend time with the event structure as it is meant to watch for user input.

0 Kudos
Message 7 of 8
(4,538 Views)

@TheAlPaca wrote:

Here is an image to give you a bit of an idea to what I am trying to accomplish.


A few more comments to your code draft shown in the image.

 

Depending on the rest of the code, there is a nonzero chance that both booleans are true when this case is encountered. Do you need to deal with that case? I also assume that you have a small wait somewhere to prevent 100% CPU use when the program is not doing anything important.

0 Kudos
Message 8 of 8
(4,519 Views)