From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
02-17-2011 04:07 AM
Hi,
In a small application that I am writing, I am continuously acquiring data in the main while loop. This data is used to calculate the misalignment of a hardware part. This part can be tilted with a motor, driven by commands to the serial port. In a previous version, I just added this functionality to the main loop, but then the motor commands lag on what they should be (the device takes some time to respond completion back to the program). As a result I get huge overshoots of the tilt angle and continuous back and forth movement. To solve this I came up with the following:
02-17-2011 05:07 AM
Maybe I don't understand this correctly, but is there any reason to have more than one element in the queue. Your design sounds great except I would suggest to just use a single-element queue (by initialising the queue as one). Then you don't have to use the eneque element at opposite end function. The standard enqueue function should be OK.
02-17-2011 05:35 AM
I agree with your design - if I correctly understood your question -, however if you need only the latest value you can use a notifier instead.
02-17-2011 06:09 AM
Hi
I think both of you understood it. Adnan's remark is valid indeed. So if I were to use a single-element queue, would the motor loop then get the latest element?
@pincpanter wrote:
...you can use a notifier instead...
Can you briefly explain how a notifier can be used?
02-17-2011 06:47 AM
OK now that I have understood it, the lossy enqueue element should be used instead of the standard queue element.
But, the above suggestion of using a notifier is better. You just need to replace all queue functions with corresponding notifier functions. Have a look through the Notifier palette.
02-17-2011 06:56 AM
Generally, you can use a notifier instead of a queue if you can afford to loose intermediate data between two read operations (it seems your case to me).
A notifier is similar to a 1-element queue, however you can write to a notifier at any time overwriting the old value, whereas you can't write a second value to a 1-el queue unless you dequeue the first one. There are other differences, of course: the receiver of a notification can grab the latest value or wait a new one (in the first case a notifier is very similar to a local variable, but it's faster); it's possible to wait on multiple notifiers, etc.
02-17-2011 09:24 AM
@pincpanter wrote:
Generally, you can use a notifier instead of a queue if you can afford to loose intermediate data between two read operations (it seems your case to me).
A notifier is similar to a 1-element queue, however you can write to a notifier at any time overwriting the old value, whereas you can't write a second value to a 1-el queue unless you dequeue the first one. There are other differences, of course: the receiver of a notification can grab the latest value or wait a new one (in the first case a notifier is very similar to a local variable, but it's faster); it's possible to wait on multiple notifiers, etc.
This is not true for newer versions of LabVIEW. I believe LV 8.6 was the first version to have a lossy queue so LabVIEW takes care of dropping the oldest data from the queue for you.
I would lean toward the queue since there is another fundamental difference between a queue and a notifier. A queue is intended to have one listener. Notifiers are intended to have multiple listeners. From a programming aspect I like to use the "correct" function for a given task. It sounds like this application only needs to have one task listening on the queue. By using a notifier someone looking at the code could be mislead to assume there are multiple acters on the data. I realize this is symantics but little things like this help to keep the code more readbale and understandable.