LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FOR Loop Inputs

Dear NI Community,

 

I have generated code that produces a set of co-ordinates, when a motion buffer has space available (monitored using a WHILE loop), where those co-ordinates are dependent on values fed in from a sensor. The co-ordinates generated are calculated using a FOR loop with a fixed number of steps (so as to not overwhelm the buffer). This code must run on the cRIO RTOS as it forms part of a motion system. As part of developing the code, I have first started with a basic numerical control, representing the sensor input, and I have been changing the value in the numerical control (while the code is running) to check that the real-time code responds as I would expect, given the input sensor readings. I have found that my code does not execute as expected and I'm wondering if it doesn't have something to do with how I am handling the input sensor values provided to the FOR loop. I have tested the code, with fixed sensor values on a PC and it works as expected. 

 

Attached is a simplified code showing in principle how the the more complex code functions, where I have used a FOR loop contained within a WHILE loop, where the FOR loop only executes when a condition is met. These values are stored in matrix which can then be written to the motion buffer. My question is whether I should only update the value of the numerical control, when the FOR loop is not running, as maybe this value should not change while the FOR loop is executing?

 

Any assistance would be greatly appreciated. 

David

0 Kudos
Message 1 of 4
(329 Views)

While I was able to open and read your VI, I was unable to make sense of what you were trying to do, partly (well, almost exclusively) because wires were running everywhere, rarely straight left-to-right, with almost nothing labelled so it was clear what you wanted to happen.

 

At least there is some (but far too much!) "white space" in your VI, but the eye get tired zipping all over following wires whereas a Block Diagram (with straight wires) occupying 10% of the space you used is easier to "see at a glance".

 

You clearly have some task in mind, as you are doing something with arrays (3 x 10000?).  You seem (??) to be building arrays, but you are doing it in the most inefficient manner imaginable, generating a huge array and then inserting tiny pieces into it.  Do you know about "concatenating output tunnels"?  In your For (and While) loops, you get rid of the Shift registers and wire the output of your 3x1 array (in the For loop) to an output tunnel, right-click the tunnel, choose "Tunnel Mode", and make it a "concatenating tunnel".  You'll see the node change from solid Orange (meaning "what you put in is what you get out") to a box with two sub-boxes inside it, meaning it is concatenating the arrays one after the other.  [There is also an "indexing tunnel" -- if you make a For Loop with N=5 and bring the Index out to an "Indexing Tunnel", you'll get the array [0, 1, 2, 3, 4].

 

Think carefully about what you want to do.  Make as simple a piece of Test code as possible.  Use "sensible" variable names so that you (and we) understand what you are doing.  Do it in the simplest way possible ("How" is less important than "What", so keep it simple).

 

Bob Schor

0 Kudos
Message 2 of 4
(296 Views)

Why are you pre-allocating a large array just to "insert" data later. Not that "insert into array" will grow the array, pushing all  higher elements up. More typical would be "replace array subset", where the array retains the same size. It is not clear to me why you insert the value three times per FOR loop iteration (because you initialize a 2D array with all the same values). Basically, the original 3x10000 NAN element will just be pushed higher and higher, forcing constant memory reallocations. Your FOR loop really makes no sense, because you are already inserting three elements.

 

Can you take a step back and explain what you are actually trying to do. It simply makes no sense at all. Of course dataflow dictates that you "array" will only update one the while loop stops. If you want to see the data "live", the indicator belongs inside the loop.

 

See if this can give you sone ideas. Of course once you run out if allocated array, nothing new will happen....

 

 

0 Kudos
Message 3 of 4
(263 Views)

Hi Bob & Altenbach,

 

Thanks for your feedback and suggestions.

It was an array problem as you both alluded to in the example submitted. I managed to resolve the issue and the code works.

 

Regards

 

0 Kudos
Message 4 of 4
(208 Views)