LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving Array Everytime a "Zero" Button is Pressed

I am using the DAQ Assistant to measure strain using some strain gauges. I would like to have the program zero out the null strain data once I press a "Zero" button (because the strain gauges always read some null strain at the beginning), and keep using that saved data to cancel out the null values for the rest of the time. I am having some issues with saving the data into an array once I press the button. I have tried shift registers, event structures, and case structures to no avail. I would really appreciate any help I can get!

 

Thanks!

(I would like to subtract the data after it goes through the Mathscript Node and out of the For Loop. You can see where I tried to do this with the subtract function and a case structure.) 

0 Kudos
Message 1 of 6
(947 Views)

Huh? I don't think I fully understood what you want to do, could you please elaborate a bit more? When you say "zero out" what exactly do you mean? Reset the array to empty? Fill it with zeroes? If you're having issues with saving the array, have you considered using a Functional Global Variable? (or action engine, as it is known to others).

 

The substract array function won't do you much good also, as it will work pretty much exactly like a for loop with 2 indexed tunnels. It will iterate as many times as the SMALLEST array it receives, so the max amount of points you would get, would be however many points your "zero data" contains, which I don't think is what you're after.

0 Kudos
Message 2 of 6
(898 Views)

You need to learn a little more LabVIEW (and understand the concept of Data Flow better).  Have you taken as many of the free LabVIEW Tutorials as you can find?  [Check out the LabVIEW Forum's Home Page].

  • You almost never need a Frame Sequence (you definitely do not need it in this example).  You can use the Error Line (put your "initializing" Property Node on the Error Line leading into the While Loop, then delete the Frame Sequence altogether).
  • If I understand what you want to do, you want to push a Button, and when it is pushed, take the (current? saved?) value as the "new Zero".  You save this in a Shift Register, and every number being processed from then on has this value subtracted from it (re-defining "Zero").

Do you see that there are two independent processes going on here?  One involves the DAQ Assistant taking (continuous? repetetive Finite Samples?) data, subtracting a Zero value from the samples, and doing something with it.  The second process involves recognizing that the "Zero" button has been pushed and "doing something that interacts with the first process" with this information.

 

Suppose you have an Array of numbers (let's call them "Samples") and want to subtract a constant offset (let's call this "Zero") from each of them.  A "Subtract" function will allow you to subtract a single number from an Array (many LabVIEW functions are good about that).  If you have a 2D array, you may want to write a little test VI (with data that you make up) to see what you need to do (off the top of my head, I don't remember, but I'd use the LabVIEW Help and a tiny test routine that would take about a minute to write to "teach myself").

 

What do you want to have happen when you push the "Zero" button?  One thing you could do would be to take the most recent (un-zeroed) sample, average it over the sampling (time) interval, and make that your new Zero.  This actually has some appeal, as an Average is less likely to be a "wild" value than a Sample picked at random.  It also "plays nicely" with the timing of your (separately-running) sampling loop.  Now all you need to do is to get these two loops "talking to each other".

 

NI comes to the rescue.  Start LabVIEW, click File, New ... (those dots are important), and look for the New from Templates section.  Drop down a Producer/Consumer Design Pattern (Events) and study it.  If you don't know about the Event Structure, re-read the first few sentences of this Post.

 

Bob Schor

Message 3 of 6
(872 Views)

@Daikataro wrote:

Huh? I don't think I fully understood what you want to do, could you please elaborate a bit more? When you say "zero out" what exactly do you mean? Reset the array to empty? Fill it with zeroes? If you're having issues with saving the array, have you considered using a Functional Global Variable? (or action engine, as it is known to others).

 

The substract array function won't do you much good also, as it will work pretty much exactly like a for loop with 2 indexed tunnels. It will iterate as many times as the SMALLEST array it receives, so the max amount of points you would get, would be however many points your "zero data" contains, which I don't think is what you're after.



I want to push a button, and when it is pushed, take the current value as the "new zero".  It will then save this in a shift register, and every number being processed from then on has this value subtracted from it.

0 Kudos
Message 4 of 6
(822 Views)


First of all, thanks so much for replying, I really appreciate it. I took a LabVIEW course in college a couple years ago but haven't used it too much since so I'm a little rusty. To answer some of your questions... the code I attached was a work in progress so while it was not necessary to have a Frame Sequence yet, I did eventually need to use it. Also, the DAQ Assistant is taking continuous data samples.

You seem to understand what I meant by "Zero when the button is pushed" and I do certainly like your idea about using the Average over a certain time interval. However, I am not sure whatyou mean by "getting the two loops to talk to each other". 


 

0 Kudos
Message 5 of 6
(817 Views)

@mark.comfort58 wrote:


The code I attached was a work in progress so while it was not necessary to have a Frame Sequence yet, I did eventually need to use it. Also, the DAQ Assistant is taking continuous data samples.

This is probably not the case (that you need a Frame Sequence).  Almost all NI Functions have Error In and Error Out, which means you can "serialize" them if nessary by using the Error Line (which you should be using) and not by going Frame by Frame.  Almost the only exception involves timing functions (which have no Error In/Out), but you also rarely need to "frame" them.

You seem to understand what I meant by "Zero when the button is pushed" and I do certainly like your idea about using the Average over a certain time interval. However, I am not sure whatyou mean by "getting the two loops to talk to each other". 


 


Did you look at the Producer/Consumer (Events) template that I mentioned to you?  It has two loops, an Event Loop looking at (infrequently-pressed) Front Panel Controls and a "Processing" loop that uses those controls to "do something".

 

Hmm.  I realize that there's another concept you need, that of a Queued State Machine (or the Queued Message Handler, very similar).  Basically, you want a loop that operates "on command".  If you push a button, you want the loop to execute "He pushed a button" code.  When the program starts, you want the loop to execute "Initialize" code.  When you push the "Start Sampling" button, you want to run "Start Sampling" code.  [Guess what you do when you push the Zero button?].

 

Once you start Sampling, you will want to execute some "Take a Sample" code.  Ignoring, for now, what you do with the Sample, what do you want to do next?  Well, it is almost always ... "Take a(nother) Sample".  At some point, you may push the Stop button and ... [left as an exercise for the Reader].

 

A loop that does this, doing one thing (State) at a time and at the end, either automatically doing something else (going to another State) or waiting until being told to do something, is called a State Machine.  A particularly nice version of the State Machine that incorporates inputs from Controls ("Buttons") is the Queued Message Handler (the Message Handler is the State Machine, the Queue is the mechanism for having, say, an Event Loop interact with the State Machine, and right now, your head is probably spinning.

 

There are examples in LabVIEW, both in Templates and Sample Projects.  Don't worry about all the Bells and Whistles right away -- try to understand the concept and see if you can apply it to your own task.

 

Bob Schor

0 Kudos
Message 6 of 6
(805 Views)