LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I avoid using Nested Case Structure?

Solved!
Go to solution

Still new to LabVIEW. How can I improve my VI.

 

I have two conditions:

  1. Setpoint (sp) values in % or litre/hour
  2. Setpoints from a CSV file or manual entry

When the sp is in %, it can be directly connected to PID (CSV or manual entry)

When the sp is in litre/hour, m3/h, litre/sec it needs to be converted percentage values and then fed to PID.

Right now, I have everything in a case structure and the second condition is working. But I want to include 1 condition in my VI and I was trying to do this with nested case structures but I have repeat what is in it for every case.

Is there any better way to accomplish the same task.

Download All
0 Kudos
Message 1 of 7
(2,584 Views)
Solution
Accepted by topic author girish_jadhav

I'm not sure I completely understand your Question, and it was difficult to figure out what you were doing in your Block Diagram (many VIs missing, far too much detail in main VI (need more sub-VIs), but here's a guess:

  • You have a routine that works correctly when you provide data in units of percentage.  [I don't understand what you mean by CSV, though I know what a CSV file means -- are you saying that the CSV files that you are using are all in "percentage" units?  If so, I recommend dropping the mention of CSV as it only leads to (my) confusion].
  • You have data that are either in percentage, L/h, cubic M/h, or L/s.  Read the data, pass it though a VI called "Convert to Percentage" (that has an input that selects Units In).  Notice I wrote this VI which has little to do with the main task of using the data, but only formats the data so it can be used appropriately.  This isn't "nested", rather it is serialized, coming before the code that uses the data to ensure that the format of the data are appropriate.  I also recommend not having an "external Case" that says "Are these data in Percentage already?  If yes, skip this test, if no, do the conversion" -- that's adding an unnecessary test.  The Case in your Convert to Percentage sub-VI will have a "Percentage" Case element that simply passes the data through unchanged, with the other Cases doing whatever computation is warranted.

Bob Schor

0 Kudos
Message 2 of 7
(2,479 Views)
@girish_jadhav wrote:

 

Right now, I have everything in a case structure and the second condition is working.


there is no nested case structure in your .vi attached. are you talking about this section of your code?

case-structure.PNG

what is the second condition? the false case?

 


@girish_jadhav wrote:

But I want to include 1 condition in my VI 


Where do you want another condition?

I suppose you want to add another case, besides true and false?

use an enum to control the case structure instead of the "Manual (OFF)" boolean.

 


@girish_jadhav wrote:

...and I was trying to do this with nested case structures but I have repeat what is in it for every case.

Is there any better way to accomplish the same task.


what do you repeat? 

 

please be more precise with your problem description.

and don't forget to attach your subvis, you could upload a .zip

 

0 Kudos
Message 3 of 7
(2,470 Views)

Hi girish,

 


@girish_jadhav wrote:

I have two conditions:

  1. Setpoint (sp) values in % or litre/hour
  2. Setpoints from a CSV file or manual entry

When the sp is in %, it can be directly connected to PID (CSV or manual entry)

When the sp is in litre/hour, m3/h, litre/sec it needs to be converted percentage values and then fed to PID.

Right now, I have everything in a case structure and the second condition is working. But I want to include 1 condition in my VI 


When you have two conditions then why do you only want 1 condition??? You really need to explain this…

 

Why is there a wait in your while loop and an additional wait inside the FOR loop?

Why is there a FOR loop calling your PID (?) subVI twice per iteration of the while loop?

Why do you need to read the CSV file in each iteration of the while loop? Why don't you read that file once before the loop?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 7
(2,423 Views)
@Bob_Schor wrote: [I don't understand what you mean by CSV, though I know what a CSV file means -- are you saying that the CSV files that you are using are all in "percentage" units?  If so, I recommend dropping the mention of CSV as it only leads to (my) confusion].

Sorry for being unclear. Right now, the values are in percentage but I would also like to have an option to read data in other units and convert them to percentage before connecting to PID input. 

 


@Bob_Schor wrote: You have data that are either in percentage, L/h, cubic M/h, or L/s.  Read the data, pass it though a VI called "Convert to Percentage" (that has an input that selects Units In).  Notice I wrote this VI which has little to do with the main task of using the data, but only formats the data so it can be used appropriately. 

And this can be achieved with enum data type? I will add the zip file which contains all other sub-VIs necessary.

0 Kudos
Message 5 of 7
(2,412 Views)

Hello Bob,

 

I used the enum and it worked. Thanks for the help 🙂

 

I have one more question: I tried to include this in a sub-VI as you suggested, but since there were some indicators and control elements present, I got a pop-up message saying that it might not work as expected. Do I need to neglect this message? Because the VI was working as expected, I thought this wouldn't be an issue in the future. 

0 Kudos
Message 6 of 7
(2,339 Views)

> are you talking about this section of your code?

 

Thanks for reading my post. Yes, I was referring to this part of the code. 

 

> what is the second condition? the false case?

 

I thought I would first check if the data I am reading is in percentage or other units (this being the first true/false condition) and then give the option to enter the data manually or from an excel sheet (also true/false condition). This line of thought caused a lot of confusion as I didn't know how to handle this. One solution that came to my mind was using nested case structures. 

 

But as you and Bob suggested, I used enum and got my VI working. 

 

Thanks for the help 🙂

 

 

 

 

0 Kudos
Message 7 of 7
(2,332 Views)