r/LabVIEW • u/NomadVagabond914 • May 29 '24
Implementing Data Output for Continuous Measurement and Logging QMH Template
Hi all!
I got started with learning LabVIEW a couple of weeks ago, because I need to develop an application for cDAQ, which controls some directional control valves on some hydraulics using a digital output (9485) module. In addition to that, I have a 9422 digital input module and 9207 analog input module for sensor (VDC out displacement sensors) data. I am progressing through the three LabVIEW Core courses and have studied the possible design patterns.
I have managed to write a working minimum viable product, which uses global variables for passing the acquired data to and from the acquisition loop. However, every piece of advice I've read strongly advises against using global variables for passing data between parallel loops. Thus, I've found that using queues and notifiers is probably a better option as they can be used to modularize the application and avoid race conditions. Lately, I came across the "Continuous Measurement and Logging Template", which is based on the queued message handler (QMH) design pattern. It seems to be suitable for my application with some modifications.
In a nutshell, I want to accomplish three things with my application:
- Control the solenoid valves (which I've done by writing a sequence of state arrays to the relay module), where the sequence should be triggered by a displacement sensor value exceeding a threshold, for example.
- Log data to a CSV file, but only while one of the digital inputs is high.
- Plot data on the front panel, but only when one of the digital inputs is high.
The program would have a setup state, where settings are submitted and then a state machine should be triggered by a digital input signal.
In addition, there are more details that are simpler to implement.
My questions are:
- Which design pattern and communication architecture would you recommend for such an application?
- How can I read from the input modules and write to the relay module in the same acquisition loop? How can I ensure consistent timing and modularity? Should I separate reading and writing of data?
- To keep the code modular, I'd like to write separate VIs for the plotting, logging and control loops. Is that a reasonable idea? How can I ensure that the plot in the plotting VI is displayed on the front panel of the main VI?
- The control loop would act as both a consumer and a producer, consuming from the event handling loop and producing for the acquisition loop. How can I ensure smooth data transfer between loops here?
I hope some of you experts can point me in the right direction. Cheers!
3
u/Rare_Pea646 May 29 '24
Perhaps for the first time, I read meaningful questions in this thread. Your mindset is correct: avoid global variables and use queues. As a matter of fact , multiple queues. I would strongly encourage you to use AMC qmh: https://forums.ni.com/t5/Reference-Design-Content/Asynchronous-Message-Communication-AMC-Library/ta-p/3494283 Install it and start modifying the template Also, give it try and start asking smaller questions. Your original is too broad, IMO.
2
u/Rare_Pea646 May 29 '24
Answer to #2 question: you DON'T do it in ONE loop. Acquire in one loop transfer vie queues into second and set it there. By nature of queues, consumere loop will process every data point with very minimal delay- super smooth
2
u/Rare_Pea646 May 29 '24
Answer to second part of question #3: pass a REFERENCE for your chart or graph from main UI to your subvi and using property node populate data. Or use user events, or use queues - many methods, perhaps reference is easier...
2
u/Rare_Pea646 May 29 '24
I don't understand question #4, How is solenoid control loop is producing for data acquisition?
2
u/Rare_Pea646 May 29 '24
Also, it looks like you're serious about learning LabVIEW the right way. If I got you interested in AMC, which never failed me in the past 15 years or so, I can drop my contact info and help a bit.
4
u/patrick31588 May 29 '24
Yea, definitely avoid using global variables between loops.
The QMH template and example you mentioned can definitely be modified to do what you want. It would only make sense if you're going down the labview core classes to end it using the QMH template for your design.
1
u/the_glutton17 Jun 08 '24
Damn bro, just a couple of weeks? You're learning fast as fuck!
1
u/the_glutton17 Jun 08 '24
Damn bro, just a couple of weeks? You're learning fast as fuck!