Delacor Toolkits Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Helper loops for active / repetitive tasks

Solved!
Go to solution
Highlighted

Helper loops for active / repetitive tasks

I finally managed to write a little something about how we use helper loops in our applications. Feel free to take a look at https://www.hampel-soft.com/blog/dqmh-actors-self-messaging-or-helper-loops/ and let me know if you have any further questions or comments


Joerg Hampel, CLA | hampel-soft.com
Message 1 of 8
(367 Views)

Re: Helper loops for active / repetitive tasks

Nice post Joerg! I need to get round to writing mine! Your approach matches mine to a great extent. The bit that I've added is to have the helper loop enable/disable itself when the module is idle/active. So the timeout in the helper loop is set to -1 automatically when there's one or more messages in the message queue and reset to the helper loop period when the queue is emptied. That way I can be sure the helper loop never (or at least almost never) gets in the way of the operation of the module.

 

We're also using the second type of helper loop in a singleton module which manages (and provides the interface to) a cloneable module. The helper loop handles all messages coming from the cloneable modules (and any other external module we're interested in hearing from). 

 

Now, this COULD be done using the main event handling loop of the DQMH, but I do prefer keeping the two loops separate - one loop for direct commands to the main module (i.e. the DQMH event loop) and one loop which I call the "External module event handler" which registers for the broadcast events of external modules...

 

Paul

 

 

Message 2 of 8
(295 Views)

Re: Helper loops for active / repetitive tasks

Paul, thanks for commenting! 

 

One interesting thing is that you point out that you don't want the helper loop to get in the way of the operation of the module. So far, for most (if not all) of our modules with helper loops, I'd not want the module to get in the way of the helper loop. This distinction is definitely something to keep in mind when designing the module. Let's talk about this some more next week in Madrid.


Joerg Hampel, CLA | hampel-soft.com
0 Kudos
Message 3 of 8
(285 Views)

Re: Helper loops for active / repetitive tasks

When talking to some LabVIEW friends about this blog post, I was confronted with reservations regarding using the timeout event of an event structure for periodic actions. It was pointed out that NI's core 3 training recommends not to use the timeout event for any critical actions.

 

dqmh-helperloop-2.png


I know from experience that timeout events used to be tricky (maybe even buggy?) some years ago, maybe in LV8.2 or 8.6 or so. I haven’t had any bad experiences with it ever since. Is there anyone who has more tangible things to say about this? Does NI still recommend to not use it for critical stuff?


Joerg Hampel, CLA | hampel-soft.com
0 Kudos
Message 4 of 8
(282 Views)

Re: Helper loops for active / repetitive tasks


wrote:

When talking to some LabVIEW friends about this blog post, I was confronted with reservations regarding using the timeout event of an event structure for periodic actions. It was pointed out that NI's core 3 training recommends not to use the timeout event for any critical actions.

 

dqmh-helperloop-2.pngI know from experience that timeout events used to be tricky (maybe even buggy?) some years ago, maybe in LV8.2 or 8.6 or so. I haven’t had any bad experiences with it ever since. Is there anyone who has more tangible things to say about this? 

 

Hi Joerg,

 
This is one of those things that became religious without people understanding the background (think about "Functional Global Variables protect against race conditions", no they CAN, but then don't always do).
 
It is true that if you have an event structure registered to a bunch of stuff, you don't want to use the timeout event case, because the timer will get reset everytime another event happens. However, if you only have:
* Stop DQMH module event
* Wakeup Helper Loop
* Put Helper Loop to sleep
 
Then, the timeout will execute without issue. You can benchmark this. Just leave a DQMH with a helper loop running overnight and count the time elapsed between each timeout.
 
As far as timeout being buggy, I don't remember this. There was an issue brought up at CLA Summit 2011, when Justin Goeres was presenting and Steen Schmidt pointed out that if one registered for an event and didn't handle it, the timer would still reset. This led to half of the room saying it was a bug and the other half saying it was a feature. All I know is that starting with LabVIEW 2013, this is no longer the case. Only the events handled by the event structure (have an event case assigned) cause the timer to reset.
 
Hope this helps.
Regards,
Fab
Certified LabVIEW Architect * Certified LabVIEW Embedded Developer * Certified Professional Instructor * LabVIEW Champion
Message 5 of 8
(276 Views)

Re: Helper loops for active / repetitive tasks

Thanks, Fab. I didn't even think of the timeout case being starved by other events being called because we don't use it that way. It might be worth adding that caveat to the original blog post.

 

And yes, I remember listening to Justin being interviewed by Michael for the 3rd VI Shots episode, and him talking about Steen triggering that event timeout epiphany.


Joerg Hampel, CLA | hampel-soft.com
Message 6 of 8
(271 Views)

Re: Helper loops for active / repetitive tasks

Yep, mine is more of an "idle time" helper loop... When no-one's talking to the module, the module talks to itself to keep itself Smiley Happy

 

We're using DQMH for a motion application and the end user can physically move the motion stages around without software input. The helper loop makes the DQMH periodically poll it's controller for any change in encoder position value and then we can broadcast that out to the application to update any UI which shows system position in real time. The module already sends its positions out during moves so there's no need for the helper loop to run...

 

Anyways, looking forward to a chat, perhaps over a beer?!

 

Paul

0 Kudos
Message 7 of 8
(262 Views)
Solution
Accepted by topic author joerg.hampel
02-12-2018 01:20 AM

Re: Helper loops for active / repetitive tasks


@ joerg.hampel wrote:

 

Does NI still recommend to not use it for critical stuff?


I would have to review the specifics of the LabVIEW Core 3 course to understand the exact scenario being described, but I can definitely see a recommendation to avoid using a Timeout event for handling "critical" events in an Event Structure that is also handling other "critical" events.

 

But in the case of a helper loop, the Timeout event *is* the critical event. As you mention above, it is critical that other requests *not* interfere with the operation of the helper loop (other than what was mentioned...enabling/disabling the helper loop, and the Stop Module request). 

 

I have never had reservations about using the Timeout event for the helper loop use case, and I am unaware of any feature limitations or bugs in LabVIEW that should prevent any of us from doing so.

DNatt, LV R&D
Message 8 of 8
(253 Views)