LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing current and previous loops values

Hi all,
 
I have been struggling lately with my VI. I want to display the value of the Number Output indicator in the case structure to two individual indicators. However, I need one indicator to show the current value of the Number Output and the other indicator to show the previous value of the Number output every time the Take Image button is pressed. I can't figure out how to use shift registers to do this. Any help is much appreciated.
 
I will want to use these two values later on for a comparison operation which will then send a signal to an external device.
 
Please see the VI to better understand what I am trying to achieve.
 
Thanks in advance,
 
JLM

0 Kudos
Message 1 of 12
(4,154 Views)

You need two new shift registers.

 

In the case structure, either wire both the shift registers through the case. Both values are retained when the button is not pressed. If the button is pressed, put the 1st (current) value in the 2nd (old) output\shift register. Wire the new number to the 1st output\shift register.

 

Alternatively, and less code but a bit harder, you can use a feedback node. The feedback node has an (optional) enable Boolean input. Normal shift registers are always enabled. So you can wire the Boolean to a feedback node enable, and the feedback node will keep both values.

 

Your "history" is not based on loop iterations, but on a Boolean state. That makes shift register less suitable, because they shift automatically based on loop iterations.

 

Never mind, those feedback nodes don't return more than 1 output. You can increase the delay, but it doesn't return all buffered values.

 

Old values.PNG

Message 2 of 12
(4,142 Views)

Thank you for your help! This works great for the RNG!

 

I have just tried inputting another portion of my script I have just made into the loop, however this doesn't work now. The RNG was just to simulate a number output every time the button was pressed.

 

Any suggestions?

 

Cheers,

 

JLM

0 Kudos
Message 3 of 12
(4,124 Views)

Hi all,

 

I want to display the value of the Nb Circles Output, in the case structure, to two individual indicators seen right, outside of the case structure and while loop. However, I need these two indicators to show the current value of the Nb Circles Output and the previous value of the Nb Circles Output every time the Take Image button is pressed.
 
I will want to use these two values later on for a comparison operation to signal over to an external device using serial comunication.
 
Please see the VI to better understand what I am trying to achieve
Thanks in advance,
 
JLM

0 Kudos
Message 4 of 12
(4,102 Views)

Vision Acquisition "image out" is an output, you can't wire it to IMAQ ExtractSingleColorPlane's output image. It should be wired to the input...

 

I don't have IMAQ\Vision installed, so I'm not sure what else is wrong.

 

Message 5 of 12
(4,113 Views)

Actually you can just pull down the shift register to get the previous value:

 

test.png

Tim
GHSP
0 Kudos
Message 6 of 12
(4,102 Views)

@aeastet wrote:

Actually you can just pull down the shift register to get the previous value:

 

test.png


That just won't work.

 

EDIT:

That will always shift the current value to previous value, for each iteration.

 

Goal is to store the current value, and push it to previous depending on the press of a button.

0 Kudos
Message 7 of 12
(4,081 Views)

You don't understand the most important principle of LabVIEW, the Principle of Data Flow.  LabVIEW is not C.  LabVIEW is not Matlab.  LabVIEW is not Python.

 

When you have a structure (such as a While Loop) and you bring data out of the While Loop (through, say, a Shift Register) and wire indicators to it outside the While Loop, the Principle of Data Flow says that nothing will appear on those wires until the While Loop exits.  You have wired a False constant to the While Loop Stop indicator, so the loop will never exit, and the indicators will never show anything other than their default value.

 

Quiz -- what (very simple thing) do you need to do with those indicators to make them show the values present on wires as the While Loop runs?

 

Bob Schor

0 Kudos
Message 8 of 12
(4,070 Views)

I guess that depends on how you are using the shift register. The way you are developing your code. To say it wont work is inaccurate. It would depend on what you are doing with it. I just wanted to make the point that the previous value is available by pulling down the shift register. I did not say that it would work in this situation. It might if you did it correctly. 

Tim
GHSP
0 Kudos
Message 9 of 12
(4,072 Views)

@aeastet wrote:

Actually you can just pull down the shift register to get the previous value:


Actually implies it's an improvement to what was previously mentioned as a solution. While in fact it doesn't solve the problem.

 



@aeastet wrote:

I guess that depends on how you are using the shift register. The way you are developing your code. To say it wont work is inaccurate. It would depend on what you are doing with it. 


To say it won't work is pretty accurate.

 

How is this related to the way I develop code?

 

OP's requirements where clear. It was not to get the previous value, but to store previous value based on a button.

 


@aeastet wrote:

 I just wanted to make the point that the previous value is available by pulling down the shift register.


It is a valid point... But not really related to the question.

 


@aeastet wrote:

I did not say that it would work in this situation. It might if you did it correctly. 


It doesn't. Perhaps you could show us how to use it correctly?

Message 10 of 12
(4,060 Views)