LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

3D line graph

Solved!
Go to solution

Hello!

Well I am trying with my basic (very basic indeed) LV skills to do this: I made a VI that pics the values of an array containin lstitude, longitude and altitude values, processes this values and calculates the spherical coordinates (azimuth,elevation) and cartesian (X,Y,Z).

Then I was trying to represent X, Y and Z in a 3D line graph. I want to obtain something like this:

graph.png

I am experiencing some issues and I think that is related with the axis scales but I can´t solve the problem.

This is wath I get:

3DLV.png

Another problem is that when the loop ends the line disapears and the second time I run the VI nothing seams to apear in the graph and I need to view the line behavior when stoping.

Can anyone please give me some tips?

I also have my code bellow.

Thank you veru much.

Duarte

 

0 Kudos
Message 1 of 13
(7,758 Views)

Start simple.  The graphing function that plots a 3D line wants three arrays of X, Y, and Z coordinates.  Simplify your first loop by throwing away the timer, putting Spreadsheet String to Array outside a For loop, using Indexing tunnels to take each point (a set of X, Y, and Z), do your transformations, and output a set of X, Y, and Z, but this time without recombining X, Y, and Z back into a 3-element Array.  You'll get out of the For loop an X array, a Y array, and a Z array.  Run this (without a loop) directly into your 3D Line Graph function and presto, there will be your line.

 

Once you have this, you can worry about changing it to do other fancier things.  Get the basics first.

 

Bob Schor

0 Kudos
Message 2 of 13
(7,703 Views)

Thanks a lot Bob!

Please check the result!

With this VI I can represent the trajectory of an object in space using saved values of latitude, longitude and altitude. Knowing what to expect, I can say that the Vi is working fine!

Now I need to jump to another level that is representing the points (XYZ) in realtime. Using the latitude, longitude and altitude arriving each 500ms, the VI processes the values and represents a dot in the graph linking this dot to the one before to give the idea of a trajectory.

Can you give me some ideas to do this?

Is it possible?

Thanks again.

Best.

Duarte

0 Kudos
Message 3 of 13
(7,678 Views)

Duarte,

     Sorry I missed your request -- been a few busy days.

 

     What you want to plot is an "Evolving Graph", which LabVIEW calls a "Chart".  However, there are no 3-D Charts in LabVIEW, so you have to "fake it" by drawing Graphs over and over.

     I'm attaching a Snippet, written in LabVIEW 2016 (I notice you are using LabVIEW 2013, which I don't have on my system, but the diagram is simple enough you should be able to recreate it for yourself).  This does a "Random Walk" starting from 0, 0 for 100 steps, updating every 250 msec.  I'll explain, below, how it works.

Random Walk.png

The top three shift registers hold the X, Y, and Z coordinates of the current point, starting at 0, 0, 0, while the bottom three shift registers hold the X, Y, and Z coordinates of the evolving line.  Each loop, the "next point" is computed by adding a random number from -0.5 to 0.5 to the previous coordinate, then appending this new point to the line, replotting the (growing) line each time through the loop.  To keep the plot from "jumping", I set the Axes to -10 .. 10 and called for a Point Size of 3 and a Line Width of 1.

 

Bob Schor

0 Kudos
Message 4 of 13
(7,657 Views)

Hello again Bob.

Once again thank you very much.

Now I understand the principle of your solution, I did it successfully but I still have 3 questions:

1- In my final VI I must replace the upper entry of the Build Array blocks with the new X, Y and Z values? Something like this:

lv.png

2- Do I have to keep the top shift registers or the last value will be the bottom entry of the Build Array block?

3- Can I use a While loop to process a variable number of entries?

 

Thank you.

Duarte

0 Kudos
Message 5 of 13
(7,651 Views)

Duarte,

     You're getting closer.  I went back to look at your Teste_array_2, and found a (minor) error you made that, when you correct it, will probably answer your question.

 

     You have a (space) delimited spreadsheet string that you (properly) read in with Spreadsheet String to Array, to get a 2D array of numbers.  Let LabVIEW do the next step for you.  When you pass it into the For loop, use an Indexing tunnel (if you just drag the 2D wire of the Array to the left edge of the For loop, it will create the indexing tunnel for you, a tunnel whose symbol is an open box with "[]", a pair of array brackets, inside it).  Look at the wire that come out of this indexing tunnel -- it is a 1D array, representing the row of your array.  You should also not wire a constant ("89") to the "N" input of the For loop -- the loop will do its own counting.  Since the indexing tunnel is pulling out successive rows for you, you also don't need the first Index Array function (to get the row) nor do you need to use the "i" Loop Index.

 

What you are now pulling out of the Array are the new X, Y, Z coordinates that you need to convert to Cartesian coordinates and add on as a new 3D point to your "list of points to plot" contained in the Shift Register.  These three values are what you are showing as Local Variables (bad!) X, Y, and Z in your picture.

 

So to fix this up, do the following:

  1. Put the Spreadsheet-to-Array function outside the For Loop, get your 2D Data ready.
  2. Don't wire anything to the For Loop's "N" input, but instead bring the 2D array of data into the For loop through an Indexing tunnel, which will deliver you one row at a time.
  3. Do whatever calculations you need to do (I strongly recommend you write a little sub-VI to hide the very messy details in your current code -- spreadsheet row array in, X, Y, Z out) and add the resulting X, Y, and Z values to the growing Array of Points-to-be-graphed.
  4. I believe you wanted to update every 500 msec, so change the Timer inside the For loop.

This should be all you need.  But seriously, do spend the time to write the sub-VI that takes Spreadsheet Row to X,Y,Z and use that in this program.  It separates two very different tasks, Converting from Map Coordinates to Cartesian Coordinate (which has nothing to do with plotting), and Plotting 3D Data (which has nothing to do with Maps).  Note that the Plotting example you are now using is easy to understand.  Similarly, a well-written Coordinate Transformation VI that doesn't have (irrelevant) plotting stuff in it would also be easy (or easier than at present) to understand.  Combining them just causes confusion (too many wires running around).

 

With LabVIEW, you can do a lot with Good Style!

 

Bob Schor

0 Kudos
Message 6 of 13
(7,637 Views)

Bob,

I have made the changes you suggested. So, regarding the list you wrote:


So to fix this up, do the following:

  1. Put the Spreadsheet-to-Array function outside the For Loop, get your 2D Data ready.
  2. Don't wire anything to the For Loop's "N" input, but instead bring the 2D array of data into the For loop through an Indexing tunnel, which will deliver you one row at a time.
  3. Do whatever calculations you need to do (I strongly recommend you write a little sub-VI to hide the very messy details in your current code -- spreadsheet row array in, X, Y, Z out) and add the resulting X, Y, and Z values to the growing Array of Points-to-be-graphed.
  4. I believe you wanted to update every 500 msec, so change the Timer inside the For loop.

I did the steps 1, 2 and 4 without any problem. Then we have the point 3. I think that you want me to pass the X, Y and Z calculated values directlly from one For loop to the other For loop using index tunnels like I'm trying in the new version of my teste_array_2 bellow.

I think I have done something wrong because I can plot anything.

The version teste_array_3, also bellow, is working, using the local variables linked to the X, Y and Z but there is the problem of the 89 values.

Can you please tell me what is wrong in the teste_array_2? I think its the closest version to the one I nedd but there is nothing in the plot.

After I am done with this I promiss you to make a sub-VI with the calculations.

Thank you!

Best.

Duarte

 

Download All
0 Kudos
Message 7 of 13
(7,631 Views)
Solution
Accepted by topic author DuarteCota

There's only one For Loop.  Each iteration through the loop, you take in one data points from your 2D array, create one point to plot, then plot it!  Like this:

Sphere Walk.png

Note that all of the "complicated" code that occupies so much Block Diagram space that it is hard to see the plotting (or, worse, hard to see that the plotting belongs inside the loop) is nicely "hidden" away inside the sub-VI Map to XYZ (which has a nice, easy-to-create VI Icon so you can easily tell what it should be doing).

 

I'm using a simple 2-row input array, of course, because I'm too lazy to type all of your 89 rows ...

 

Bob Schor

0 Kudos
Message 8 of 13
(7,624 Views)

Something I've said to many of my LabVIEW Advisees -- tell me what you want to do, don't tell me how you want to do it.  When you become a little more advanced (or take on more challenging LabVIEW Projects), you do what I'm currently doing -- Write the Documentation First.  [I've currently got about 8-10 pages, single-spaced, with only a little LabVIEW Code to show for it ...].

 

In your case, "What" you want to do is "Get a bunch of points into Map Coordinates, then for each Point, plot it on a 3-D Graph, connected to the previous points".  The key concept here is "For each ...", which implies a For Loop acting on "the current point and previous points", i.e. a single For Loop.

 

Another trick I often use (for myself) is to write a very simple version of what I want to do (like my Random Walk generator I first posted), then modify it as little as possible to incorporate what I really want to do (Spreadsheet to Array outside the loop + Map-to-XYZ inside).

 

BS

0 Kudos
Message 9 of 13
(7,622 Views)

Bob,

I´m very sorry for all this confusion. Now I did it! It's working fine.

Thanks for all.

Please let me tell you something. The reason I am using the values saved in a spreadsheet, computing them to plot the values, is a way to be shure that the code is doing what I whant because I know what I am expecting.

In my "real" project, the updated values of latitude, longitude and altitude will be arriving each 500ms. I will just pass them to the For loop. I hope it works.

Now I will dedicate some time building a subVI to compute de coordinates and get a clear and organized code.

Then, do you mind I send it to you to get your opinion on the final result?

I am sorry for my english. I am Portuguese and sometimes I write some bad sentences.

Thanks once again.

Duarte

0 Kudos
Message 10 of 13
(7,618 Views)