06-01-2018 09:09 AM
Hi all,
I have a VI that rotates a line by a specified number of degrees around the X axis
The VI does this well and displays the rotated and original line on an XY graph
However, I now want to get the values for the rotated line (so I can calculate how far the line is from a target line using RMS), but I can't seem to work out how to do it... It appears to be giving me an *output cluster* but I can't transform it to a 1D array (tried with an indexed for loop and unbundle element).
Weirdly also it doesn't seem to plot just the transformed line alone - it tells me that the type of data is 1D array of cluster of one element and the sink is also a 1D array of cluster of one element... so I am a bit confused...
Any help getting this into a 2D array with the X and Y values for each point would be great, thank you!
06-01-2018 09:53 AM
You are getting confused between Clusters and Arrays, and between Bundle (assemble elements into a Cluster) and Unbundling (getting elements out of a Cluster).
You start with a 2D array representing Points from Excel, with the rows being Points and the two Columns being X and Y coordinates. With a For loop, you bundle the Points into a Cluster of X and Y coordinates, but make a Beginner's Mistake (which, fortunately, my LabVIEW Guru warned me about when I first started learning LabVIEW) -- if you are going to use a Cluster to do some serious work, always create a TypeDef for it and name the Components. Your TypeDef would be a Cluster of two Dbls labeled X and Y, and would look something like this:
I assume you know how to create a Cluster on your Front Panel, fill it with two Numeric Inputs, name them X and Y, create a TypeDef from the Cluster, and name the TypeDef (I called it TYPE Point). You might also notice I created an Icon for this TypeDef -- this is because LabVIEW lets you place a Cluster TypeDef on a Block Diagram (where it looks big and ugly, and you have no idea what it means) and right-click its edge to turn it into an image of its Icon -- how cool is that? Self-documenting!
Now you want to always use Bundle by Name and Unbundle by Name, no more Bundle/Unbundle -- you will "see" X and Y, and will instantly know what is happening.
So you now have an Array of Clusters. In your For Loop, you auto-index through the Array, getting out each Point (cluster), Unbundle (by Name) the Cluster to get X and Y, transform it by your rotations, then Bundle-by-Name and assembly the Point Array on the output Tunnel.
So you now have an Array of Points. Did you really want an Array of X and an Array of Y? The time to do that is before Bundling X and Y back into Points inside the For Loop. If, instead, you brought X and Y out into Arrays, you would have an X Array and a Y Array. You could bundle this into a different Cluster (let's call it "Line", being an Array called X and an Array called Y). It is perfectly legal (and occasionally useful) to have an Array of Clusters and a Cluster of Arrays, but they are very different things!
So now, knowing all this, go back and think what you want, and make it happen!
Bob Schor
06-01-2018 12:10 PM
Hi Bob,
Thanks for your help - I have extracted the x out and y out values after their transformation and put them into an array at that point (using a shift register and build array), this seems to be working!
I was interested in what you said about making typedefs - I had a bit of a read about them and watched some videos but not sure I have quite understood the whole process... Is this anywhere near what you meant?
Thank you!
Harriet
06-01-2018 01:27 PM - edited 06-01-2018 01:28 PM
Don't use the shift register with the Build Array. Use an autoindexing tunnel. And do NOT use that local variable. You are guaranteed to get bad data due to an obvious race condition. This is probably closer to what you need.
06-01-2018 04:10 PM
@hdempseyjones wrote:
I was interested in what you said about making typedefs - I had a bit of a read about them and watched some videos but not sure I have quite understood the whole process... Is this anywhere near what you meant?
Harriet,
Sorry, I "dropped the ball" and failed to get back to you last week. Listen to crossrulz about indexing tunnels -- much easier way to build arrays (you can even make the tunnel a "conditional" tunnel that allows you to choose which elements go into the array).
As to the TypeDef, you did it exactly right! Mine differs from yours in that I named the Cluster "Point" (instead of Cluster), got rid of the Increment/Decrement buttons on X and Y (they take up space), used Autosizing (right-click cluster on Front Panel and choose "Autosizing") to Arrange Vertically (why not make it compact and "pretty"?), and use the Icon Editor to give it an Icon (I made a square box with the word "Point" inside it).
But where do you use it? In the very first place you define the Cluster, the For loop where you do an "Array-to-cluster" operation. Instead of doing that (which, you must admit, is a little mysterious -- what is this Cluster about, anyway?), you put in a Bundle by Name, wiring the TypeDef you created to the top input, and "Presto!", the X and Y inputs magically appear. Drop an Index Array function down, wire the (now 1D) Array to it, and (here's a trick I learned after about a year using LabVIEW) drag down on the bottom margin of Index Array to get two index inputs. Don't wire them -- they'll give you (by default) the first and second elements of the Array, i.e. they give you X and Y.
Now it is clear what you are doing -- the 1D array "represents" the X and Y values of your Point, which you are putting into the Point Cluster. [If you'd made an Icon for the TypeDef, you could have something like this on your Block Diagram:
Bob Schor