LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does LabVIEW skip over commands in programming structures

Solved!
Go to solution

Hello everyone!

 

Is there a certain way you program to make labview execute ALL commands within a loop before going into another loop? For example, I have a while loop that stops if either the stop button is pushed or if the set point input is greater than 8. If both of these are false, then the code entered a case structure where it controls the output from a plant model. However, labview will enter the case structure without checking if both conditions are met. I've attached the VI and in the next message will post the VIs from the plant. I want it to do the below code,

 

IF (Set Point > 8 OR Set Point < 0) THEN

       SET_Point OK= False

ELSe

      SET_Point OK = True

END IF

 

IF (SET_Point OK = FALSE OR Stop Button pushed) THEN

         ! STOP VI

ELSE

         ! Enter PID Control Loop

END IF

 

But labview likes to just jump around and skip parts for some reason. So when it for example, skips the OR check it uses the default value of true for the next case structure. It's driving me crazy. Can anyone please tell me why its doing this??

 

Thanks.

Download All
0 Kudos
Message 1 of 21
(4,321 Views)

Here's the other VIs. 

0 Kudos
Message 2 of 21
(4,320 Views)

Here's a picture of what its skipping.

0 Kudos
Message 3 of 21
(4,317 Views)

@andrewjoe777 wrote:

Here's a picture of what its skipping.


LV doesn't skip anything. If it's only sending True to the case structure, then your global is True all the time.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 21
(4,305 Views)

@andrewjoe777 wrote:

But labview likes to just jump around and skip parts for some reason. So when it for example, skips the OR check it uses the default value of true for the next case structure. It's driving me crazy. Can anyone please tell me why its doing this??


LabVIEW does exactly what you ask it to do. Since you do a logical OR, the output depends on the "set point OK global" as well as the negated stop button value. Since stop is false, NOT.Stop is true and the output of the OR function is also true, independent of the global.

 

You should really simplify your code. Do you really need a global variable to send a value to the next sequence frame? Just use a wire. Same for the set point global. Why do you need a global in both cases?

 

You should simplify your logic. Call the boolean "Set point error", use "stop if true" on the loop condition, and switch the two cases. Also look into the "in range and coerce" function

Message 5 of 21
(4,299 Views)

The vi code does not implement your pseudocode: as you negated both conditions about SET_POINT and STOP, you must use an AND instead of an OR.

Otherwise, as long as you don't click STOP (not STOP = true), the OR result will be TRUE.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 6 of 21
(4,290 Views)

Ah! I can't believe I made that dumb of a mistake. And thanks for the advice altenbach. My overcomplicated diagram probably lead me to making that error. 

 

I have another question though. How come when I use the Write to measurement file VI it will start the process variable at like 40 inches but when I don't use it, it'll start it at 0 and do as its supposed to? I've attached my updated VI with the write to measurement file VI in it. You'll see that if you delete it then it'll do as its supposed to. I don't understand why though..

0 Kudos
Message 7 of 21
(4,281 Views)

Here's the VIs for the plant. They didn't change though.

0 Kudos
Message 8 of 21
(4,280 Views)

Here;s a picture of it giving the wrong initialization when using the write to measurement VI as well the a picture of it giving the right initialization when NOT using write to measurement VI.

0 Kudos
Message 9 of 21
(4,274 Views)

I cant open your code, but it sounds like a race condition, especially as writing takes time. That's a common problem when using local variables instead of wires.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 21
(4,252 Views)