06-02-2016 11:29 PM - edited 06-02-2016 11:32 PM
I regret to tell you your code is a mess! You seem to be ignoring the patterns in what you are doing -- instead of saying "I'm doing 10 channels worth of things" and handling an array of (essentially identical) tasks, you are doing them one at a time, with wires and code running all over the place. You are using the DAQ Assistant which makes it impossible (well, no, just Extremely Difficult) to tell whether you are Reading or Writing, doing 1 Channel or 20 Channels, taking 1 point or 1000 points, and are using Dynamic Wires which have their own Obscuring Features.
So forget about the code! Think about what do you want to do. Let me give it a try -- I'll probably get some of the details wrong, but that's OK because you can correct me ...
So the above description is for a single Channel. You now say "We run 10 Chambers simultaneously". At this point, you should be thinking "Aha, I know how to do this for one, so for 10, I just build an Array of 10 "things" and run them through a For loop to access the individual Array elements". In the case of DAQmx, you define your DAQ Task (you did read that article I pointed you to, didn't you?) to set up the 10 A/D input channels, configure the DAQmx Read as N Channels (which gives you an array of data with an index corresponding to your channels) and pass your Array of Data through a For Loop to process each Channel identically. The output of this process will be a decision to Open or Close a Channel-appropriate Valve, which is another DAQmx Task, presumably for a multi-line (or is it multi-port? I get mixed up with DIO) Digital Out device, so you would have an Array of Booleans to drive the DAQmx Write.
The block diagram for this VI should only be slightly larger than the size of the box I'm typing this Reply into, particularly if you use a few sub-VIs to handle some of the more "boring" functions. What do you need? A Configure DAQmx (Analog In Task) to define the 10 AI channels, Configure DAQmx (Digital Out Task) for 10 DO channels, both going into a While loop where a DAQmx Read gets an array of data from the 10 Channels, "processes it" (a wonderful place to "hide the details" in a sub-VI) to produce an Array of Booleans that goes to ... the DAQmx Write to set the Valves, with a Stop Button wired to the While Stop indicator. This skips saving the data (a detail that can be added later, or you could even do it within the same loop, just open the file before entering the loop and write one set of data each "loop"). Since your loop runs so slowly (1/sec), this should be a piece of cake to code and "keep up".
Bob Schor
P.S. -- if your next posted code uses the DAQ Assistant and Dynamic Wires, I promise not to make any more comments, since I'll know you aren't serious about learning how to improve.
06-03-2016 11:38 AM
Bob,
Thanks a lot for taking the time guiding me. I am going to work on it and get back here soon.
Regards,
Sia
06-05-2016 03:49 PM
Here is what my task is:
I tried learning some DAQmx functions and wrote the attached VI (for some reason it takes me a long time to learn these, could be the fact that I am a civil engineering student and not really used to programming).
Since all my valves are not doing the same thing, it seems to be challenging to write a For loop. Instead, I am thinking of passing a 15-element boolean array to control the valves. However, I still have problem writing the condition (how to write "if pressure was lower than X for 5 seconds" and how to control the valves (update the array) accordingly. Any help would be highly appreciated.
Regards,
Siavash
06-06-2016 09:30 AM
Without reading your post but looking at your code:
Why don't you take a look into the DAQmx examples you can find in the Example Finder? They answer your question/issue on how to configure a continuous acquisition/generation without DAQmx Assistant.
Also learn about queues and improved design patterns like Producer/Consumer.
These are they key for you to generate a working solution.
Norbert
06-06-2016 04:52 PM
There is a lot that I just don't get about this setup, but if it is clear to you, then OK. Here is a suggestion to help you (and help us).
FORGET ABOUT 5 CHANNELS! Let's try to figure out how to do a single Test Chamber.
You describe (a) Test Chamber with its valve open (which I presume means "Connected to a Pressure Source") and then say "until failure". Why are you mentioning this? Does it play a role in your tests?
You describe (another) Test Chamber with two valves. One I presume is connected to a Pressure Source, the other is an "exhaust" (connected to nothing). At any time, only one is on, and you switch back and forth at one second intervals. So if the Pressure Source level is P, and if we assume that the pressure rises and falls "very quickly" in the Chamber, then the Pressure will be a Square Wave that is 0 for one second, P for one second, 0, P, 0, P, etc. Is this correct?
You describe measuring the pressure in the Test Chamber at 5 Hz. Is the timing synchronized in any way with the 1-second on/off of the valves? If they are synchronized, and if the pressure rises and falls rapidly, the sensor should measure 0 0 0 0 0 P P P P P 0 0 0 0 0 P P P P P etc. (Not very interesting).
You talk about the pressure "lower than 90% of the initial pressure" (what does this mean? What is the Initial Pressure?) for more than 5 seconds (during which time the valves have cycled at least 5 time). This makes no sense to me.
Why do you make measurements at 5 Hz? Are you interested in the time course of the pressure? When you say "the pressure is lower than 90% of the initial pressure", are you referring to a single reading? In other words, do you require 25 successive readings at 5 Hz to be below 90% of the initial pressure?
Do a Web search on "Learn 10 Functions in NI-DAQmx", read the article that it references, and fix your code (put the While loop and Stop control in the right place).
Bob Schor
06-07-2016 10:06 AM
Thanks Norbert,
I used a voltage reading example to modify my VI.
Regards,
Siavash
06-07-2016 10:33 AM
Bob,
There are two types of test chamber, as you mentioned. Here is what happens in a single chamber
Type-A: The chamber (a tube, to be precise) is kept under pressure P provided by a pump. There is only one valve before the tube. the tube bursts after a while, causing a pressure drop, this drop is captured by the transducer and the valve will be closed as a result. I would need the pressure readings to be saved in a file so that I can later on find out when the tube has failed and what has been the average pressure during that time.
Type-B: In this tube, the pressure is a Square Wave that is 0 for one second and P for one second (0,P,0.P) just like you mentioned. I want to be able to see the pressure pattern . Please see the attached picture. The curve on the right is the cyclic pressure (the cycling time is different in the picture but it is the same pattern). The reason I am not reading the pressure more frequently is that the test could be running for weeks and I don't want to end up with a huge file.
The pressure being "90% lower than the initial pressure" is what I use to assume the tube failure (shown as "Pf" in the attached picture). However, in the case of cyclic pressure, the pressure is zero during each cycle, and this should not be seen as a failure. That is why I have defined a "tf" (attached picture) and I consider it failure if the tube has a pressure lower than "Pf" for "tf" seconds.
I did a search on those 10 functions and saw a few examples and changed my VI accordingly. I am now saving the data out of the loop. I am considering it a failure if the last 5 readings (performed in 5 seconds) are lower than Pf. It is still a very busy code, and I am getting all the diagrams in a single graph which is not really working for me (I am assuming it is helping the program to run faster though). I have also attached the VI.
Sorry for the long response. I don't see any way to explain these in a shorter message.
06-07-2016 04:30 PM
Much clearer! And the pictures showing Pf and Tf also really help.
Tell me if this makes sense -- in the cyclic case, you want to detect a failure when the tube blows out, When this happens, the pressure will always stay below Pf (because there's nothing to contain the pressure).
So here's a simple way to detect a failure. Let's say that you are sampling once per second, so you will sample Tf times in Tf seconds. Simply keep a running average of the last Tf readings. You expect the average pressure to be approximately P/2 (since it will be P in half the readings and 0 in the other half). If the average is much below this, you have a failure. Note that if you have synchronized your pressure reading with Valve motion, you can do this even simpler by noting if the pressure in the middle of the "Supply Value Open" interval is near P (OK) or not (failure).
This sort of logic will greatly simplify your code, as will following my suggestion to design a simpler routine for a single station (not 5), get it working, then do a very simple operation (going from a single element to an array of 5) to handle multiple channels.
Bob Schor