取消
显示结果 
搜索替代 
您的意思是: 

Why does LabVIEW skip over commands in programming structures

已解决!
转到解答

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.

下载全部
0 项奖励
1 条消息(共 21 条)
5,840 次查看

Here's the other VIs. 

0 项奖励
2 条消息(共 21 条)
5,839 次查看

Here's a picture of what its skipping.

0 项奖励
3 条消息(共 21 条)
5,834 次查看

@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
4 条消息(共 21 条)
5,822 次查看

@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

5 条消息(共 21 条)
5,816 次查看

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
6 条消息(共 21 条)
5,807 次查看

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 项奖励
7 条消息(共 21 条)
5,796 次查看

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

0 项奖励
8 条消息(共 21 条)
5,794 次查看

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 项奖励
9 条消息(共 21 条)
5,786 次查看

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 项奖励
10 条消息(共 21 条)
5,764 次查看