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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Notifier timeout behavior

Solved!
Go to solution

I have a routine to move a stage through a set of positions. The position is set by a sub-vi, and I need to be able to tell the sub-vi to "move on" if the user clicks a button. I thought a notifier would be perfect for this: pressing a button would send the notice to the sub-vi to exit, and while the stage is moving, the sub-vi would be querying the position (while also waiting on the notification); if the notification is not received, the Wait on Notification vi would time out (since I've passed a positive value) and the position would be queried again and again until the target is reached.  (That was my understanding of how it should work, and it seems supported by the post here.)

 

What is actually happening is that because of the notifier, the code just sits there, waiting. Nothing happens until and unless I press the button that triggers the notification.

 

Have I misunderstood how the notifier should behave when it times out? If so, what is a better architecture for achieving my goal? If I've understood correctly, what do I need to do to make my code work as intended?

 

I've attached a demo -- no actual motion control, but positions / motion are simulated by elapsed time. Block diagram screenshots are below. Thanks in advance!

Move Sequence.pngMove and Query.png

 

Download All
0 Kudos
Message 1 of 7
(1,880 Views)

The Wait on Notification is working fine, but your While loop is coded to keep looping until you get a True notification. Note that if you probe the output of Wait on Notification that the Last Update time continues updating, thus your assertion that it's still waiting on the notifier is false. It times out after 200 ms, just like it's supposed to.

 

I'm not sure what exactly you WANT this code to be doing. In this example, your Distance from Target value keeps increasing, so it will never be less than Tolerance, this your loop will never exit until you get a Notification. Basically, your loop is doing exactly the behavior that you want... the Wait on Notification is timing out most of the time, and only stops when Distance from Target is less than Tolerance OR you get a notification.

 

You also have a Wait function in there- why do you have both a Wait and a Wait on Notification with the same timeout values?

0 Kudos
Message 2 of 7
(1,872 Views)

Thanks for your reply. 

 

The Wait on Notification is working fine, but your While loop is coded to keep looping until you get a True notification. Note that if you probe the output of Wait on Notification that the Last Update time continues updating, thus your assertion that it's still waiting on the notifier is false. It times out after 200 ms, just like it's supposed to.

What I see is that the last update time continues updating up until the Distance to the Target is less than the Tolerance -- just like it's supposed to. At that point, the less-than-or-equal comparison is True, and its negation False, so the loop should stop looping. And it does (the loop index can be seen to stop changing). It also stops looping when it receives the True notification. This is how I intended it. But then nothing further happens -- once the loop inside "Move & Query" stops, control does not return to the calling code ("Move Sequence"). The calling code never resumes its loop unless I click the button to send a notification.

 


I'm not sure what exactly you WANT this code to be doing. In this example, your Distance from Target value keeps increasing, so it will never be less than Tolerance, this your loop will never exit until you get a Notification. Basically, your loop is doing exactly the behavior that you want... the Wait on Notification is timing out most of the time, and only stops when Distance from Target is less than Tolerance OR you get a notification.

I wasn't able to see the Distance from Target value continue to increase... For me, it started out negative (which for an unsigned integer is a large positive value) then becomes a small positive number once the sign changes. I've changed it to use signed integers (which also lets me use the absolute value before the Distance from Target indicator, as I should have had). I also

corrected the Final Position wiring (it should be the difference between the in-loop millisecond timer value and that initialized outside the loop). And "Num Loops" should be, say, 10. Sorry -- I was trying to make a minimal working example from my original code and didn't get everything right. With the revised code, do you see the same problems you saw before?

 

You also have a Wait function in there- why do you have both a Wait and a Wait on Notification with the same timeout values?


That was a mistake -- thanks. I meant to put a Tick Count there.

So: why does the code appear to stop executing once we are within Tolerance from Target? Both the sub-vi and the calling vi loop indices stop incrementing, even though the Wait on Notifier is timed out and should therefore, I think, allow the code to continue.

 

Move and Query - revised.png

 

Download All
0 Kudos
Message 3 of 7
(1,846 Views)
Solution
Accepted by topic author jmu25

Ah, that works better now with correct initial values.

 

Your problem still isn't with the notification- it's actually the *calling* VI that's hanging, not Move and Query.

 

Try adding probes to the input and output of Wait on Notification- you'll see that they're always within 200 ms of each other. The issue is that your testbed here will only ever move on once you get a Declare Position OK event or a Timeout, and since the Timeout is unwired it defaults to -1 (thus, never a timeout). You need to put the button handling in a separate loop.

 

Right now, Move Sequence will begin executing and will call Move and Query and begin waiting on a Declare Position OK value change. M&Q will finish and return the Final Position value, but the event structure will still wait until you click that button. Once you click the button, the sequence structure can continue executing and the For loop will iterate, then fire off Move and Query again. Try this:

 

Move Sequence_BD.png

Message 4 of 7
(1,816 Views)

The issue is that your testbed here will only ever move on once you get a Declare Position OK event or a Timeout, and since the Timeout is unwired it defaults to -1 (thus, never a timeout). You need to put the button handling in a separate loop. 

Aha! That makes sense! Thanks. I made your changes and it does work. I've attached it for future visitors. (I also moved setting the "Declare Position OK" to False to outside the loop; I didn't need to include it in the sequence structure since that assignment is performed in the Event structure.

 

As a side note, the 200 ms difference is expected -- that's what I put as Tolerance and the timeout period for the Wait on Notification. In a more realistic scenario, I'd have the Tolerance smaller (I've changed it to 50 ms... but this is only a demo anyway).

 

Thank you for your help!

Download All
0 Kudos
Message 5 of 7
(1,794 Views)

@jmu25 wrote:
 (I also moved setting the "Declare Position OK" to False to outside the loop; I didn't need to include it in the sequence structure since that assignment is performed in the Event structure.

Get rid of that all together, especially since you never read this button. Change your button to latch and move it inside the event structure so that it gets read and therefore returned to FALSE. No need for local variables. 

0 Kudos
Message 6 of 7
(1,764 Views)

That's a great idea -- thanks for the tip!

0 Kudos
Message 7 of 7
(1,748 Views)