LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nested loops in Formula Node don't work

Hello people,

 

I'm working on a code which calculates some mechanical loads. It has a number of variables so I tought I'd rather use Formula Node than wire all the things together. However, when I try to nest two for loops in each other, or an "if" in a for loop, I can't have the code start. I excluded all the other possible errors and I had a really strange conclusion... that one cannot nest structures in each other the range of which is determined by {} characters. Can someone please comfirm it, or tell me what's the way to make these nested structures run? I attach the code, don't bother about the other variables, the point is the loops and the if structures.

 

Greetings,

Andris

0 Kudos
Message 1 of 7
(2,664 Views)

First,  if you want some help, please post some data in your controls, make those value default, and then save and post the VI.  That way we don't have to guess what the data should be to make it run.

 

Second, index array is expandable.  Drag the bottom border downwards.  Then you'll get indices 0 through 3 with a single function node, and BONUS!, you don't have to create all those index constants.  It gives the indices in order.

 

Third, why are you using a formula structure?  If you are just using some loops and if then else statements, that can all be done in LabVIEW G code.

Message 2 of 7
(2,632 Views)

Thank you RavensFan, expanding Index Array was whole new for me.

I wanted to use Formula Node because on some further parts I will need to nest two For loops in each other and then two If in each other within the inner loop. After some search for G code in Labview I only found what I suspected - machine tools' programming. I don't see how would that help me in writing loops and conditions, can you please recommend me a thread at the forum or any article on that?

 

Andris

0 Kudos
Message 3 of 7
(2,620 Views)

No.  G was not meant as in the CNC program code.  G as in "graphical" programming, which LabVIEW is a part of.

 

Actually use LabVIEW.  There are Case Structures, For Loops, and While Loops.  Shift Registers maintain a "variable" from one loop iteration to the next.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 4 of 7
(2,616 Views)

@Andris26 wrote:

After some search for G code in Labview I only found what I suspected - machine tools' programming.


Andris,

     I decided to try to write your Formula in LabVIEW (it should, in principle, be very simple to do).  However, I was struck by the comment you made in your last post, so wanted to start by clarifying something.  When talking about a Programming Language, many of them are given names, sometimes consisting of a single letter (C and R come to mind).  I don't know when (or how formal it is) that LabVIEW Developers began "informally" (though there may be a formal definition, I'm just too "green" to know) calling the Graphical representation of LabVIEW code "G" (as in "Graphic" or "Graphical", get it?).  So by "G", we mean "The structures, wires, and functions you get when you open LabVIEW and create a new VI or sub-VI".

 

So I thought it would be easy to go from your Formula Node to the Inputs, Outputs, and the "stuff in the middle", but several things seem "wrong" --

  • You declare MP as an Array of 4 Floats, yet in the For loops in the formula, MP is never given an Index (i.e. you write MP = MP + ... instead of MP[index] = MP[index] + something.  This seems "wrong" to me, unless you mean to set every element of MP to the same value (but then why is it an array?].
  • You carefully define p1m and sz1b, then never seem to use them.
  • You carefully split out the four values in the input array to variables Ap, Am, Bp, and Bm, but seem to only use Am.  What are the others for?
  • The first For loop computes Mh[i] = -Am*(i/10) (I see no reason to create another variable, j, to represent i/10).  Just before exiting the second For loop, you do it again, but with different values for i.  It might help the Reader, the next person to try to use this code, or yourself to simply compute this once.  Of course, now that I say that, I realize that I cannot properly do this, as Mh[3] and Mh[4] are never defined!  [Look at your code -- the first loop has i = 0..2, the second has i = 5..50].  Is this what you intended?

Here is a suggestion, which will certainly help us to help you:  instead of writing down the computations you want to do using a script language (which appears, to me, to have several mistakes in it), why don't you show us the formula you are trying to compute (if it is available on the Web, you can point us to it, or you can write it down in "math" notation, using Capital Letters for 1D Arrays (Vectors) and lower case letters for scalar variables.  As has also been suggested, if you provide what might be typical (or otherwise known, reasonable) values for these quantities and the output that you would expect, we would be able to test any code we suggested to ensure that it works.

 

     One of the beauties of LabVIEW (or "G") is that you can often glance at some code and see what is going on.  For loops with arrays going into them are much easier (for someone who knows LabVIEW) to recognize as "process each element of this array" than a C-style For statement (see my last point, above, where you appear to have left two indices out in your computation).

 

Bob Schor

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

@Bob_Schor wrote:

@Andris26 wrote:

After some search for G code in Labview I only found what I suspected - machine tools' programming.


Andris,

     I decided to try to write your Formula in LabVIEW (it should, in principle, be very simple to do).  However, I was struck by the comment you made in your last post, so wanted to start by clarifying something.  When talking about a Programming Language, many of them are given names, sometimes consisting of a single letter (C and R come to mind).  I don't know when (or how formal it is) that LabVIEW Developers began "informally" (though there may be a formal definition, I'm just too "green" to know) calling the Graphical representation of LabVIEW code "G" (as in "Graphic" or "Graphical", get it?).  So by "G", we mean "The structures, wires, and functions you get when you open LabVIEW and create a new VI or sub-VI".

 

 

Bob Schor


The official name for the language is G, where LabVIEW is the actual name of the IDE. Since you have to use the IDE in order to program, most people simply started calling it LabVIEW.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 6 of 7
(2,592 Views)

@Mark_Yedinak wrote:

@Bob_Schor wrote:

@Andris26 wrote:

After some search for G code in Labview I only found what I suspected - machine tools' programming.


Andris,

     I decided to try to write your Formula in LabVIEW (it should, in principle, be very simple to do).  However, I was struck by the comment you made in your last post, so wanted to start by clarifying something.  When talking about a Programming Language, many of them are given names, sometimes consisting of a single letter (C and R come to mind).  I don't know when (or how formal it is) that LabVIEW Developers began "informally" (though there may be a formal definition, I'm just too "green" to know) calling the Graphical representation of LabVIEW code "G" (as in "Graphic" or "Graphical", get it?).  So by "G", we mean "The structures, wires, and functions you get when you open LabVIEW and create a new VI or sub-VI".

 

 

Bob Schor


The official name for the language is G, where LabVIEW is the actual name of the IDE. Since you have to use the IDE in order to program, most people simply started calling it LabVIEW.


G-Wiz.  That's my new name for you.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 7
(2,567 Views)