LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

System that output consist of multiple conditions by using If Condition

Solved!
Go to solution

Hello master. I want to create a system that outputs consist of multiple conditions by using if conditions. The system input is derived from "count" and the second input is "Y". Y input is control input. Then the expected outputs are:


If Y <= 5 and count <= 20, the result is A 
If Y <= 5 and 20 <count <30 result B
If Y <= 5 and count> = 30 result C

 

If <= 5 Y> = 10 and count <= 20, the result is A 
If <= 5 Y> = 10 and 20 <count <30 result B
If <= 5 Y> = 10 and count> = 30 result C

 

Thanks for your attention.

 

Regards,

 

Fajar

0 Kudos
Message 1 of 10
(4,813 Views)

There are a variety of books and on-line tutorials to introduce you to LabVIEW.  Ask your Instructor.  Learn about the Case Statement.

0 Kudos
Message 2 of 10
(4,788 Views)
Solution
Accepted by topic author rmfajar

Assuming "A", "B", and "C" are numeric outputs from a calculation, you can use a formula node.

 

Here is a quick example based off of your (somewhat confusing) notation.  It may need altered slightly, but it could be a starting point (assuming I understood you correctly and you are only dealing with simple, numeric data types as described in your example).

 

formula node.png

 

Otherwise you could just do this using regular LabVIEW Comparison Functions and Dataflow.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 3 of 10
(4,785 Views)

Thanks MrHappyAsthma for your help. I've try but i get some problem.

 

 

 

error1.JPG

 

I try to define this variable but i get an error again

 

error2.JPG

 

What's wrong with my syntax? Thank you Smiley Happy

0 Kudos
Message 4 of 10
(4,759 Views)

@rmfajar wrote:

What's wrong with my syntax? Thank you Smiley Happy


Remove the first line "float x,y,z".  You don't need that.  The inputs/outputs you add to the outside of the formula node declare/initalize the variables.

 

Also "if" should be lowercase.  You have "If" with a capital "i".  This is considered a variable and cannot be found by the compiler.  Lowercase "if" is the reserved word you need.  Change all of these to lowercase and you should be able to compile/run fine.

 

Let me know if you have any other issues!

 

EDIT:

 

Note:  You should be familiar with text-based programming languages for formula nodes.  A helpful guide to the syntax is here: http://zone.ni.com/reference/en-XX/help/371361K-01/lvhowto/formula_node_syntax/ however you may be confused by some points if you have little/no Computer Science backgroud.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 5 of 10
(4,752 Views)

Honestly, there are several things i really don't understand.

 

1. What has the VI you attached to your initial post to do with the question?

2. Your formulas in the inital post are not correct. What is "<= Y 5 >= 10"? I would assume you wanted to write "5 <= Y <= 10". Is that correct?

3. In connection to 2.) Is it possible that Y > 10 at all? You have NO case for this....

4. Looking at your AND with count: The output is completly independent of Y! Simplified, your case is:

count <=20: A

20<count<30: B

count>=30:C

 

just my 5 cents,

Norbert

 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 6 of 10
(4,735 Views)

@Norbert_B wrote:

Honestly, there are several things i really don't understand.

 

1. What has the VI you attached to your initial post to do with the question?

2. Your formulas in the inital post are not correct. What is "<= Y 5 >= 10"? I would assume you wanted to write "5 <= Y <= 10". Is that correct?

3. In connection to 2.) Is it possible that Y > 10 at all? You have NO case for this....

4. Looking at your AND with count: The output is completly independent of Y! Simplified, your case is:

count <=20: A

20<count<30: B

count>=30:C

 

just my 5 cents,

Norbert

 


I agree with a lot of these points.  But it seems like he likes the formula node solution (assuming it works for his program).

 

I assumed the following:

 

1. I believe he wants to wire the "Count" indicator value to the formula node. (Based on his second revision of the program). 

2. I believe you're right.  I also commented on the confusing format.  But based on his second revision of the program, I think we are all on the same page (somehow 😛 )

3. Agreed... I assumed he wanted the cases as he typed them.  I didn't worry much about the logic of his algorithm.  I just pointed out a way to implement it. 

4. Again... I didn't worry much about his logic behind his algorithm

 

OP please address these points to make sure we are on the same page! 😄

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 7 of 10
(4,725 Views)

Forgive me for joining this conversation so late, but what is going on here?  Why are you using a Formula Node to solve this problem?  If this was a MatLab Discussion Group, I might understand it, but this is LabVIEW!  Use one or more Case Statements, and look at some of the comparison functions (such as In Range and Coerce.  Note that wiring a Boolean (say, the output of the In Range and Coerce function, or the output of a Greater Than or Equal function) into a Case Statement will give you both True and False cases, resulting in an Error condition if you don't wire both.  This handles the "missing Y>10" case mentioned in an earlier Reply.  Also, if a little thought and design is given, the resulting VI ("code") should be much easier to understand than a whole series of MatLab IF statements (at least that's my experience).

 

The other advantage, of course, is that the Case Statement is probably the most commonly used LabVIEW block, so a problem like this one is practically designed to get you introduced to Graphical Programming.  Why subvert this goal by reverting to Text Programming?

 

Bob Schor

Message 8 of 10
(4,686 Views)

@Bob_Schor wrote:

Forgive me for joining this conversation so late, but what is going on here?  Why are you using a Formula Node to solve this problem?  If this was a MatLab Discussion Group, I might understand it, but this is LabVIEW!  Use one or more Case Statements, and look at some of the comparison functions (such as In Range and Coerce.  Note that wiring a Boolean (say, the output of the In Range and Coerce function, or the output of a Greater Than or Equal function) into a Case Statement will give you both True and False cases, resulting in an Error condition if you don't wire both.  This handles the "missing Y>10" case mentioned in an earlier Reply.  Also, if a little thought and design is given, the resulting VI ("code") should be much easier to understand than a whole series of MatLab IF statements (at least that's my experience).

 

The other advantage, of course, is that the Case Statement is probably the most commonly used LabVIEW block, so a problem like this one is practically designed to get you introduced to Graphical Programming.  Why subvert this goal by reverting to Text Programming?

 

Bob Schor


I concur.  This can (almost) just as easily be done in LabVIEW.  And the performance would probably be better and you run less risks of compiler errors regarding the Formula Node.  I just used it as it took me about 20 seconds to copy/paste his comparisons, fix the few out of place comparison operators, and wrap a Formula Node around it.

 

I just as easily could have taken two minutes to do this in LabVIEW, but I figured I'd take the fastest approach.  Based on the user's VI, they have some familiarlity with the basics of LabVIEW, so I really don't think this is a necessary learning excercise.  (As you mentioned yourself, the case structure is a common and essential LabVIEW element)  If I am wrong, however, then he/she could easily start working on a case structure based approach if they desire and request more help as needed.

 

NOTE:  In case it wasn't clear OP, Bob_Schor makes a great point.  This can, just about as easily, be done in LabVIEW using more common functions.  This will not only perform slightly better (even though the computation behind this should be pretty quick to begin with), but it will also be less error-prone and easier to read as a LabVIEW programmer.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 9 of 10
(4,671 Views)

Thank you for your help Smiley Happy

0 Kudos
Message 10 of 10
(4,564 Views)