04-22-2016 04:34 AM
Hello! I've tried this suggestion but I can't get acces to each number for every iteration, The loop is just sending out the final one. I need the numbers as they increase inside another loop. Any help would be of help!
04-22-2016 07:30 AM
To (badly) paraphrase a well-known saying, "What Changes Inside a For (or While) Loop, Stays Inside the For (or While) Loop". [As with every rule, there are exceptions ...]
The Principle of Data Flow (absolutely central to LabVIEW) says that functions (such as graphs, charts, and indicators) placed outside the Loop cannot show you changes that take place inside the loop (but see [statement] above) -- values only are exported from the loop when it exits. If you want to use/watch values that vary inside the loop, you need to put your indicator ... inside the loop!
Look at these three examples, all of which end with Rand being the final Random number and Count being the final Count (99 -- do you know why?).
The first example will display only one value, the final one. The second example will, in fact, display all 100 values, but they'll zip by so fast you'll only notice the last one. The final loop adds a 50 millisecond wait to let you see the numbers count up, and after 5 seconds, the loop will exit leaving the final values in the indicators.
[If you try this yourself, you'll notice that when you code the first example, the wire coming out of the For loop is not a "Last Value" tunnel, but an "Indexing" tunnel, looking like a square-within-a-square, building an array instead of the last value. You can right-click the tunnel and change it to a Last Value tunnel, which is what I did.]
Bob Schor
04-23-2016 03:19 AM
Many thanks for your fast reply.
The reason for needing access to the loop, was that we are doing some frequency analysis on an hydraulic actuator, and therefor we nedded to change the frequency at given time intervalls. The code attached seems to respond like we want. If you have suggestion how to improve the code, pleas feel free to comment, sample rate at 0,5ms is required.
Regard Jan
04-23-2016 09:20 AM - edited 04-23-2016 09:58 AM
10 second analysis:
04-23-2016 12:22 PM
Many thanks! It seems like my Labview code has room for improvements.
Regards Jan
04-23-2016 01:44 PM - edited 04-23-2016 01:45 PM
Also note that your lower loop run at a near infinite rate if the selector boolean is false, spinning the loop as fast as the computer allows, trying consume all available CPU and starving all other processes (e.g. the upper loop!).
Here's how the code of the lower loop could look like instead. (Personally, I would probably implement that logic into the upper loop and eliminate all locals.)
04-23-2016 01:44 PM - edited 04-23-2016 01:45 PM
I don't usually recommend this (it is far better to learn to write "neat" code from the beginning), but something you might try (do it with a copy of your VI, just in case) is to use the "Clean up diagram" tool (on the Block Diagram toolbar, it's off to the right and looks like a broom). This tries to straighten your wires, make sure they don't "run backwards" (as some of yours do), and tries to get rid of unnecessary blank space (because it is easier to see/understand code if you don't have to "search" for where wires go).
Bob Schor
04-23-2016 01:59 PM
Many thanks for your feedback. I did try to manage to increase the frequency inside the main loop but I cound not figure out how. The lower loop seems to be a quick fix, but obviously not that clever. Why is local variable not a such a good idea?
Regards Jan
04-23-2016 02:51 PM
If you use local variables without thinking, you create situatios where you can't control when they're being read or written from/to. Your logic breaks down if the two operations happen in reverse or arent' consistent. It's better to pass a wire, when possible, or use a queue to block computation until a new values appears.
04-24-2016 01:24 AM
Thanks!