LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C like structures in Labview

I'm programming a motor control application based off some C example code. In the C code there is a structure containing motor profile constants (max speed, slope, limit) and varibles (current_postion, status). I have created a cluster of numeric controls for the constants so I can easily pass it to each sub-vi. However I would like to include variables in this cluster such as current postion. So far it looks like clusters cannot mix controls and indicators. Is there a way to define a numeric control (ex. current_position=0) in a cluster, then have a sub-vi change the value of the control so I can pass along the same cluster to the next vi? I suppose it could be converted into an array however I would still like the current_postion
control to be updated on the control panel.
Thanks,
Lou
0 Kudos
Message 1 of 6
(3,150 Views)
You can modify any single element in a cluster. Wire the cluster into the Bundle By Name function (the input cluster connection) and then select the element you want to modify by right clicking the element input and choosing Select Item. You can also expand the function to have as many elements as you want. The attached picture should give you the general idea.
Message 2 of 6
(3,150 Views)
You're correct that you can only have either Controls or Indicators in a cluster.

You can operate on individual cluster elements regardless of which type (control or indicator) they are initially.

Define your cluster with all the elements you need, pass this into your sub-vi and use either the �Bundle� or �Bundle by Name� function to write new data into the element.

Bundle by Name will let you select which and how many of the cluster elements you want to write to. If you use the Bundle function, you must connect a value to each of the cluster elements on the function. So the Bundle by Name is usually the better way to go.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 3 of 6
(3,150 Views)
Thanks Guys,
I see how the undbundle function works. Once the position value is modified is there a way to feed it back into the cluster so the control panel is updated and the new position value is used on the next run?
Download All
0 Kudos
Message 4 of 6
(3,150 Views)
This is usually done with a shift register if the modification is done inside of a while or for loop that is continuously running the program. I've attached a modification of your VI that shows this and also it writes to a local variable so that the modifications are visible to the user. I also stuck in an Unbundle By Name to show how you can use that to retrieve a single value from a cluster.
0 Kudos
Message 5 of 6
(3,150 Views)
Thats exactly what I was looking for! Accessing the cluster as a local or global variable allows read and write, similar to a structure in C.
Thanks,
Lou
0 Kudos
Message 6 of 6
(3,150 Views)