01-04-2010 05:06 PM
I used the Vission Assistant and created a sub vi that I use in the Vision Processing vi in the advanced framework. The VI suspensefuly finds a red Santa hat and returns information in a cluster named "Matches". From that cluster I can un-bundle it and get the X Y coordinates of the hat among other things, my question is how do I get that real-time data (cluster) over to the Autonomous Independent vi? I think I need to use Type Def's, but I have not had any luck getting them to work in two days. Any help would be greatly appreciated.
01-05-2010 07:06 AM
There are many ways to pass data between loops in LabVIEW - queues, notifiers, "functional global variables," and global variables. Global variables are generally discouraged in LabVIEW code, but here I think it may be the easiest way to solve the problem, due to the way the Autonomous Independent is structured. You'll see that global variables are already used in that framework for passing other pieces of shared information. You can add a new global variable for your data by right-clicking on any existing global variable (the ones with the little globe next to them) and choosing Find->Global Definition. That will bring up the file containing all the global variables (it's just a VI with no block diagram). Add a new control of your cluster, and you can then use that variable to pass data between your loops.
01-05-2010 08:43 AM
Hi Doug,
You should be able to use a global variable to pass data from your Vision Processing VI to the other parts of your code. You can pass values individually, but if multiple values will always be used in the same places in your code (such as x & y coordinates, and perhaps color values) then you can bundle these values together into a cluster. You can create a global variable that is defined as a cluster of the same data types, and then pass your bundled data to that global variable in the Vision Processing VI, and read out the cluster anywhere else you need to in your code.
Be careful using global variables though. While they are necessary in some situations like this, you should always pass data by wire if you are able. It's faster and makes your code easier to understand. Additionally, introducing global variables also introduces the possibilities for race conditions in your code. To avoid this pitfall, always make sure that you are only writing to your global variable in once place, though you can read from it in many locations. If you do need to update a global variable from multiple locations, you need to protect that section of code to ensure that the global variable can only be updated in a single location at any given time.
For more information on the use of local, global variables, and functional global variables, see these resources:
Best Practices For Using the FRC cRIO Project Frameworks
Joystick Button Control (Using a Functional Global Variable)
Multi-Functional Global Variable
The LabVIEW Help also has some good information on creating and using variables.
Good Luck, and let me know if you have further questions!
Best Regards,
~Nate
NI FIRST Support
01-07-2010 01:29 PM
Thank you very much for your help, a Global variable worked perfect, once I grasped the concept.