04-14-2018 11:29 AM
Hi there,
I'm still relatively new to LabVIEW and looking for some help regarding counting the number of good/bad parts in an inspection v.i. I have previously used while loops and for loops for either the good or the bad parts cycle and used the iteration counts of said loops to show the number increasing or decreasing on a vertical slider.
How can i do it in the example i have attached? i tried a few things but only ever increase by 1 when I get the TRUE value. how can i make these values cumulative? Array perhaps? sorry i am still very much a rookie.
any guidance greatly appreciated.
Solved! Go to Solution.
04-14-2018 12:22 PM - edited 04-14-2018 12:23 PM
Hey Newton,
You can use a shift register as the one that you already use in your VI. Something like this colud work :
Check the value of your control (TRUE or FALSE) or any of your triggering object, and increment the value in the shift register only if needed 🙂
Hope it helps.
04-14-2018 01:11 PM - edited 04-14-2018 01:41 PM
@Newton1878 wrote:
I'm still relatively new to LabVIEW and looking for some help regarding counting the number of good/bad parts in an inspection v.i.
Yes, all you need is a shift register, but make sure the count is an integer (blue). It is bad form to use a floating point (orange) number for tracking counts. You should keep track of at least two of three numbers (good/bad/total), the third can be calculated. In this case, you get the "total" directly from [i] of the outer loop, so all you need is count bad or good.
We can see that you are a beginner, because your code has some very questionable code constructs in your existing code. for example.
04-14-2018 01:33 PM
Thanks for the input much appreciated.
Don't worry its not usually that messy just trying to figure some stuff out before i start on the finished article!
04-14-2018 01:38 PM - edited 04-14-2018 01:43 PM
Of course creating an elaborate state machine is a good exercise, but for the current problem all you probably need is something like this. (The single LED is true=red, false=green, note that I flipped the logic of the comparison). See if you can build it. Modify as needed.
As you can see, it is also useful to label the various diagram constant (right-click...show label) for better documentation. Also keep them in one place. There are harder to find and modify if they are randomly scattered around the diagram. Since they cannot change during a run, it is irrelevant if they are inside or outside the loop.
You can probably guess what's in the other case 😄
04-14-2018 01:56 PM - edited 04-14-2018 02:04 PM
@ML927 wrote:
Something like this colud work :
... or simpler ...
(Note that it is often better to have the indicator right after the shift register, else it might show a stale value if the loop contain lengthy code (e.g. an event structure) before a decision on the value is made. Does not apply here of course.)
And yes, that coercion dot is perfectly fine 😄
04-15-2018 06:54 PM
I'd be curious to see if the Select or the conversions are quicker. I suspect the first (with data type changed to Int) would be easier for others to read right away.
04-15-2018 10:30 PM - edited 04-15-2018 10:30 PM
I did some tests and it seems that the Select version is slightly faster (~30ms vs. ~48ms for the conversion version). Yet, I did the test over 20M increments which I really unlikely to happen here. So I guess that both versions are pretty much the same considering the timing factor 🙂