LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

change value during while loop of subvi

Hi,

I´m still quite new to LabVIEW. I´ve done the Core 1 and Core 2 course to get a nice headstart but now I´m running into an issue.

I decided to look on the internet for some practice exercises and I came across the idea off the Car Wash which is an old exam exercise aswell.

I have the entire thing working apart from the pause time function. Each state of the washing program lasts a set amount of seconds. When a car is not in the correct spot a sensor should give a signal(T/F). That signal should then be used to pause the timer. The signals are switches for the test and have to be defined in a type definition. I've got a working timer with pause function in a subVI, but when I try to control the pause-button from my mainVI it either doesn't switch at all in the subVI, or it switches for the next loop.

 

Things I've tried:

-Reference -> Property Node

-Event structure in subVI

-Event structure in mainVI

-Unbundling the type definition in the subVI aswell as the mainVI

-Tried creating a global variable without succes

 

Attached are some screenshots.

The underbody is one of the washing states in which I have the subVI in which I'd like to be able to pause the timer.

 

I hope someone can help me out with a nice explanation, it's much appreciated. 🙂

Download All
0 Kudos
Message 1 of 13
(4,634 Views)

Hi dabrainz,

 

rethink your program design. THINK DATAFLOW…

 

- How should we debug using just some picture?

 

- Why do you write to a value property node (of "Indicator") to just read the very same value back from a value property node? Why not use a simple wire?

- I don't see any of your switches in the timer block diagram…

- Why do you use property nodes where a simple wire would also do ?

- What happens in your "Soap application" loop when the timer outputs a FALSE? Why is there no wait in the loop? What's the purpose of the special output tunnel mode?

 

To send values to subVIs you should prefer wires. When the subVI will block your mainVI you should either have no loops in the subVI or run it in parallel to your main loop.

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(4,622 Views)

I didn't think of zipping the files. I have 8 documents in the folder and I knew I could only add 3. That's why I only uploaded pictures.

The project is in a zip-file now. Sorry for the inconvenience.

 

-I was under the impression I had to link back the new value to the indicators, but I was wrong. Deleted the extra node for all states.

-The switches are in the cluster. As a type definition-cluster shows.

-Explained before.

-It's a condition-tunnel. So it runs as soon as the timer gives true. It waits for the true to come while it's false.

 

I put property nodes in the case structure so it would update when switched. I was under the impression it wouldn't update for the same cycle if I would just draw a wire from the type definition control to the input of the subVI.

 

I know my work doesn't really deserve a style-award, but I'm still trying to get a grasp of how to make it work at the moment.

 

A zip is in the attachment.

0 Kudos
Message 3 of 13
(4,605 Views)

Hi dabrainz,

 

It's a condition-tunnel. So it runs as soon as the timer gives true. It waits for the true to come while it's false.

Wrong.

It will not wait for any TRUE. It will either stop immediately or it will run forever (burning the CPU). THINK DATAFLOW!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 13
(4,593 Views)

I wasn't experiencing any cpu problems but nonetheless thanks for the tip. 🙂

Added wait timers to the while loops.

I'd just wish you could help me with the referring to the subVI. Up untill now it has been style issues rather than programmatic issues, because it works fine apart from the referring.

 

Edit: I don't believe the wait is necessary. It waits at the start for all the inputs to the while loop are present. The subVI doesn't give an output untill it's done with the counting so the only time there is an input to the while loop is when the subVI sends the "true"-value. Which would make the condition-tunnel pointless to be honest. But that is just my way of thinking and since I'm not that experienced in LabVIEW I might be wrong. 🙂

0 Kudos
Message 5 of 13
(4,589 Views)

I'm limited to LV2011 here right now, so you will have to wait until I get access to a different computer with LV2014 installed on…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 13
(4,586 Views)

That's okay.

I'm just getting a bit fed up with the program not working.

Sorry if it reflects in my replies.

I removed the conditional tunnels and it worked as I predicted. The while loop waits for the input from the subVI before it runs.

0 Kudos
Message 7 of 13
(4,578 Views)

I had a brief glance at your code, and, as Gerd already said, it shows a complete lack of understanding of dataflow. The  small inner while loops in the toplevel program will either run forever without any possibility of stopping or they will stop immediately, depending on the value of the boolean when the loop starts. Once the loop starts the value of the boolean in the tunnel is fixed and will never change. Since the subVI can only exit when the time has elapsed, the boolean is always true and the inner loops can be deleted without any change on program functionality. In fact the boolean output of the subVI is redundant information that is not even needed.

 

Now let's talk about the subVI:

  • Why is there a hidden stop button as an indicator? Since it cannot be operated and there is no programmatic access, it serves no function and can be deleted.
  • Why do you use value property nodes to set the elapsed time and the boolean? Since these indicators will get valid values before the subVI completes, these actions are not needed.
  • Why do you constantly re-read the cluster with each interation? Since these values are recevied at the subVI call, they can never change during the current call.
  • Why do you do all these fancy computations with start times, etc. All you need is the elpased time express VI. It will do all that internally for you already.
  • Why do you reset the elapsed time express VI with every iteration of the while loop? You should only reset it on the first iteration (do an =0 on the iteration terminal, for example).
  • You only need one instance of the elapsed time express VI. The instance before the loop is not needed.
  • You don't need to wire the error across the while loop, since it is loop invariant.
  • Overall, you have way too much and way overcomplicated code.

I only glanced at the code for a few minutes, so there are probably way more monsters crawling everywhere. 😄

0 Kudos
Message 8 of 13
(4,548 Views)

I know it's a monster. It definately doesn't deserve a style-award. I didn't know that about the subVI's and it changes a lot. 🙂

 

This is just an explanation and my way of thinking(which I know is not really good in LV yet, I've only been trying it for about 3 weeks now):

- I deleted the hidden stop button. I tried to use it in an earlier stage and hid it, no idea why.

- I used the value property nodes to reset the values of the VI everytime it's called. Now I see that the one for elapsed time is worthless since it's just an indicator. Thanks for the insight.

- Here's where's my problem. I've been trying desperately to change the value while it was running and I've been trying tons of stuff messing up both my VI's.

- I'm using te start time and the computations to be able to pause it. The express VI in LV14 doesn't have a pause function. So in order to pause it I came up with the idea of comparing two of them. With, when paused, adding more time to the start time.

- The reason I wire the errors through the loop is because the trainer at core 1 taught me to give a subVI an error in and out for dataflow managing and also passing errors.

 

I generally don't take criticism well, but I really appreciate you guys reviewing it and throwing the criticism at me. I'm not just learning more about LabVIEW, but also get more experience in having to cope with criticism. So thanks for all those things.

Beware of the monsters hiding in the closet. 😉

 

Latest updates:
- I tried using an event structure in the case structure of the state machine. Using the OldVal to a case structure in the event itself and changing the global variable that is now my switch-box. This way I could change the value of the switch to true and false and back again.

(I know it's probably another faulty way but I'm learning by falling down, a lot, at the moment. :p)

 

0 Kudos
Message 9 of 13
(4,539 Views)

You should really re-architect this as a simple state machine. You don't even need the subVI. Have a look at the design pattern templates that ship with LabVIEW. Also have a look at the solutions posted in the certification forum as well as the review comments.

 

At this point you are not ready for the CLD, but once you gain more experience, that day will come. As exercises, I would suggest to write very small programs that only demonstrate one aspect of what you are trying to do. Then explore it with debugging and execution highlighting to fully understand how dataflow works. Once you have a clear understanding of each aspect, combining the parts into a functional bigger project will be simple.

 

 

0 Kudos
Message 10 of 13
(4,532 Views)