LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Update Looping Sub Vi From Main & Run Multiple Instances

Solved!
Go to solution

Hey everyone,

 

So I want to keep my code as modular as possible so I'm designing everything ni sub VI's.

 

One of the SUB vi's consists of continously polling incase a different output is detected. I don't want to do this polling at the main level because I don't want to have a huge loop in my main.vi and don't want to worry about sending shift register valuse to my subvi for it to function.

 

Essentially I have designed this sub Vi and am now trying to continously control it from a main.vi

 

This main is simply.

 

Input Cluster --> Sub VI

Sub VI keeps looping waiting for a change to prompt it to do an action. Unfortuantely when I change the vale in main.vi the avlues in subvi don't update. I guess this makes sens, in C for example when you call afunction you need to wait until the function call is complete for it to update. Still, given that Labview is so heavily focused on making SUB vi's to pretty much do everything for you, I can't imagine labview isn't able to update these values. I've looked around and the answer seems to be global variables. I really don't want to use the because my application is going to get really large, but I'll use them if I need to.

 

Unforunately, when I tried to use my gobal variable trick, it didn't work. 

 

1. Global Var = Cluster

2. It is in both the subvi and the main VI.

3. When I run my code the global variable doesn't update on both front panels when I modify one of them. Am I doing something wrong?


 

0 Kudos
Message 1 of 9
(3,657 Views)

One more thing.

 

My application is essentially looking at controlling 4 motors simultanously. Thus I'll need 4 Sub Vi's to run at the same time. Can I simply accomplish this by not having any data linked between them and dropping them all on 1 main.vi?

 

Also, on my early question, is there antoher way to trade data between sub Vi's and main.vi when sub.vi is looping? I'd like to use that approach since i'll be callng the same SubVI 4 times which would make this global variable trick really bad.

 

0 Kudos
Message 2 of 9
(3,655 Views)

Please show us some code. Thanks.

0 Kudos
Message 3 of 9
(3,654 Views)

Here is my code.

 

Go to Full is my main.

 

It is calling on Go To Single Control.

 

Go to single control in turn just calls on a large case structure that I wanted to seperate out just to tidy things up.

 

The links between Go to Single and Go to Sub work fine. If you step through the code, you'll notice that Velocity and Acceleration do update once and then go back to being null. I don't care much for having the value still displayed as in a real application I would send the Velocity and Accel Clusters (which are in an appropriate format) straight through to RS232 via another VI I have already developped which takes in a cluster array.

 

My question is when I step through my Go to full code, the values inside Go to Single aren't being updated based on what I change in go to Full. This is because go to control is still looping. How do I get a global variable to fix that? I tried used global variables but it only updated my value the first time I hit run and not as I was running.

 

Also, I guess property nodes with references might work, but I haven't yet started to use them or references so some sample code would be nice.

 

second question.

 

Sine I'm trying to control 4 axises at the same time. I want to use 1 VI but the onyl different is a different "Address" or "Axis" is being sent. That address reference actually controls my motors (1, 2, 3, 4). The only problem is I need them all to run at the same time and I need to be able to hit Go To and have them all be running (potentially) at the same time.

 

 

0 Kudos
Message 4 of 9
(3,651 Views)

-How do I delete this extra reply?-

0 Kudos
Message 5 of 9
(3,647 Views)

After reading up some stuff on the forums. I found my answer and am now using references and property nodes.

 

Labview is kick ass.

 

I'm still having trouble figuring out how to run multiple instances at the same time. But I'll figure it out!

 

 

0 Kudos
Message 6 of 9
(3,627 Views)
Solution
Accepted by topic author pierroil

 

A few comments.

 

  • You did not include the global variable
  • If you want to run multiple instances of the subVI in parallel, it should be reentrant.
  • Since the subVI is interactive, it should be set to show the front panel when called, else there is no way to ever stop it.
  • All your while loops need small waits. They don't need to spin as fast as the CPU allows, starving all other processes.
  • "Go to Sub Control" is exceedingly complex and crawling with weird stuff like a formicarium.
    • The shift register should be initialized to avoid surprises (but you probably don't need it at all)
    • Your loop spins one too many times.
    • Avoid coercion dots, e.g. at the case structure.
    • You can replace that entire contraption with e.g. threshold array, no loop needed. (see image below).

 

Good luck!

Message 7 of 9
(3,621 Views)

Thanks for this!

 

Yeah, I don't quite know all of the labview pre built functions yet. So I just make my own contraptions and replace them as I learn new things.

 

Thanks!

 

0 Kudos
Message 8 of 9
(3,612 Views)

Hey,

 

Thanks for this. I got all the code I wanted to work today and I cleaned it up so it doesn't look like a mess anymore 🙂

 

Message 9 of 9
(3,594 Views)