Jump to content

How to avoid stopping and restarting my VI


Recommended Posts

Hi everyone, total newb to this.

I've started writing a vi and pretty much got it doing what I want, but I want to make a few improvements and I'm not sure about how to go about it.

Part of my vi is attached. This loop takes data from an array where the user can specify which columns are passed to the loop. There is a bottle neck in initially passing the data to the loop as there is a sub vi which does some array maniupalation to put the data in a form suitable for plotting. So what I would like to do is to be able to simply load the data then have the user be able to clear the graph and replot various columns against one another without having to load all the data again.

There are some further things I would like to do, but a little less essential at the minute:

1. How do I vary the timing of the loop? One of the columns in my data is time, I have done a little routine to get the difference between each time (roughly 25 ms hence the delay of 25 ms in the loop) however when I try to delay each point by the 'real-time' delay I think all that is happening is that the loop is running right through with the first delay, then with the second delay etc. etc. Hope this bit makes sense :unsure:

2. A density map. This data is time and location, what method would I use to make a plot of how long our tracer spends in each location over the course of a run? I have a rough idea that I would need to make a 2D array where each value corresponds to a location then loop through the location data and populate my array. Not sure what the best way to go about this would be though.

Anyways, any help appreciated :)

Link to post

QUOTE(mcguirpa @ Mar 7 2008, 10:38 AM)

Hi everyone, total newb to this.

I've started writing a vi and pretty much got it doing what I want, but I want to make a few improvements and I'm not sure about how to go about it.

Part of my vi is attached. This loop takes data from an array where the user can specify which columns are passed to the loop. There is a bottle neck in initially passing the data to the loop as there is a sub vi which does some array maniupalation to put the data in a form suitable for plotting. So what I would like to do is to be able to simply load the data then have the user be able to clear the graph and replot various columns against one another without having to load all the data again.

There are some further things I would like to do, but a little less essential at the minute:

1. How do I vary the timing of the loop? One of the columns in my data is time, I have done a little routine to get the difference between each time (roughly 25 ms hence the delay of 25 ms in the loop) however when I try to delay each point by the 'real-time' delay I think all that is happening is that the loop is running right through with the first delay, then with the second delay etc. etc. Hope this bit makes sense :unsure:

2. A density map. This data is time and location, what method would I use to make a plot of how long our tracer spends in each location over the course of a run? I have a rough idea that I would need to make a 2D array where each value corresponds to a location then loop through the location data and populate my array. Not sure what the best way to go about this would be though.

Anyways, any help appreciated :)

As far as number 1, the only way to vary the timing of that loop is to wire a control to the timer rather than a constant, or send a number to it programmatically. For example, the loop iteration (i) can be used with a scaler and fed to the timer. If you already know that stuff, then I probably didn't understand your question.

As far as number two, I can't tell what's happening from just the screenshot.

Link to post

QUOTE (BrokenArrow @ Mar 10 2008, 10:42 PM)

As far as number 1, the only way to vary the timing of that loop is to wire a control to the timer rather than a constant, or send a number to it programmatically. For example, the loop iteration (i) can be used with a scaler and fed to the timer. If you already know that stuff, then I probably didn't understand your question.

As far as number two, I can't tell what's happening from just the screenshot.

Cheers.

The answer to no. 1 is absolutely obvious now you've said it. I can have an array of time steps inside the loop and index it using the loop iteration. I was trying to feed the time steps in from an array outside the loop.

The 2nd one isn't really related to the screenshot. What I'm really looking for is ideas for a reasonably efficient algorithm. The application I have is following a radioactive tracer particle inside a chemical reactor. So the data I have is time and location data. What I want to do is build up a picture of where our tracer spends the most time so I need to build up a density map from the location data.

I have the bare bones of what I think I need to do: Initialise an array where each value corresponds to a location, so say my reactor is square with 9 possible locations ofr the particle, initialise a 3x3 array. Then loop through the location data at each time step and work out the location, then increment the corresponding value in the array by one.

In reality I'm tracking the particle to an accuracy of 1mm in a 100x100x100 mm reactor. I could take locations of say 5 mm^2, so initialise a 20x20 array to represent my reactor (in 2D for the minute). The only way I can think of to populate the initialised array is then to loop through the data and use a case structure to decide which value in the initialised array to increment. But in a 20x20 array there's 400 possible locations, so I'll need 400 cases. Doable, but not pretty.

Surely there must be a mnore elegant way to do it. :unsure:

Link to post

QUOTE (mcguirpa @ Mar 11 2008, 06:04 AM)

...... But in a 20x20 array there's 400 possible locations, so I'll need 400 cases. Doable, but not pretty.....

If you can provide code I (or someone) can likely help, but you might have to make the executive decision that doing it the ugly way gets the job done, and that by the time you get to the elegant solution, they've got your job on Monster. I'm positive that there's a better way to do it, but as you know, 400 cases involving insert into array or replace array subset (better) is a cakewalk for a Pentium processor. But your code will be ugly and hard to maintain.

Just heed this: Under almost not curcumstances should you build arrays of unknown size in loops.

Link to post

If I understand you right, there *is* a more elegant method that's pretty simple. Simply use computed indices to determine which array element to increment. Supposing you wanted to locate within a 5mm x 5mm x 5mm cube, you'd simply divide the actual x,y,z location by 5 mm to produce integer (i,j,k) indices that range from 0 to 19. Then extract the (i,j,k) element, increment the value, and use "Replace Array Subset" to put it back in the (i,j,k) location.

Sorry, don't have LV near my network PC or I'd post a screenshot to illustrate.

-Kevin P.

Link to post

QUOTE (Kevin P @ Mar 11 2008, 02:45 PM)

If I understand you right, there *is* a more elegant method that's pretty simple. Simply use computed indices to determine which array element to increment. Supposing you wanted to locate within a 5mm x 5mm x 5mm cube, you'd simply divide the actual x,y,z location by 5 mm to produce integer (i,j,k) indices that range from 0 to 19. Then extract the (i,j,k) element, increment the value, and use "Replace Array Subset" to put it back in the (i,j,k) location.

Sorry, don't have LV near my network PC or I'd post a screenshot to illustrate.

-Kevin P.

That's it isn't it?

Sometimes all it takes is a gentle nudge in the right direction :worship:

Thinking about it in a different way: If I had a resolution 1mm x 1mm then my location would be the same as the index in the array I wanted to populate (assuming I rounded all the data to the nearest mm and normalised it all to a suitable zero). So If I want to change the resolution all I need to do is normalise the data to a suitable starting point by subtracting a constant (essentially making the top left position = 0,0) then divide each value by my resolution to give me the index of the value in the population density array I need to increment.

Many, many thanks!

***

With regards to my initial query about keeping a VI running while i played with the data and not having to load the data again, I sorted that out with a while loop.

But I now have a related question:

Once you stop a while loop and pass the data out of it how do you make it run again?

The VI i've posted below opens a file, plots the data then lets me choose the timescale and select the data I want to keep. As soon as I stop the loops where i choose the timescale and select the data then the data is saved and the VI stops.

How do I keep it running so I can make a different selection of data?

As it is, it's ok for a run where I use one tracer, but it's not inconceivable that I could put numerous tracers through the reactor one at a time and save all the data to the same file (saving data for each tracer seperately at the time of the run is not an option unfortunately). I would then need to look at the plot, select the data corresponding to the first tracer, save to a file, then select the data for the 2nd and save again etc. How would I do this? I've tried using while loops in various ways but I can't get it to do what I want.

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.