LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement this "simple" algorithm?

Solved!
Go to solution

@sunson29 wrote:

I just abstract the question into this simple version. 


We already gave you plenty of abstracted simple answers. Please point out what's not clear to you. Here's what I would do:

 

Feedback node to get previous value.

Subtract old from new and wire result to sign function

Wire to case structure with three cases (-1,0,1).

One case for A, one for B, one empty for when nothing changed.

 

See how far you get.

 

Message 11 of 22
(3,084 Views)

2.png

1. The "input" will give the 0 or 1 to the upper loop.

2. Now, I want to know how to see this before and current value. I don't know how to do this with feedback or shift register. right now, the current will be always the same as before. Could you please help me modify this vi, and load? Thank you.

 

 

0 Kudos
Message 12 of 22
(3,076 Views)

Dear friends. 

 

I need some help here. Thank you so much in advance. VI attached. 

1. The "input" will give the 0 or 1 to the upper loop. In other words,  in top while loop, "input" will keep change between 0 or 1 for each iteration.   

2. Now, I want to know how to see this "before" and "current" value in top while loop. I don't know how to do this with feedback or shift register. right now, the current will be always the same as before. Could you please help me modify this vi, and load?  Please do keep those 2 while loop.  Thank you.

 

2.png

0 Kudos
Message 13 of 22
(3,118 Views)

One problem is that your upper loop runs millions of times per second, so the (current vs previous) reading will only be different for a nanosecond and you'll never see it. Your feedback node before the loop makes absolutely no sense at all. I really recommend you do a few more tutorials.

 

Here's what I would do (you can put it back in a separate loop, of course, but make sure to include a reasonable wait). As I said, if you need to execute different code parts depending on the state, wire to a case structure.

ChangeDetector.png

 

 

 

0 Kudos
Message 14 of 22
(3,094 Views)

Why did you open a new thread and post your question twice?

Kudos are welcome...
0 Kudos
Message 15 of 22
(3,065 Views)
Solution
Accepted by topic author sunson29

You really should learn about and understand the dataflow concept of LabVIEW. There are some good introductory online courses on ni.com.

 

You should also think about another mechanism to transfer your data from your producer loop to your consumer loop (btw, that pattern is called a producer-consumer pattern and can be found under File -> New... -> From templates).

 

Here's a version with that pattern.


Regards, Jens

Kudos are welcome...
0 Kudos
Message 16 of 22
(3,047 Views)

Thanks, Jens. Let me check this vi carefully.  

0 Kudos
Message 17 of 22
(3,017 Views)

This is slightly different from Altenbach's option.  It allows for an array input.

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 18 of 22
(2,996 Views)

Oh, thanks. could you upload the vi for me? Thank you again. 

0 Kudos
Message 19 of 22
(2,993 Views)

@Minions wrote:

This is slightly different from Altenbach's option.  It allows for an array input.


Your array input is on the FOR loop, not on the change detector and thus irrelevant for the change detector code. 🙂

0 Kudos
Message 20 of 22
(2,992 Views)