01-30-2013 05:29 PM
I have been writing a program for about a week now. This project involves communicating via RS-485 to a stepper motor driver as well as a displacement sensor. Long story short I use the stepper motor to rotate a surface which gets measured with a displacement sensor. To gain some confidence in the meaurement I repeat the measurement several times, take an average, and report that value. At the click of a button this process is repeated. Here is a quick summary of what I am trying to do.
I am using a case structure in such a way that when the user clicks a button a loop initiates. This loop rotates the surface, measures it, rotates back and repeats this process five times. An array is built which contains the five measurements. I use several of these case structures so that ten of these measurements can be performed. At the end of the program I have ten, seven element arrays.
Up to this point everything is fine. Now comes the problem. When trying to write the data to a text file I have tunneled the array out of the case structure. Since the case is only true for the short time the loop is being performed the data does not persist upon the exit of the case structure. Is there a way to pass the data out of the case structure while the case is true? Maybe there is a trick for handeling the false case?
Thank you for the help. I have atached two images to maybe clear up what I am getting at.
01-30-2013 06:21 PM
It is very difficult to troubleshoot an image of a portion of a block diagram. It is usually better to post your VI.
My guess is that you should use a shift register to pass the data from one iteration to the next. The True case puts new data into the shift register. The false case is wired straight through so the old data is retained.
Lynn
01-30-2013 09:31 PM
Like Lynn said, Shift Register is the way to go. A simple example is shown.
01-30-2013 10:09 PM
Hi Lynn,
Thank you for your comment. I originally tried using a single loop with a shift register and outputted the data as an array. The problem I ran into was I could not figure out how to have the array essentially append to itself with each iteration. After struggling with that for a while I thought to myself why be fancy and just created a subvi and make 10 instances. Once all of that was figured out I ran into this problem with saving the data. Thinking back I believe I would have had the same problem moving the data out of the case structure.
Chris
01-30-2013 10:14 PM
Thank you for the idea. I played around with a shift register but ran into a problem where I could not figure out how to append the current loops array to the previous. I jut kept overwriting the array. Rather than struggle for a few days I figured I would just create a subvi and implement 10 instances. That is where I ran into this problem saving the data.
It's not elegant but aside from writing the arrays to a file I have everything working well enough. Once I am done with testing the hardware and feasibility a legitimate programmer will make a more suitable program.
01-31-2013 07:44 AM
You could use something like this. On the "build array", you have to right click and check concatenate so it'll append the data. Otherwise, it'll add dimensions to your array. Hope this helps.
01-31-2013 10:20 AM
@97sportster wrote:
Thank you for the idea. I played around with a shift register but ran into a problem where I could not figure out how to append the current loops array to the previous. I jut kept overwriting the array. Rather than struggle for a few days I figured I would just create a subvi and implement 10 instances. That is where I ran into this problem saving the data.
It's not elegant but aside from writing the arrays to a file I have everything working well enough. Once I am done with testing the hardware and feasibility a legitimate programmer will make a more suitable program.
While it might be working now from your description I would not want to inherit this code to work on it later. It is well worth your effort as well as for the sanity of the next person to work on the code to learn how to properly use shift registers and avoid kludgey implementations. You will thank yourself in the long run.
02-01-2013 12:52 PM
Thank you all for your advice. Being a new user of LV I kept going back and forth in ways to accomplish the goal. In the end I made a more respectable code using shift registers and event structures rather than copying and pasting code over an over.
Anyway, thank you.