LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Leaving constant for control only?

Highlighted

Hi all,

 

There is a portion of my code that requires a 10x10 2d matrix constant.  Instead of using a constant, I just use a control, put the values that I need into the control, and set the values as default.  I do this because it is clearer, since the front panel has more space (relative to the block diagram), the control values are more clearly shown.  Constant on block diagram takes too much space, and it is not clear. 

 

Is there a problem with doing that?  Why would people use constant on block diagram anyway?  When we need to use a constant on the block diagram, can we just use a control instead?  What is the advantage for each? 

 

Can I leave constant forever?

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 14
(967 Views)
Highlighted

Nothing particularly wrong with doing that.

 

I myself, don't like the idea of having hidden controls (or controls that are off the edges of the front panel).  It just makes more trouble to try to track them down when trying to adjust or debug them during programming.

 

Another idea you could use (and I like doing this for clusters because they take up more space than arrays) is to create a simple subVI that contains the constant on its block diagram and just has a single about of that constant wired to an indicator.  So you use the subVI on the block diagram as your "constant".  This gives you the opportunity to give it a descriptive icon, even a smaller icon if you use transparency around the edges, and also can protect the constant from accidental changes since it is in a subVI that you would only open if you intend to change something.

Message 2 of 14
(962 Views)
Highlighted

When your program has more outputs to show in the front panel like some waveform graphs, charts and more number of indicators then instead of using more controls (unless otherwise needed), it is better to use constants thereby you can have all the things visible in a single screen in the front panel. Like Ravens mentioned try to use Sub-Vis.

0 Kudos
Message 3 of 14
(961 Views)
Highlighted

Small experiment and I don't have LV in front of me to test.

 

Wire an Array control to a For Loop, do some operation say +1 on each element and wire out to build a new array.

Copy the For Loop and wire a constant instead of the control to the for loop.

 

Go to Options -> Block Diagram -> Select Show Constant Folding (if not already doing this).

 

Change to Run Mode and back and look for fuzzy lines on the BD.  If memory serves you will see a fuzzy wire on the constant but not the control.  This is constant folding and lets the compiler perform numerous enhancements to make the code run much faster.  This is why I use constants, you can shrink them down quite a bit. 

Message 4 of 14
(959 Views)
Highlighted

Hi Darin,

 

Can you explain constant folding?  I am not sure I am following you.

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 14
(940 Views)
Highlighted

Another good idea into my thinking box.   Thx!

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 6 of 14
(939 Views)
Highlighted

jyang72211 wrote:

Hi Darin,

 

Can you explain constant folding?  I am not sure I am following you.

 

Yik


 

Let's say you have a couple of constants where you do some math on them before you use them.  LabVIEW, seeing that the values will never change since they are constants, will do the math and save the result at compile time and use that, rather then saving all the individual constants and performing all the math operations during run time thus making the code more efficient.  If the constant is a control, then LabVIEW can't make that optimization at compile time because it will recognize that value could change at anytime during run time since it is in a user control.
Message 7 of 14
(937 Views)
Highlighted

jyang72211 wrote:

Hi Darin,

 

Can you explain constant folding?  I am not sure I am following you.

 

Yik


Ravens Fan pretty well summed it up, you might also check out
http://decibel.ni.com/content/docs/DOC-4713 

 

Message 8 of 14
(927 Views)
Highlighted
good read.
------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 9 of 14
(898 Views)
Highlighted

I think you could be using more memory that if it was a constant since it will have to return the data you want and maintain its default. Yes your array is small so this is trivial in this case.

 

Next,

 

WHen you turn it into a exe, you will have to include the FP on that VI otherwise the FP and the dfault data may be stipped possibly rendering the sub-VI non-functional as an exe without special atention.

 

Advantage ?

 

I have seen code that can be morphed into other languages by using off-screen hidden controls not on the icon connector to provide the required strings. Before the app runs, VI serve can go through and write all of the off-screen control with the right text for the target language and at run time the strings come from thos controls. To do the same thing using BD constants, would require scripting.

 

So I guess its OK if you are aware of the pit-falls.

 

Take care,

 

Ben

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 10 of 14
(892 Views)