FIRST Robotics Competition Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How can you make "instances" of a subVI in LabVIEW when it is used repeatedly?

The other programmers on my team and I would like to know how to create/use "instances" of a subVI in LabVIEW (this is the programming term that is used by the other programmers, to which I am new to). If we could have someone direct us to where we can find out about this or explain it to us personally, that would be much appreciated. Let me describe our situation to explain better.

We have implemented acceleration control and traction control on each of our 4 wheel motors. This requires that we run a joystick/encoder/constant value into a bunch of code to get our motor value. Since it's big and bulky and the same oporation for each motor, we made a subVI for this section of code. We used the "select VI" option in the palete of the block diagram to insert this subVI into our main VI four times, one subVI for each motor. But when we tried out our code, the VI was calling up the same exact subVI file four times and was running it four times at the same time. This of course caused major problems and slowed down our robot a lot. We came up with a "duct-tape-like" solution and just make four files of the subVI and named the 4 files like "subVI", "subVI_1", "subVI_2", etc. Then we just used those four subVIs individually in our program. With our traction control section, we didn't even bother making subVIs and the guys who were working on that just coped the raw code four times (yes, that part of the code is very large).

I am pretty experiened in LabVIEW but am not as familiar with programming in general, while the other two programmers on our team are very experienced with C. They explained to me how something called "making instances" of the subVI is what needs to be done, and that LabVIEW probably has that capability to do this (like C does, supposedly), but we don't know what to do to "make it happen". This would automatically make copies of a subVI if it is used multiple times in a VI and call up those, not the same subVI simultaniously.

We would appreceate if someone could tell us how to do this. It's really late in the season and our code works, but this definitely sounds like a usefull skill to have for future years and such.

Thanks so much!

0 Kudos
Message 1 of 6
(11,713 Views)

You need to enable reentrant execution in the VI properties (go to File->VI Properties, choose the Execution category, and select the Reentrant execution and preallocate clone for each instance).

On LabVIEW RT, you won't be able to debug your VI, but it sounds like that's done already, so that should be all you have to do.

This might satisfy more the the computer science behind it: http://wiki.lavag.org/Reentrant_VI

0 Kudos
Message 2 of 6
(2,909 Views)

If you really need to be able to debug it, you can create a copy with a different name.

Stephen B
0 Kudos
Message 3 of 6
(2,909 Views)

In addition, KnowledgeBase 2QKDG7DW: Differences Between Reentrant VIs (Preallocate), Reentrant VIs (Share Clones... also has some useful information.

Ben

National Instruments
Certified LabVIEW Associate Developer
Certified TestStand Developer
0 Kudos
Message 4 of 6
(2,909 Views)

Thanks everyone, that was helpful. Thanks for the links on this topic.

Stephen, could you explain more? That sounds helpfull.

0 Kudos
Message 5 of 6
(2,909 Views)

Sure. Instead of making the VI in question reentrant, you could do a save as and name it something else like MyAnalysis1.vi and MyAnalysis2.vi. Then in your calling VI, call one in one spot and the other in another spot. Since they are separate VIs, they are separate instances like you wanted... and you can still debug them.

Reentrant is more efficient and easier to do, but you lose the ability to debug on RT targets like the cRIO.

Stephen B
0 Kudos
Message 6 of 6
(2,909 Views)