LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with states machine, UDP and while loops.

Hi, 

I am currently working on a project that involves EEG signals and Virtual Reality.

I have a VR application and it communicates with LabView through UDP.

When I press a button on the VR it starts an animation and it sends a message to LabView and activates a boolean indicator, it works by itself. While the animation is inactive I want to write 0's to a file and when the animation is active I want to write 1 values to the same file.

I tried to do it with state machines, when I click the button on the VR app it does write 0's but I can't get it to write 1's while it is on standby.

snippin1.PNG

I attach the needed files and controls.

statemachine_justaddingvalues, control_3

testingUDP_andSTATEMACHINE, udptestcontrol

 

Any help will be greatly appreciated, you are my last resource I have tried many things and I don't seem to find any related thread.

 

 

0 Kudos
Message 1 of 4
(2,363 Views)

Hello T-46+2,

for me it's not entirely clear, what you want to achieve. I refer to "testingUDP_andSTATEMACHINE_Whileandsss.vi":

  1. why do you use a shift register, initialized with an empty array, and then with every loop iteration it is written with an empty array again?
  2. why don't you wire the UDP- RefNum through all cases of your state machine (i.e. when the loop is stopped while the case "Add stuff" is executed, your UDP- connection will not be closed properly). Don't use "Use default if unwired"! The only right use-case for this setting is in your VI "statemachine_justaddingvalues.vi" the use of the conditional boolean to stop the loop since there is only one case wich is delivering a TRUE
  3. how is the case "exit" reached?
  4. what do you mean with standby, from your description I would think the case "Waiting UDP" means standby, "Add stuff" is the active state
    what ist the format of the data you receive (or expect) with the UDP packets?
  5. are you sure, you receive any data at all?
  6. why do you have these many wait- nodes? The "UDP Read" has a default timeout of 25 seconds, so if you dont't get data, the Wait is meaningless (because the case is exitet when data is floated through all nodes) and if you get the packets faster than 10 times per second, the received packets will be queued up and you develop a delay between sent data and received packets
  7. why do you write 10 times a 1 to the file, although you enter the state "add stuff" only once? Why the 100ms Wait?
  8. since your loop speed is very slow you won't get problems with it, but it's better style, to open the file once outside the while loop and feed the RefNum (via shift register) inside the loop and use "write to text file" in conjunction with "array to spreadsheet", to write your datato file. But you should have only one constant with the filepath (outside the loop)

 

Greets, Dave
0 Kudos
Message 2 of 4
(2,285 Views)

Hi Dave, thanks for taking the time to check my code!

As you were able to tell, I don't usually work with LabView 

 

why do you use a shift register, initialized with an empty array, and then with every loop iteration it is written with an empty array again?

What I am trying to do is write 0's and 1's to a file, I am not really interested in the array itself,  I got it to work with the "build array" so I just left it that way. I'll use MatLab after the files are created. I am writing directly to a file to avoid running out of memory (if it's possible, at all).

I'll be capturing EEG signals and I am interested in analysing the signals while the VR animation is active, I am trying to create a "window". Of course, the 0's and 1's file has to be synchronized with the EEG readings file. And all the values in that VI are just to get it to work, not the values I'll actually be using. I hope this makes sense, any suggestion on how to approach this problem is welcome.

why don't you wire the UDP- RefNum through all cases of your state machine (i.e. when the loop is stopped while the case "Add stuff" is executed, your UDP- connection will not be closed properly).

I don't understand this.

Don't use "Use default if unwired"! The only right use-case for this setting is in your VI "statemachine_justaddingvalues.vi" the use of the conditional boolean to stop the loop since there is only one case wich is delivering a TRUE

I am trying to fix it right now, mind to explain why shouldn't I use "use default if unwired"?

how is the case "exit" reached?

I don't think I really need this exit case at the moment, so lets just ignore it.

what do you mean with standby, from your description I would think the case "Waiting UDP" means standby, "Add stuff" is the active state

Yes, "Waiting UDP" means standby, in the time it is waiting to receive the data (it's actually more like a flag, to tell LabView that the animation is active). And "Add stuff" is the active state.
what ist the format of the data you receive (or expect) with the UDP packets?

It's more like a flag

are you sure, you receive any data at all?

Yes I am sure, I have tested it.

why do you have these many wait- nodes? The "UDP Read" has a default timeout of 25 seconds, so if you dont't get data, the Wait is meaningless (because the case is exitet when data is floated through all nodes) and if you get the packets faster than 10 times per second, the received packets will be queued up and you develop a delay between sent data and received packets.

I'll take this into account.

why do you write 10 times a 1 to the file, although you enter the state "add stuff" only once? Why the 100ms Wait?

Those values are there just to say a number and see if the program actually works. I'll actually write around 3 seconds of data at 960 samples per second each time I enter that state. 

since your loop speed is very slow you won't get problems with it, but it's better style, to open the file once outside the while loop and feed the RefNum (via shift register) inside the loop and use "write to text file" in conjunction with "array to spreadsheet", to write your data to file. But you should have only one constant with the filepath (outside the loop)

I'll fix it but isn't running out of memory an issue?

 

0 Kudos
Message 3 of 4
(2,262 Views)

Hello,

how is the state of your work? In the meantime do you have more success?

why do you use a shift register, initialized with an empty array, and then with every loop iteration it is written with an empty array again?

... but it's better style, to open the file once outside the while loop and feed the RefNum (via shift register) inside the loop...

To illustrate the principle of writing data to a file I made a little example:

Write Text File.png

 

This is the same principle, the VI "Write delimited Spreadsheet.vi" uses. Since you write only single '0's to the file you even don't need the "array to spreadsheet" node.

Don't use "Use default if unwired"!

why don't you wire the UDP- RefNum through all cases of your state machine...

Both questions touch the same topic. With "Use default if unwired" in unchecked state, LabVIEW will force you to deliver a value to the output terminal, so you will take care, that there is a valid UDP RefNum when the case structure is finished.

 

If you still see no '1's in your file, I would recommend to set a probe on the string- wire after "UDP Read", after the "String Subset" which extracts the first character and perhaps a conditional probe on the boolean wire with "DISPARO", set to break on TRUE. Then you can see in highlighted mode, what happens after a recognized active animation.

Greets, Dave
0 Kudos
Message 4 of 4
(2,244 Views)