07-23-2026 09:51 AM
Hello all,
I am having trouble figuring out why there is a disconnect between some parallel loops in my main VI. The general idea is that the feeding loops are state machines that will snap a photo, run a detection subvi and overlay vi, and send coordinates to another state machine for a robotic pickup via queue if there is a part detected, or run a partial/full feeding cycle dependent on if a partial had been run already or not. One of the feeding loops has two parts but I think that is negligible. The state machine that is responsible for part pick has a dequeue element in a while loop with a timeout that determines when a part is ready for pickup then goes through the pickup cycle.
The problem that I am running into is that the snapped image data will often not update and so the feeding cycle will send incorrect data to the pickup loop. I am unsure at which point in the feeding loop it is doing this because the buffer for the image gets copied onto by the snap and by the overlay subvi but neither can be skipped over in the loops. My instincts are telling me there is something about the properties of image buffers that I am not understanding and I am hoping someone would be able to help find what's wrong with my architecture. Thank you in advance.
I have attached the Main VI and SubVI's and I am using LabVIEW 2020.
07-23-2026 04:24 PM
Hello, @tbayrg. Thank you for attaching your files.
When I was learning LabVIEW (thankfully with 1:1 interaction with my LabVIEW mentor), I bought a copy of "The LabVIEW Style Book" by Peter Blume and read it cover-to-cover at least 3 times. Here is a key lesson I took away (and have followed ever since) -- Every VI Block Diagram should fit on a Laptop Screen. Granted, the screens are a little larger ...
How do you make this happen? Use sub-VIs to encapsulate chunks of code that "do one thing" (like "Initialize DAQmx Devices" or the Consumer loop of a Producer/Consumer pair. I'm attaching an example and will point out some features:
To help you debug your code as it is, one would need several really large monitors. Take advantage of the "Third Dimension" (depth, or sub-VIs) that LabVIEW provides (and encourages). It also make testing the code much simpler.
Bob Schor
07-24-2026 06:21 AM
Thank you for the advice, I realize it may be quite hard to read when looking at my code so thanks for helping me learn how to clean it up. I was hoping to make my code functional before I started simplifying and grouping things into sub VI's. I've since started a new main vi to see if restructuring the producer and consumer loops into a single state machine would fix my problem or at least expose the issue that I am currently having.
My introduction to LabVIEW was going through an even larger jumbled mess of a main vi with tens of layers of sub VIs, so starting to create my own web of SubVIs intimidates me a bit.
If I manage to find the problem I'll post again. Thank you again for your help.
07-25-2026 12:04 PM
I think the queue is probably doing its job. look to how the image is being handled instead. If the same image buffer is being reused its possible a new snap is overwriting it before the previous one has finished processing, which would explain why you are seeing old image data. Check whether you are passing around the same IMAQ image reference. If you are try making a copy of the image before sending it to the detection and overlay VIs. Also throw a few probes on the image wire to see exactly where the data stops matching what you expect. My guess is the issue is with the image buffer being reused rather than the state machine or queue.
07-25-2026 01:09 PM
Hello, @tbayrg.
After reading (again) your original post, and having my (tired) brain "tweaked" by the recent post from @he,they, the "light bulb" in my head began to glow. I should have asked these questions earlier, but better late than never.
I just noticed (sorry for my sloppy reading of the initial post) you and @he,they used the term "snap" in describing image acquisition. Here's a question -- how do you determine when to acquire an image? Do you analyze each image "looking for a feature" or have a Digital signal that says "Part is in place, take a picture now"? If the first is the case (you examine successive video frames until you find one that shows the part clearly), then you don't want to do a "snap", but rather a "grab" at a suitable frame rate with the camera set up to use image buffers. The frame rate will be determined by how fast the image moves through the frame of the camera. Please clarify what other DAQ devices (besides a camera!) you are using to set the timing parameters for this project.
More things I'd like to know:
Bob Schor