LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer/Consumer architecture: Optimize Queues

Hi

 

I have reduced the queue lines outside of the loop (the screenshot below). The application is working. I hope that it is correct. I would like to reduce the queue lines inside the loop too. 

 

RegardsSnap6.jpg

0 Kudos
Message 11 of 35
(2,208 Views)

Your unbundling whould be done inside of the event cases.  Then you unbundle only what you need to and just pass the cluster wire straight through all of the event cases.  This will help clean it up quite a bit.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 12 of 35
(2,189 Views)

The application starts normally but I have to push a lot of times my buttons related with the optimized queues to launch the corresponding event.

 

The only reason that the event won't run when you push a button is if you are 'hung up inside the event loop somewhere' rather than 'waiting for the next event'. I am guessing this might be because somewhere in your event cases you are de-queing and there is nothing in the queue so it is waiting, either for something to arrive in the queue (which might not happen if your enqueue node is in the same vi) or for the timeout (do you set the timeout on your dequeue?)

 

Using queues inside event loops like this is fraught with peril and there are few cases where it is the optimum design pattern. And four queues being read inside the same loop is also asking for trouble. More often an event loop adds items to a queue in response to user input and a separate loop de-queues the items and processes them accordingly. Usually a separate loop for each queue.

 

On your readability, you have a lot of cluster constants taking up a lot of space. Double-click the border to reduce them to an icon and you diagram immediately becomes much less cluttered.

 

I think you would benefit from drawing or listing out exactly what it is you are trying to do - what has to happen in response to what stimulus, what states are involved, and so on. You will probably find that your architecture can be enormously simplified.

0 Kudos
Message 13 of 35
(2,187 Views)

One of the nice things about Queues is that it facilitates communication between parallel loops.  I notice that your Enqueue takes place inside the timeout of an Event loop.  It seems to me that it would be much simpler to put the Enqueue in a "Loop of Its Own", a While loop with a 100-msec Wait (to clock it at 10 Hz).

 

Here's a suggestion about improving the Wire Mess.  Building a Cluster is (probably) a Good Idea.  Bring the Cluster wire in, and pass it through to the outside (rather than the individual Queue wires).  Now, when you dequeue your four or 5 Queue wires, instead of spacing them tightly together, take just one Queue wire, arrange it as straight horizontally as you can, and take it only as far as the Enqueue function.  You don't need it past this, as you are bringing out the combined Cluster wire.  Now repeat this process with the second Queue wire, spacing it far enough below the first so it can also run straight horizontally (up to the Enqueue).  Space the code needed to "feed" these Queues so they line up nicely with the Enqueue function.  When you are done, you should have no wire tangles, four (or 5) horizontal groupings of related functions (loading the camera, the manipulator, etc.), and probably a smaller total loop.

 

You now have nicely separated Function into "Events" (which are, by their nature, asynchronous) and "regularly-timed sampling" (which is highly synchronous).

 

Bob Schor

 

P.S. -- I highly endorse the comment made just before this one about drawing or writing out what you plan to do.  I've been known to say that before opening LabVIEW, one should open Microsoft Word (or something similar) and only start coding after at least 5 pages of text are written.  It has taken me quite a few years to learn this, myself ...

0 Kudos
Message 14 of 35
(2,168 Views)

Hi

 

Thank you for your answer. I didn't understand exactly how to connect the cluster with queues to the loop. I am sending the screenshot with my code and with blue lines I have drawn what I understood. If it is correct what I have to do with the unbundle part of the queues marked with red ellipse? 

 

Snap7.jpg

0 Kudos
Message 15 of 35
(2,154 Views)

Move the red circle inside the event structure.  Now you only have one single cluster of queues wire going in.  Pass that through every event case.  That way you don't need the rebundling going on inside your event cases.  Just unbundle the cluster into whatever queues you need to use in each event case.

 

Your picture shows a False constant wire to the while loop's stop terminal.  That while loop is going to run forever.    You are forced to abort your VI in order for it to stop, in which case everything that would occur after the loop like releasing the queues, will never happen.

Message 16 of 35
(2,148 Views)

Hi

I will say first clean Up your code.Use sub Vi.Then we can understand the issues better.

Example:

QueueInit subVI.jpg

Certified LabVIEW Architect
Certified TestStand Architect
Message 17 of 35
(2,123 Views)

... and take the Enqueue out of the Event Structure.  Make a separate, parallel loop with the Cluster coming in, being unbundled into 4 Queues, each Queue having data Enqueued into it, and the entire loop "clocked" with a Wait (ms) (or, better, Wait until Next ms Multiple).

 

With two loops (one being the Event Structure with nothing in the Timeout case, the other being the "Enqueuing" While loop), you have the problem of how to stop the While loop.  But (I'm guessing here) you also have an elegant solution in your Event Structure, which probably tests a Stop Button and stops its While loop when Stop is pressed.  Well, pass the Queue Cluster through the Event loop in addition to passing it into the Enqueue While loop.  When the Event loop exits (because you pushed Stop), use the Queue Cluster to Release all of the Queues.  What will this do to the Enqueue While loop?  Well, every Enqueue that tries to put something on a destroyed Queue will generate an error on the Error line -- if you wire the Error line to the Stop indicator on the While loop, the While loop will stop when the Queues are released (which is precisely what you want).  No need to bring the Queue cluster out of the While loop at all!  This gets rid of lots of wires.

 

Bob Schor

0 Kudos
Message 18 of 35
(2,111 Views)

Hi

 

Thank you for your answers. I have corrected my code according to your suggestions. What I have to do with the queue lines, marked with the red ellipse, shown in screenshot below? I have to delete them or I have to bundle them? 

 

Snap8.jpg

0 Kudos
Message 19 of 35
(2,075 Views)

Delete the wires going into those tunnels.  You are no longer using the output of those tunnels after the event structure.

 

Those queue references are all still in that cluster you have wired out at the bottom of the events for when you do need to get to them again after the event structure.

 

I would combine the error wires wires from the Enqueue functions as well inside the event structure so you only deal with one error coming out of the event structure.

0 Kudos
Message 20 of 35
(2,051 Views)