Accessing the most recent data from a shift register - labview

I am fairly new to LabVIEW so please bear with me. I am working on a piece of code where I am reading data (in the form of an array) from a USB device, splitting this array to meet a required size, storing part of this array in a circular buffer and passing the rest of the data in a shift register. The problem I am encountering is that the shift register will save the data from all other iterations, however I simply want the data from the most recent iteration, but I am not sure how to do this in labVIEW. Perhaps the shift register is not my answer here, but I was wondering if anyone might have some suggestions.
Please let me know if this is clear enough.
I should probably mention that I am using LabVIEW 2011.
In the picture above, I am reading data coming from my hardware. This data is read as an array and I split the array to meet a specific size. I then store part of this array in a 2D array, which serves as a circular buffer and the other part of the array is set to a shift register, where with the next iteration this data will combine with the next set of data read back from my hardware.
The problem I am seeing right now, is that the size of my shift register is constantly growing.

I took, Adrian Keister advice and found my problem. CharlesB was correct the shift register does only show the data from the previous iteration. The reason why the contents of my shift register was consistently growing was because I did not account for the next set of data that would be read during each iteration. Well back to the drawing board

I don't know if I understand your problem correctly, but you should probably try using conditional appending of the array. In LabVIEW 2012 this operation is even simplier because of conditional indexing in for loops.
I provided an example here and hope that it helps. Similar condition can be created for your index modulo operation.
http://i.stack.imgur.com/AALLo.jpg

Related

How to best create an Octree/BVH in GPU memory without pointers?

I've been working on a GPU-based boid simulation recently. I've spent most of my time trying to get the underlying sorting system working, in an attempt to avoid having each boid check every other boid—I'm ideally looking for this algorithm to end up being scalable into the hundreds of thousands of individual particles. However, I'm a bit confused as to how I should try to organize my boids into some kind of spatial tree structure when I don't have access to pointers (I'm working in HLSL).
I elected to try and base my method off of this incredibly helpful article. I already have a relatively quick radix sort functioning properly, but what I'm confused about is how I can actually put the sorted z-order morton keys to use. I naïvely assumed that, once sorted, all sequential boids would be sorted by distance, but this assumption breaks down whenever the boids are near the edge of two "sections" in the z-order curve, which causes some bizarre behavior that I've pictured below:
It seems clear that I also need to construct some kind of BVH (Bounding Volume Hierarchy) data structure so I can predictably access boids within a set distance, instead of just iterating over nearby sorted boids, but I'm stuck on how to achieve this in a language like HLSL that doesn't include pointers. I've read this article a few times, but I'm not sure if it's well-suited to what I'm trying to do. Should I create nodes that store buffer indices instead of pointers? Or is there a simpler way that I could go about this?
I'd deeply appreciate any advice on how to move forward, thank you!

LabVIEW: How to copy from one array to another array?

I would like to deep copy one array to another array. What is the best way to do it ?
I have attempted this way and it seems to work. I would like to deep copy it.
Thanks
Perhaps you're used to a different language where everything is done by reference, but you don't need to do any of this in LabVIEW. LabVIEW automatically copies data on a wire when necessary, but not when it isn't necessary.
The only thing your code is doing is creating an array with an extra dimension, because inside your loop you're building each scalar value into a 1D array with one element, then passing that array to an indexing array terminal which builds an array of the data that is wired to it - since you're passing a 1D array in, you get a 2D array out. However you could have got exactly the same result, if that's what you really wanted, by wiring your original array to a Build Array function then reshaping it from 1 x n to n x 1 using Reshape Array:
If you're worried about memory allocations, which you shouldn't need to be unless your code is actually running out of memory or running too slowly, you can see where LabVIEW will and won't make a copy by choosing Tools > Profile > Show Buffer Allocations. This adds a little black dot to any terminal, of one of the data types you select, where a new memory buffer has had to be allocated. If you do this for the code above you'll see that building an array from lower-dimensional data needs a new buffer, but reshaping an array doesn't.
If you have a very special case where you need to force LabVIEW not to allocate a buffer you can use an In Place Element Structure. But for the vast majority of programming you don't need to think about any of this: just let LabVIEW take care of it for you.
In the meantime I suggest you read the tutorial on loops.

labview - buffer data then save to excel file

My question is with respect to a labVIEW VI (2013), I am trying to modify. (I am only just learning to use this language. I have searched the NI site and stackoverflow for help without success, I suspect I am using the incorrect key words).
My VI consists of a flat sequence one pane of which contains a while loop where integer data is collected from a device and displayed on a graph.
I would like to be able to be able to buffer this data and then send it to disk when a preset number of samples have been collected. My attempts so far result in only the last record being saved.
Specifically I need to know how to save the data in a buffer (array) then when the correct number of samples are captured save it all to disk (saving as it is captured slows the process down to much).
Hope the question is clear and thanks very much in advance for any suggestions.
Tom
Below is a simple circular-buffer that holds the most recent 100 readings. Each time the buffer is refilled, its contents are written to a text file. Drag the image onto a VI's block diagram to try it out.
As you learn more about LabVIEW and as your performance and multi-threaded needs increase, consider reading about some of the LabVIEW design patterns mentioned in the other answers:
State machine: http://www.ni.com/tutorial/7595/en/
Producer-consumer: http://www.ni.com/white-paper/3023/en/
I'd suggest to split the data acquisition and the data saving in two different loops using a producer/consumer design pattern..
Moreover if you need a very high throughput consider using TDMS file format.
Have a look here for an overview: http://www.ni.com/white-paper/3727/en/
Screenshot will definitely help. However, some things are clear:
Unless you are dealing with very high volume of data, very slow hard drives or have other unusual requirements, open the file before your while loop, write to it every time you acquire a sample (leaving buffering to the OS), and close it afterwards.
If you decide you need to manage buffering on your own, you can use queues. See this example: https://decibel.ni.com/content/docs/DOC-14804 for reference (they stream data from disk, buffering it in the queue, but it is the same idea)
My VI consists of a flat sequence one pane of which
Substitute flat sequence for finite state machine (e.g. http://forums.ni.com/t5/LabVIEW/Ending-a-Flat-Sequence-Inside-a-case-structure/td-p/3170025)

Reading specific bytes of data from a large text file... quickly

For argument's sake, let's say you have a single, enormous file to hold your map save data. The game that comes to mind as a great example is Terraria. They save all MapWidth*MapHeight tile data within a single map file (Horrible idea, really) but they can render only what is visible within the camera (And some outer-lying tiles for smoothness sake) based on the camera position.
So my question is, "How can they search through all of that data in real time starting at the camera position?"
That would entail reading through potentially millions of tile data just to get to the screen coordinates. I understand you could skip bytes of data based on the x/y coordinates if the tile data was consistent (This is all I can find in my week or so of searching), but that is where my problem lies. The tile data is dynamic. If one tile is empty, the data beyond "isValid" is nonexistent. So that is less bytes to search through. If a tile has water, multiple states, a background, etc... it contains all the data and is the largest in terms of bytes. So it is not constant at all. In that case we cannot just skip X amount of bytes as it changes (Constantly as tiles are modified).
My current solutions are: Read it line by line (Ugh), use chunk files, or ensure fixed line sizes (Padding? Data wasted... Ugh).
I know chunks would be the best option, but being able to reach that deep into text files quickly would still be a nice thing to know.
If you have chunk-based data, you need a chunk-based reader, simple as that.
Additionally, if you're particularly interested only in certain parts of the data and you can process it first, is to build a second file/list that stores the offsets to the start of every object in the first file.
In that case, whenever you need to reference an object, you look up the offset first and then do a straight jump to it in your original file. It still requires you to read through the whole file at-least once.

How do I manually increment/decrement index in a Labview for/while loop

Here is my basic use case:
After Labview receives a trigger from external hardware start collecting analog data. It monitors this data and triggers another piece of hardware if the analog data reaches a threshold. This threshold can have different values for each trial. However, the operator might want to be able to redo a trial (if the trigger is sent to early because of noise or the threshold isn't reached as expected).
Is it possible to increment/decrement the index or do I need to use a shift register that I can either increment/decrement as needed (ie decrement it if the redo button is pressed)?
Thanks
Azim
Without getting into the nitty-gritty of your application and to answer your actual question, no, you can not affect the value that comes out of the index node in a for or while loop. It autoincrements by one for every loop iteration.
Application-wise, you may want to look into a State Machine. It sounds like you might be able to use that for what you're trying to do.
I think a shift register is your best bet if you don't want to use the autoincrementing index of the loop. This gives you the most flexibility in manually adjusting your index.