LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to time and relay commands and value-signaling to sub-VI

Hi LabView Experts,

 

my question is basically how I can control a fairly complex VI (which has become too cluttered with controls and displays) from a designated UI-VI. This also requires some automation i.e. by setting a protocol in the UI which then executes step by step.

 

More specifically I am trying to control 1) a humidity sensor, 2) a set of mass flow controllers and 3) a Keithley source meter,

all at the same time, to do measurements at a specific relative humidity.


Therefore, I have created a VI (let's call it control-VI) that allows the user to

  • get a single reading from the humidity sensor by pressing a button,
  • set the flow of the controllers to a specified value,
  • specify a relative humidity and have the program reach it automatically using a PID loop (this uses function 1) and 2) during execution by value signaling the corresponding buttons) and
  • do a resistance measurement using the Keithley.

This part seems to work as intended. Using the UI-VI, I want to be able to control long measurements. A typical measurement could look something like this (for now ignoring the Keithley for simplicity):

  1. go to 10% rH and hold for 2 hours
  2. ramp from 10% to 50% rH over the duration of 1 hour
  3. hold at 50% rH for 1 hour
  4. go to 90% rH and hold for 2 hours
  5. go to 0%, then switch off

This outputs an array of parameters which should be used as input for the control-VI.
Example: To execute step 1, I need to tell the control VI the humidity setpoint (i.e. 10%), then press the "Go to Humidity" button on it's front panel. It will then automatically reach 0% and keep running until "Go to Humidity" is turned off again. Therefore I need to get the current rH value as feedback to know when to start the timer, once the target is reached wait for the specified time and after that go to step 2. (Flow can now stay on continuously as any change to the humidity setpoint will value-signal to set the new parameters on the control unit).
During the sequence, the recording of data (t, rH, T, dry flow, wet flow) should be continuous (e.g. 1 Data point per second). The next step can only be read once the current step is completed as the user may make adjustments while a step is in queue. Also, the total number of steps may change while the procedure is running (delete step in queue or append new step).

 

I'm struggling with how to use my array of parameters as input to the control-VI and also with everything that includes timing.

 

I've been teaching myself, mostly, so I've probably done some stuff you will tell me to 'NEVER do that' - please be kind, tell me why and I'll try to improve 🙂 VIs are attached but as I said fairly complex, so I added annotations in the top left corner of while loops to explain which is which. If someone is willing to help I am happy to go more into detail. Using version 2020/SP1

 

Cheers!

Download All
0 Kudos
Message 1 of 5
(1,519 Views)

Hi MaWi,

 


@MaWi711 wrote:

I've been teaching myself, mostly, so I've probably done some stuff you will tell me to 'NEVER do that' - please be kind, tell me why and I'll try to improve 🙂 VIs are attached but as I said fairly complex, so I added annotations in the top left corner of while loops to explain which is which. If someone is willing to help I am happy to go more into detail.


Please do some of those Training resources at the top of the LabVIEW board (again)!

 

Especially look at:

  • avoiding local variables, especially when the terminals of frontpanel elements are unused in the block diagram!
  • avoiding local variables by using shift registers!
  • learning about "best practices" for using event structures! Most of your loops can be simplified into just one loop, with one event structure with more event cases. Most often you don't need a case structure next to the event structure as you can execute to code in those cases directly in the event cases!

As the code is right now I wouldn't try to implement even more functionality. I recommend to step back and start over with some more thoughts about the algorithms and programming schemes you want to implement…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(1,494 Views)

Hi Gerd,

thank you for your reply. I did take a couple days to read some of the resources again. However, before I make an effort to simplify my project a few questions remain:

 

Can "hiding" front panel elements in nested loops cause problems? If they need to be read from multiple loops, in which should I put the element itself (and local variables for the rest)?

 

When I started this project I also didn't know about shift registers but I can see now how some local variables and even front panel elements could be replaced by them. Thanks for the hint. Apart from needing memory, is there a reason not to use local variables? In some cases, like the stop button, I can't avoid it because every loop also needs to stop executing when stop is pressed.

 

When I first started, I was taught that event structures should only be used to output numbers which are then handled by case structures, i.e. "never put any more complex functionality in there". You're now saying the opposite. So how can I tell if it is ok to put something in the event structure directly?

 

Kind regards!

0 Kudos
Message 3 of 5
(1,459 Views)

@MaWi711 wrote:

 

When I first started, I was taught that event structures should only be used to output numbers which are then handled by case structures, i.e. "never put any more complex functionality in there". You're now saying the opposite. So how can I tell if it is ok to put something in the event structure directly?

 


Oh my... Whomever told you that was just wrong on so many levels.

 

Unless you are using a more complex architecture that has a separate GUI loop, each case in an event structure should contain all of the code that is to be ran when that event occurs.

 

You have to think a little differently when programming "event based" architectures then when programming a linear polling architecture. I know when you first start out the Event Structure seems to hold little code fragments instead of a cohesive block diagram, but that's not really what's going on...

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 5
(1,447 Views)

I can't open your vis because I'm still on LabVIEW 2019 but I wanted to respond to a couple of your comments.

 


@MaWi711 wrote:

 

Can "hiding" front panel elements in nested loops cause problems? If they need to be read from multiple loops, in which should I put the element itself (and local variables for the rest)?

 

When I started this project I also didn't know about shift registers but I can see now how some local variables and even front panel elements could be replaced by them. Thanks for the hint. Apart from needing memory, is there a reason not to use local variables? In some cases, like the stop button, I can't avoid it because every loop also needs to stop executing when stop is pressed.

I would not "hide" front panel elements in nested loops. It sounds like you really don't have an architecture. When you have multiple loops it is generally a good idea to have one loop that handles all of the UI interaction and some type of approach to send the information in an organized way to the other loops. I generally use queues. Others utilize channel wires. Local variables can be used, but you need to keep in mind that race conditions may occur. You might, for instance, get one more loop on some loops than on others if you use a local variable for your stop button because of when the local variable is read. While there are some instances where Local Variables are OK I recommend that you take great measures to avoid them when you're new to LabVIEW. You'll soon find that you rarely, if ever, really need them.

 


@MaWi711 wrote:

 

When I first started, I was taught that event structures should only be used to output numbers which are then handled by case structures, i.e. "never put any more complex functionality in there". You're now saying the opposite. So how can I tell if it is ok to put something in the event structure directly?


It is generally not a good idea to put code inside your event structure that is going to take a long time to execute. That's probably what was meant by "never put any more complex functionality in there". My recommendation or long actions is to react to the UI interaction and send the appropriate information to the loop(s) that need it. This leaves your UI open for more interaction while your process is running. You don't, for instance, want to put the code to wait for 2 hours inside your event loop, essentially locking your front panel for two hours. 

 

I would recommend looking up queued message handler (QMH) on this board (include DQMH and even as a variation CMH) for ideas on how you might communicate between the loops. Once you've got that figured out putting the code into subvis that communicate with the main vi is a piece of cake!

 

 

0 Kudos
Message 5 of 5
(1,438 Views)