VI High 66 - How to Use XY Graphs with Inconsistent Timing
Much like the frequency we post VI High episodes, the timing of your data can be inconsistent. This episode, we explore the basics of XY Graphs, and then see how they can be used to display data taken at inconsistent timing intervals in a state machine. This completes our 4 episode series on charts and graphs in LabVIEW.
Come visit us at sixclear.com/labview-training
And keep up with us here:
http://facebook.com/sixclear
http://twitter.com/sixclear
http://gplus.to/Sixclear
(start transcription)
Thanks again for coming to visit us at VI High. We have been talking about waveform charts and graphs, we discussed their main differences, we looked at adding multiple plots to each, we changed their timing around, and I have been shamelessly encouraging binge watching by alluding to an XY graph discussion, which has finally arrived, after which you can go to bed, get up for work in an hour, spend the first hour tweeting to your friends about the amazing finale, hashtag us, but please no spoilers.
XY graphs are different than waveform charts and graphs, because we are plotting two arrays against each other. For instance, let’s have an array of pressure readings and a corresponding array of temperature readings. I want to plot them against each other, and an XY graph is perfect for this. As always, bring up our Context Help, and it tells us we need a bundle function. I run it now which one is which? The Context Help tells us X array and Y array. So, generally we would have the temperature on the X array so I will switch these. There we go, and I want to relabel these. Now, that is all pretty simple, but the last episode I talked about using an XY graph for inconsistent timing. Let’s see how to do that. I will open up a new VI, put down a random number function, which I will let go a hundred times, ten milliseconds per time, and at first I will start out pretty simple. I will use for my timing palette to get date time in seconds, and as before I will make arrays of these by wiring them to the border. Bring up my XY graph, and use the bundle function. Run it, and it looks like we made the same mistake as last time, and as before I will make arrays of both of these. As we learned, whatever is the top input to the bundle function will be the X axis, so I want this to be the X axis, this the Y axis. Wire them both to the border, put a bundle function down and wire them both to the bundle function and then to an XY graph. Run it. Now, my values across the bottom, what are those? 3.5 billion? Well those are the number of the seconds that are elapsed, since January 1st1904. As our Context Help tells us regarding to get date time in seconds. Now that is not too helpful for the display though, so I can right click, properties, go to my display format, for my time X axis, and then I will change it to absolute time, and I will get rid of the date. So, I just show the time. Actually I will get seconds, okay. Let’s run this again, now this is shifting around a little bit, because the time at which I start the VI, and thus the first time stamp won’t always be exactly on a second, so we see it moving around a little bit, but the common way this would be used, would not be in the method that I have shown here, but rather we would typically have one or more data points being acquired at a single time, and then have time stamp affixed to that, and the next time we get another piece of data we will put another time stamp on it, so that the end result is that we will have an array of values, and then an array of time stamps, corresponding to when those values are taken. For instance, maybe I have a state machine and I cycle through my states and then one of my states is take temperature, whenever I arrive at this stage I will take the temperature, and then get a time stamp from when that temperature is taken, and then I put that on a graph. This XY graph, because the time at which I come to that state in the state machine varies, it is not consistent.
Note that in many cases you often see these time stamp values be changed to double precision. Right click, insert from the numeric palette, from the conversion palette to double precision flow. The reason being, is that this double value ends up being easier to work with, easier to manipulate, to compare between different states, to subtract and get differences in time, etc.
Now if you take our Lucid LabVIEW Fundamentals Training, there will be an exercise called the LabVIEW toaster where you use a state machine to control the states of a toaster, timing how long would it take to toast, to cool down, checking for temperature, and so on. There are various states in the state machine and in the couple of the states we check the temperature, so here would be a use case for the XY graph application we just discussed. On my front panel is my temperature versus time with my time already set on the X axis. Looking at the block diagram I see that I have a cluster with two arrays in it, now this cluster with two arrays in it is the format that the XY graph expects. I put that in a shift register so that it is accessible to all the states in a state machine. If you are unfamiliar with state machines, go check out VI high 49 and keep watching for a few episodes. We talk all about state machines, error handling, passing data between states, and so on. As we see there are many states, and the state where we are polling the temperature is here in the toasting state. Do not worry all about this code down here. In fact, I’ll move it down. This is the part we’re concerned about. In this toasting state we access our way of time stamp and temperature, we get the new value of the time stamp, whenever this is taken, and we concatenate it on to the array. We do the same thing with the temperature array, and then we bundle both of those back into the cluster, and each loop iteration, we pass it to the XY graph. Now granted there are a bunch of things happening in this loop and we have not really dictated our execution order to ensure that these happen at about the same time. However, the resolution I am more concerned with is around the seconds range and not the milliseconds range so, this is okay with me. Then we can watch this in action if we like, we run it, hit the toast button, and see that we record temperature and time together.
Well all this toasting is making me hungry, I think I am going to toast up a salad. I’m cutting carbs. Thanks so much for joining us in this series exploring waveform charts, waveform graphs, and XY graphs. Do you like this stuff? Check out our course, at sixclear.com/labview-training, either online, regional, or we will come to your company, we would like to meet you. Now I have a salad to toast.
(end transcription)