LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Update value on boolean change

Solved!
Go to solution

Hi,

 

I want to update a value on changing the setting of a boolean switch. I'm trying to use a shift register to do this, but I have no idea how to make the register only update if the boolean value changes, rather than every iteration. Can anyone help?

 

0 Kudos
Message 1 of 10
(5,038 Views)

I'm assuming you have learned almost no LabVIEW (maybe you are taking a class and have had only 2 lectures, maybe you are playing around by yourself, maybe you have viewed one Tutorial Video or taken one Tutorial Web lesson).

 

Learn a little more LabVIEW.  There are a series of Tutorials mentioned on the first page of this Forum.  Spend time with them.  Do them in order.  Pay attention if you see something that discusses the Event Structure.

 

Bob Schor

Message 2 of 10
(5,014 Views)

@jnc8mc wrote:

Hi,

 

I want to update a value on changing the setting of a boolean switch. I'm trying to use a shift register to do this, but I have no idea how to make the register only update if the boolean value changes, rather than every iteration. Can anyone help?

 


There is a value changed vim.  But, there is also a value changed event!  Can you show us how you want to respond to the user,?


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 10
(5,008 Views)

The desired behavior is a smooth transition into increasing or decreasing from the value currently displayed on the numeric.

 

I tried to use an event structure to make this happen, but my understanding of how they work is poor, even after viewing a few YouTube videos on their implementation, and reading their NI documentation.

 

The ideal thing now would be to have a structure that outputs false except when the value of "True: decrease" is changed, and outputs true to the select statement for only one tick, updating "Numeric 2". I think there is a way to do this via case structure, but as I said, I can't get them to work.

0 Kudos
Message 4 of 10
(4,999 Views)

You really need to do a few simple tutorial and exactly define the problem.

 

  • What does the indicator show at any time?
  • What values does the user enter into the "numeric 2" (please give it a useful label!) and what should happen as a result? Maybe use a chart for the output so we can see how the values change over time.
  • At what point does the user operate the boolean?

Now about your latest code. Maybe fixing the basics will get you closer to an easy solution:

 

  • You cases differ by a single primitive ("x" vs. "1-x") All shared code belongs outside the case. No need to duplicate all that code.
  • Wiring a true constant to a "stop if true" termination condition will give you exactly one iteration. Shouldn't it run longer than that? ("run continuous" is a debugging tool, not a way to run a VI)
  • There is a primitive for "+1".
  • There is a primitive for e^x.
  • Typically, a program should update indicators instead of controls. Don't fight the operator!
  • The value in your blue shift register is at all times identical to the iteration could available from [i]. You can remove all that code!
  • ...

So please explain exactly how the program should be used and what the operator should experience. Don't focus on algorithmic detais, because they might be wrong.

0 Kudos
Message 5 of 10
(4,994 Views)

I've realized that the way I'm trying to do this is totally wrong. Please ignore the VI attached to the previous post. The one attached to this post displays minimum working behavior, except for one thing - when the switch is flipped, the numeric jumps to where it would be had the VI been running with the switch in that position since the beginning. I would like a smooth transition from growth to decay and vice versa.

0 Kudos
Message 6 of 10
(4,989 Views)
Solution
Accepted by jnc8mc
  • You still have lots of duplicate code in the cases, only the "1-x vs wire" should be inside the case structure!
  • You still have not found the exponential function.

 

lessduplicatecode.png

 

 

Maybe you are looking for something like an exponetial smoothing filter (wild guess). Her's a simple example (see also)

 

ExponetialFilter.png

Message 7 of 10
(4,983 Views)
Solution
Accepted by jnc8mc

... and here's a possibility with just two states controlled by the boolean:

 

ExponetialFilter2StateInput.png

 

Note that an exponetial filter does NOT need an exponential function. An exponential is inherent to successive scaling operations. Think about it! 😄 It is left as exercise to the student how to convert from exponential time constant to the filter factor (0 ...1, fixed at 0.05 here)

 

 

Message 8 of 10
(4,974 Views)

Thank you! I see why my algorithm wasn't working, and why yours does. I apologize for my bad quality code - some of my quirky style makes it easier for me to see what is going on (although it probably makes it harder for everyone else).

 

Regardless, which a little modification, the exponential filter works wonders.

 

I think I need to redo the tutorials in the meantime...

0 Kudos
Message 9 of 10
(4,967 Views)

I am glad it helped. Good luck and success with the project! 😄

0 Kudos
Message 10 of 10
(4,963 Views)