LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can XY Graph add a single point to a plot without redrawing previous points?

Background:  I've designed a control system that controls the position of an object.  I want to monitor both the "ideal position" (the path the object should be following) and the "actual position" (the real-time position of the object).  The ideal path is a simple sine wave, and I receive the "actual position" via encoders. 

 

The Problem:  What I want to do is this:  Plot the sine wave on an XY Graph, and then as i acquire samples indicating the current position of the object (via encoder), add these samples, one at a time, to the existing plot.  So basically, the sine wave will be plotted prior to the "Acquisition Loop".  Then my program will enter the "Acquisition Loop" (a while loop), where a new point will be read from the encoder on every iteration.  I want this new point to be added to the existing plot.  I implemented code to do this (I add the new point to an array that is being plotted), but the problem I am seeing is this:  Apparently "XY Graph" replots all the points every iteration instead of just adding the new point to the existing plot.  My program needs to be able to run for a long time, and it also gathers new data points fairly quickly, so I potentially need to gather many data points.  Unfortunately, as the total number of data points I have acquired gets large, the time needed to plot them all becomes too long and the execution rate of my loop slows way down. 

 

I have considered alternatives such as using a circular buffer to plot only the "N most-recent points", but my application really needs to be able to retain ALL the data points.  I also would also really like to be able to use an "XY Graph" due to some of the properties it has that fit my application well.  Is there any way to get "XY Graph" to accept a new data point and add it to an existing plot without erasing the plot first? 

0 Kudos
Message 1 of 26
(9,612 Views)

Hi Nate33,

 

I believe you can just use an XYgraph Buffer.vi. Take a look at the attached example.

Regards,
Claire Reid
National Instruments
0 Kudos
Message 2 of 26
(9,564 Views)

If you use the Express XY graph there is an input called reset.  Wiring a false to this input will add points to the existing plot.  I'm not 100% certain, but I believe it does not redraw the entire plot every time.

 

See attached VI

--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 3 of 26
(9,547 Views)

Could you do me a huge favor and re-post your example as a Labview 8.2 file?  I'm running 8.2.1 and can't open the attachment.  Thanks so much

0 Kudos
Message 4 of 26
(9,465 Views)
This should be it.  If not let me know, I'll see what I can do.
--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 5 of 26
(9,450 Views)

Thanks, i was able to open your example.  However, the Express XY Graph seems to have some peculiarities when it comes to timing.  As i mentioned previously, i need my loop to run at a fairly consistent speed.  Thus it needs take a consistent (and short) amount of time to add a point to an already existing plot (no matter how many points are on that plot already).  I thought this is what the Express XY Graph was doing at first, but after adding some timing to the example you sent me, i could see that the more points that were currently on the graph (ie, the higher the "iteration" number), the longer it would take to plot the next point.  This resulted in an overall slow-down of my loop-execution.  I attached your example with the added timing control. 

 

Also, as a side note, i set the "Reset" option to false and also unchecked the "clear data on each call" box (accessed by clicking on the Build XY Graph.vi).  Any idea what the difference is between these two options?

 

Also attached is an excel file where i plot the iterations vs. time.  The slow down is very apparent from the graph.

Download All
0 Kudos
Message 6 of 26
(9,432 Views)

There are a couple problems I see in your VI. One, you do not have any wait timer so you are asking the computer to run this loop as fast as it can go, and you will probably choke the processory by doing this. Second, you are using build arrays so at some point you would have exhausted a lot of memory, not to mention the memory allocation that must occur at every iteration.

 

I would put a wait timer in there, initialize the arrays and use replace, and then see if you are still having timing problems. It may not be related to the XY graph.

0 Kudos
Message 7 of 26
(9,421 Views)
Also if you want, you can right click the express xy graph on the block diagram and choose show front panel. You could then go in and look at the code used and see if you could build something similar to meet your needs.
0 Kudos
Message 8 of 26
(9,413 Views)

I have put a lot of effort into trying to get graphs updating in a timely fashion when faced with a continuous stream of data.

Here are my tips:

  • Do not update the graph within the control / acquisition loop.  Use seprarate loops, or even separate VIs
  • Put an appropriate delay in every top-level loop - even 1ms stops the loop hogging the processor. Use 100 - 250ms for user interface loops that need a good response time.
  • Use a queue to send data from the acquisition loop to the user interface loop.
  • Use "flush queue" to get all pending data points then append them to the array of acquired data or directly to the graph (using a local variable).  Don't append just one point at a time if there may be several waiting.
  • For really fast acquisition or control put your data acquisition / control algorithm in a sub-vi and set the "Preferred execution system" to something different from the user interface vi.  This stops the user interface blocking the control/acquisition.
  • Use mathematical functions on whole arrays rather than iterating all the points in a for loop if you can.

 

0 Kudos
Message 9 of 26
(9,347 Views)

Hi

I am also having the same timing issue, the first few values are generated pretty fast, but then it slows down.

where exactly should I add the timing delay?

I tried but doesnt seem to really help...

My vi generates the random 2d array, then displays each row on a separate xy graph...

 

 

Thanks!!

(this is my vi in case you need to take a look at it!)

 

0 Kudos
Message 10 of 26
(7,671 Views)