取消
显示结果 
搜索替代 
您的意思是: 

Update value on boolean change

已解决!
转到解答

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 项奖励
1 条消息(共 10 条)
7,339 次查看

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

2 条消息(共 10 条)
7,315 次查看

@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 项奖励
3 条消息(共 10 条)
7,309 次查看

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 项奖励
4 条消息(共 10 条)
7,300 次查看

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 项奖励
5 条消息(共 10 条)
7,295 次查看

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 项奖励
6 条消息(共 10 条)
7,290 次查看
解答
接受人 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

7 条消息(共 10 条)
7,284 次查看
解答
接受人 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)

 

 

8 条消息(共 10 条)
7,275 次查看

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 项奖励
9 条消息(共 10 条)
7,268 次查看

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

0 项奖励
10 条消息(共 10 条)
7,264 次查看