Log in

View Full Version : Making two instances of a sub-vi run independently of each other?


Chaos in a Can
18-01-2009, 11:39
I wrote a rate limiting vi in LabVIEW that takes an input and maximum rate of change value and outputs a value that moves towards the input but changes no faster than the maximum rate.
To simplify the number of wires running to and from the vi, the vi remembers when it was last run and what its output value was by storing those values in a couple of indicators. Those indicators are not connected to terminals.

The problem arises when two or more of these are running at the same time in a program:
What I want to happen, is each instance of the vi should run independently of the others, with independent timers and last output values.
What actually happens, is each instance of the vi in the program calls the same function, so all of the vi's share the same timer and last output value.

This means that if I apply rate limiting seperately to the left and right wheels for tank style controls, whichever side executes first runs mostly normally, but when the rate limiter for the second side runs, the delta time is only a couple milliseconds--the time from the execution of the first side, not the time from the last iteration of the program. Also, what the program thinks is the last speed value for each side is actually the last value of the opposite side.

Short of duplicating the vi file for each instance in a program, is there any way to make multiple instances of a sub-vi run independently of each other?

Greg McKaskle
18-01-2009, 13:06
Short of duplicating the vi file for each instance in a program, is there any way to make multiple instances of a sub-vi run independently of each other?

Absolutely. Bring up the VI Properties dialog by right clicking on the icon in the upper right or finding it in the menus. On the Execution tab, make the VI reentrant. Reentrant VIs run independently, whereas a nonreentrant VI is intentionally protected. The only tradeoff here is that debugging of the VI will get a bit more limited.

Greg McKaskle

Chaos in a Can
18-01-2009, 13:23
I think I may have superpowers. If I ask a question on a forum, I will almost inevitably find the answer just before a response is given. :yikes:

After asking, I continued searching through LabVIEW and found that option.
Thanks for the help though.

Greg McKaskle
18-01-2009, 17:11
No harm. Glad you found it and understood it.

Greg McKaskle