03-10-2020 10:39 AM
I know similar questions have been asked, but I could not find a solution exactly for my case.
I am currently using a VI in the vision module to do some real-time checking of an object and calculate its's location. The problem is when the object is out the sight of the camera, the calculation takes too long before it tells it can't find the object. I want to stop the VI if it runs too long (say 100ms) and then return 0. My first idea is to use a Timeout event. But I do not know what should I put inside the event structure to stop the whole VI. Some help here will be appreciated.
03-10-2020 12:16 PM
Well, if you had attached your VI, we could make suggestions that would work for your current code, or could suggest how you could modify your code. The basic idea is that your processing routine probably has a loop -- what you need to do is to get a "stop" signal into that loop from the Event Structure. Look up the Producer/Consumer Design Pattern (you can find a Template for this by going to the File menu and choosing "New ..." (the three dots are important!), choosing VI\From Template\Design Patterns\Producer/Consumer Design Pattern (Events)" and studying the example it produces.
Bob Schofr
03-10-2020 04:51 PM
There is no loop in the subVI. I tried to use "stop function", but it stopped everything. Another question is: if a subVI is still running, can I execute it by giving it new inputs?
03-10-2020 10:27 PM
As I've gotten older and crotchetier (is that a word?), I have lost all interest in trying to untangle messy block diagrams. If you make it nice an neat, I'll take another look at it.
03-11-2020 04:06 AM
@paul_cardinale wrote:
As I've gotten older and crotchetier (is that a word?), I have lost all interest in trying to untangle messy block diagrams. If you make it nice an neat, I'll take another look at it.
'Grumpier' works. 🙂
/Y
03-11-2020 05:23 AM
I the VI hangs in a IMAQ function, it simply can't be stopped.
Those IMAQ functions call a dll function, and dll functions can't be interrupted. Even if you manually try to stop the VI, you'll get a "resetting VI" dialog. This will not go away until the function is done.
The event structure will work (if the dll function isn't the problem), but there are a few problems. In the time out case, you'd have to actually stop the VI (with a abort method). If you don't, the event structure will simply finish. The VI will still wait for the rest of the code. Another problem is the VI won't stop, because it isn't running top level. So you'd have to run it top level, with VI Server. If you do run it with VI server, you'd also have to dynamically set the control values, and get the indicator values when done. You might run into new problems, as some values that are created in the sub VI won't live anymore once it stops. I'm not sure if IMAQ images work that way...If it doesn't, you might get leaks because the images aren't closed (although IIRC the memory is recycled if you use the same name). You'll basically run into a waterfall of misery. Fix one problem, get two new problems for free...
I'd try to make a fast initial IMAQ test for the object. Perhaps the same test on a reduced image size? Once you establish it's there, do the accurate test that takes time.
Stopping a VI because it takes to long is symptom treatment. If you get it working, it will never be pretty.
03-11-2020 05:26 AM
And if you wander where your precious CPU power goes...
It's wasted by polling the stop button. That will drain one core. At least put an event structure in the loop!
03-11-2020 09:54 AM
I am wondering why NI do not put a control for the number of iterations in the pattern match VI. It seems very simple. Is it any way I can give a feedback to NI so that they can implement that in their next version of Vision Development module?
03-11-2020 10:28 AM
@Jacobier wrote:
I am wondering why NI do not put a control for the number of iterations in the pattern match VI. It seems very simple. Is it any way I can give a feedback to NI so that they can implement that in their next version of Vision Development module?