LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem sequencing certain boolean signals

Don't know all that much of LabVIEW, but I've been tinkering with some Wiimote VIs and stumbled upon a problem.

I've created a grid of 15 LEDS (3x5), kinda like this

 

http://i13.photobucket.com/albums/a290/Rorschachinkblot/GRID.jpg

 

Each LED corresponds with a certain Wiimote position. So if you aim high & left a boolean signal will light up the top left LED and if you aim right & low the down right bottom one will.Now what I'm trying to accomplish is that when you move the Wiimote in a horizontal way from left to right and all the corresponding LEDS lit up in precise order a message will appear that you've been successful (in making a horizontal slice with your wiimote). Unfortunately I've been puzzling with it for days but I can't seem to come up with a proper solution.

Should I be using Event Structures corresponding with the 'value change' of the specific LEDS perhaps and somehow get them to work in the specific order I have in mind (maybe incorporate a Flat Sequence Structure as well then)?

 

At any rate thanks for your time.

0 Kudos
Message 1 of 22
(4,264 Views)

I'm not sure what you want, but I'll try.  You want to have some even only when the LEDs in the middle light up, one at a time, in a row?  Like if there were 3 horizontal LEDs, you want to trigger when the left LED lights followed by the middle, followed by the right.  Only then do you want to trigger an event?  You could capture the LED  value change event, but you would have to check that each LED is on before you took action.  Or you could just poll the first LED with a while loop, and when the first comes on, go to a True case where the polling for the second starts.  When the second comes on, then call a true case where polling for the next LED to come on takes place.  But this is too many nested loops and cases.

 

Hmmmm, an interesting problem.  What about using a value change for each LED, and then each event would set a sequence of flags.  In the Timeout event, you could check to see if the flags were all set.  If one flag was set out of order, the code would reset all flags.  So the proper order would have to take place for the final event to occur.  Is this clear?

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 22
(4,250 Views)

 


@tbob wrote:

Hmmmm, an interesting problem.  What about using a value change for each LED, and then each event would set a sequence of flags.  In the Timeout event, you could check to see if the flags were all set.  If one flag was set out of order, the code would reset all flags.  So the proper order would have to take place for the final event to occur.  Is this clear?

 


 

It's quite clear and it sounds perfect, but I'm uncertain how to implement the flag system you described. It also took me some time to get the value change for each LED working (using property nodes), but I think it works now. Should I be using 'notifiers' perhaps to get things in the right order?

Thanks for responding and I've added the VI just in case.

0 Kudos
Message 3 of 22
(4,203 Views)

Your block diagram size is too large.  You need to learn how to modularize your code.  Use subvi's,  If it doesn't fit on one monitor, then it is too large, making it extremely difficult to follow.  Inside the sequence structure you repeat the same code over and over with the output going to a different terminal.  This is a good place to use a subvi.  Create the code once, call the subvi many times with the output going to where it needs to go.  All of those shift registers could be bundled into a cluster.  You don' thave to convert the boolean arrays to dynamic data, then convert the dynamic data ot DBLs.  There is a function that will convert booleans to 0 or 1 located inside the boolean palette.  Write to spreadsheet will take in arrays of any numeric type.

 

You should not use three separate event structures.  Just use one and add event cases to create the three events.  You can use a shift register as a flag.  When the first event happens (first LED of a series), wire a true to the shift register.  On the second LED event, check to see if the shift register from the left is True.  If so, pass the True to the shift register on the right.  If not, then the sequence of order is not correct and send a False to the shift register.  Continue on until all conditions are met.  When they are, set an indicator and write to its Value(signaling) Property node.  Then you can create another event case on the indicator's value change event.  In this event you can put the code that you want to happen when the sequence is met in order.

 

- tbob

Inventor of the WORM Global
Message 4 of 22
(4,187 Views)

 


@tbob wrote:

 

You should not use three separate event structures.  Just use one and add event cases to create the three events.  You can use a shift register as a flag.  When the first event happens (first LED of a series), wire a true to the shift register.  On the second LED event, check to see if the shift register from the left is True.  If so, pass the True to the shift register on the right.  If not, then the sequence of order is not correct and send a False to the shift register.  Continue on until all conditions are met.  When they are, set an indicator and write to its Value(signaling) Property node.  Then you can create another event case on the indicator's value change event.  In this event you can put the code that you want to happen when the sequence is met in order.

 


 

Thanks for helping me on my way!

As this is a school project my priority is to get the thing working, but I've taken your comments into consideration and made the VI smaller and bundled the shift registers like you proposed.

I followed your instructions concerning the event structures and I think it's wired okay now, but what I don't understand is that the first 'true' activates immediately without waiting for the first (indicator) value to change. I went through some examples and the online help and I was under the impression that the event structure doesn't fire up before the value changes? I've added some probes but they seem to tell me otherwise though.

 

Either there's a brief value change at the beginning or (more likely) did I wire it wrong?

 

0 Kudos
Message 5 of 22
(4,142 Views)

The output terminal of the event structure is set to Use Default if Unwired.  So if an event happens where this is unwired, you will get a False out of the terminal, even though no event pertaining to that wire happened.  Don't use this feature.  Just wire something to the terminal in every event case.  The Value Change event will not fire until a value changes. But if the value on that wire were True, and the Timeout event fired, the value will change to False because of the Use Default if Unwired.  You need to put a value on the Timeout case.  It does not fire if there is nothing wired to the hourglass.  If Timeout doesn't fire, and no other events fire (no bool changes), you will not be able to stop your program because the event structure is still waiting for an event.  That is the purpose of Timeout.

 

Your event structure is all wrong.  The first event should have New Val feeding the output terminal.  The second event needs to have an AND function of the shift register and the New Val.  Only if both are true do you want to set the output true.  Same for the third event.  Only if the shift register AND the New Val is true do you send a true to Signal.  The shift register will remain true is if the order of events are bool 1 becomes true, bool 2 becomes true, and bool 3 becomes true.  If any of them become false before the next becomes true, the output will be false.  However, there is a flaw.  If the order is bool1 true, bool2 no change, bool3 true, then Signal will become true.  So this needs to be fixed.  There needs to be a flag for bool 1 and one for bool 2.  The bool 2 event needs to check if bool 1 flag is true before setting its flag true.  Bool 3 event needs to check both flags before setting Signal.  So you need one more shift register.

 

Where do you use Signal?  It is supposed to be a flag telling that the correct sequence of events have fired.  I don't see it being used anywhere.

 

 

- tbob

Inventor of the WORM Global
Message 6 of 22
(4,132 Views)

 


@tbob wrote:

 

Your event structure is all wrong.  The first event should have New Val feeding the output terminal.  The second event needs to have an AND function of the shift register and the New Val.  Only if both are true do you want to set the output true.  Same for the third event.  Only if the shift register AND the New Val is true do you send a true to Signal.  The shift register will remain true is if the order of events are bool 1 becomes true, bool 2 becomes true, and bool 3 becomes true.  If any of them become false before the next becomes true, the output will be false.  However, there is a flaw.  If the order is bool1 true, bool2 no change, bool3 true, then Signal will become true.  So this needs to be fixed.  There needs to be a flag for bool 1 and one for bool 2.  The bool 2 event needs to check if bool 1 flag is true before setting its flag true.  Bool 3 event needs to check both flags before setting Signal.  So you need one more shift register.

 


I actually started off using New Value & AND, but that didn't work out. Of course I hadn't wired the Time Out event and all those other things you mentioned (again thanks for that). So now I did, but unfortunately (using probes again) the boolean signal only seems to get across the shift register while the first indicator is activated, as soon as it switches to the second one the signal disappears. I've been over it these last couple of days but I can't seem to get it right.. even trying different while loops & conditions but to no avail.

 

Concerning your solution for the flaw, if I understand you correctly I'll be using the first shift register as a flag for Bool 1 and the second (which I have to add) for Bool 2, then compare the two before Bool 3 fires at 'Signal', right? 'Signal' isn't used yet btw, I'm thinking of lighting up a certain pattern of LEDS when it's on but I'm waiting for someone's input on that.

0 Kudos
Message 7 of 22
(4,099 Views)

You haven't changed a thing in your code.  You still have the absurd Selector function that says If True then True.  If you would have done what I said, your code would be working.  I guess some people can only see by example.  So here is an example that works.  Just click Boolean 1, 2, 3 in that order to get Signal.  Any other combination will not produce Signal.

 

- tbob

Inventor of the WORM Global
Message 8 of 22
(4,083 Views)

Although you might be right about the see by example part, my mistake was that I had uploaded the old vi instead of the one in which I had followed your advice. (My fault for naming it the same way.) Looking at your example though I wasn't that far off the mark, but even after some changes it won't work. It should be wired okay, 'cause when I change the compound arithmetic to OR then 'Signal' fires when one of the 3 positions is held.

I suppose your switches work a little differently than the wiimote positions (they remain pressed while the positions of the wiimote fluctuate I guess), but I thought the shift registers were there to solve that.

Other than that I wouldn't know what the difference is, but I'll look at it again tomorrow.

 

 

0 Kudos
Message 9 of 22
(4,054 Views)

Your shift registers are not initialized.  You should wire a False on the left side to intialize them.  Same for you shift register above which holds a boolean array.  Wire an empty array into it.

You Signal output from the event structure is set to Use Default if Unwired.  It will go True at some point, then after the next Timeout event, or any other event, it will go False again because it is unwired in all other cases and the default for a boolean is False.  If you want to hold it true, you need another shift register.

 

I'm not familiar with the action of your wimote.  Does the boolean go true, then false right away?  Every time it fluctuates, an event is fired (Value "Change").  This will prevent Signal from becoming true.  You need to describe what happens to these booleans and when you want signal to fire.  Like, bool 1 becomes true, then it goes false, then bool 2, etc...

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 22
(4,046 Views)