LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Structure/While loop

Solved!
Go to solution

Hi everyone, i am new to Labview and i easily lost my way trying to figure some issues on a program i'm working on. So the issue is that i've been trying to establish specific conditions for an event structure, and a while loop, with local variables, results from logic ops.. Well while surfing the internet for some answers, i discovered that it is required to a value(signaling) for the both of the structures to be "recognised".. Sadly i couldn't create one for the local values or the outcome of the logic ops.. i know the issue i mentioned might be stupid, but i'm simply stuck in the mud trying to figure out how to finish a project, with something new to me on a very limited period of time, so your help will be greatly appreciated.. Thanks 🙂

0 Kudos
Message 1 of 7
(5,139 Views)

Show us some code!

 

Events typically are for user interactions, not for algorithms. Also local variables are typically for UI tasks, not computations.

 

What is your program supposed to do? Let's start here!

0 Kudos
Message 2 of 7
(5,133 Views)

altenbach it's good to see you here, been seeing your posts all over the forum! 🙂

Well i wouldn't say algo are what you'll find in the program but here is the thing:

The program mainly is about a UI that consists of controlling a stepper motor via an Arduino. The stepper motor is attached to a "disk" marked with various position, uuh let's say a marked knob. The user, with the UI, has the ability to change automatically from a position to another without having to intervene manually.. I tried to begin with the command part so i began with something virtual, like virtual sensors etc. The blinking LEDS are equivalent the direction of rotation of the motor.

Anyway the huge amount of repetitions and case structures is because of the issue i previously mentioned, they were a desperate try to turn around it to some degree..

Please bare me with what you're about to witness, it's been about 2 days since started with Labview! ^^"

 

The 'capteur' are supposed to be position sensors just in case..

 

0 Kudos
Message 3 of 7
(5,106 Views)
Solution
Accepted by Vito_Scaletta

Yes, you need to start with more tutorials. 😄

 

  1. If these booleans come from a daq reading, you don't need an event structure.
  2. Get rid of the local variables and connect the controls directly to the indicators (lower right). You also need to ensure that the indicators are only updated after the event has fired. Right now, they update with the old values while the event structure is still waiting.
  3. Many cases seem identical, so you need only one case each (name it e.g. 1..6 and make the other the default)
  4. reading a local variable (e.g. "boolean 2" or "boolean" (also in the lower right) and writing it to its own terminal makes no sense. You are also writing to these terminals (via local variables) in the case structure above in parallel, so whatever writes last wins and the outcome might not be as expected.
  5. Your event structure prevents the big loop from spinning.
  6. You could dramatically simplify your code by using arrays of booleans. (8x less code!).
  7. You are only dealing with integers, so all orange wires should be blue instead.
  8. ...

 

 

Message 4 of 7
(5,100 Views)

will do haha!

Again forgive me for the mess you saw, but just two things, before the stock of case structures you saw i used while loops, the problem is the values do show up, the condition to stop spinning  (the results of the logic ops) they show operate correctly only once then the program gets stuck in an infinite loop and no longer responds, and in the event structure, they have no effect at all, only the values coming from the "mechanical" ones work without any issue. Do you have any idea why? And if you do not mind, if i may ask, why is the case event preventing the bigger loop from spinning?

0 Kudos
Message 5 of 7
(5,092 Views)
Solution
Accepted by Vito_Scaletta

Regarding the Event Structure stopping the While Loop from spinning - the while loop will only start the next iteration (i.e. loop) when everything inside itself is finished.

 

The event structure only does something when one of the 13 cases you've specifically given happens - and since you've set the timeout to '-1', the timeout case never happens (so you could delete that case for timeout = -1 always, or you could make it so the event loop can timeout.) In this case, it seems like maybe you would want to change the timeout value to a small(ish) positive value, but as altenbach mentioned, you might not need it at all if you restructured the code (depending on the real source of input).

 

Regarding the top Case Structure, you have many cases with the same content as altenbach mentioned, but moreover, each contains three more case structures where only one will ever execute, and the one chosen only changes the timer value. Since this is all the same code in each case, a subVI seems like a good choice, but I've placed below a snippet (you can drag and drop it onto a block diagram) that shows both altenbach's suggestion of grouping the cases, along with some simplification of the cases themselves. The 0 and 7 cases are also joined (with each other), because they also only change the timer value.

 

boolLogic.png

 

 

 


GCentral
Message 6 of 7
(5,060 Views)

I couldn't be more grateful for your replies, thanks to your advice i got my system somehow working! Thank you so much who ever you are! 😄

0 Kudos
Message 7 of 7
(5,024 Views)