[proposal] mavactive: util to send heartbeats in the background#577
[proposal] mavactive: util to send heartbeats in the background#577ES-Alexander wants to merge 4 commits intoArduPilot:masterfrom
Conversation
A class for keeping an active mavlink connection alive by sending regular heartbeats. All heartbeat parameters can be changed live, including the period, and an instance can be killed at any point, and revived later if desired.
Augments internal `MAVLink` instance file with locked writing, to ensure thread-safety.
|
It's possible this is better placed within |
|
On Sat, 14 Aug 2021, ES-Alexander wrote:
Accordingly, for active mavlink connections it's useful to be able to send regular heartbeats without needing to set that up manually as part of every script/program.
Doesn't this lose the whole idea of a heartbeat - that your component is
actually alive?
Sending the heartbeat as part of your main control loop (rather than in a
thread) would seem to be rather more preferable as it is a much stronger
indication your component is alive and kicking.
|
Interesting take. I'm seeing it more from the perspective of if you had something like a slow sensor or processing step then having a separate thread for heartbeats enables frequency consistency and simplifies the main program logic (i.e. our hearts keep pumping even if we're busy - it doesn't always make sense to focus on it 'consciously'). A similar idea applies for a passive observer, where you want to keep getting information so the heartbeat is just there to say "hey I'm still here, please keep sending messages" - simplified logic is appreciated. I'd agree that a thread-based heartbeat would be a worse indication of aliveness in the specific case of the main program getting into a blocked state that it can't get out of. For cases where the main program ends (e.g. via completion or exception) both multi-threaded and single-threaded methods are equivalent, and for cases where the main process is subject to long enough waits/calculations to be significant on the heartbeat timescale then a threaded approach is perhaps preferable. I'd also make the case that having separate threads for different functionalities can be helpful for simplifying logic in each functionality (they can be programmed and operate independently). I'm not saying this approach is always better than a single-threaded approach, but it provides a choice that (at least to me) seems sufficiently useful that it should be available, so users can make their own decision about what is most appropriate for their particular use-case 🙂 |
- more robust and consistent handling of shutdown process
According to the heartbeat microservice docs:
Accordingly, for active mavlink connections it's useful to be able to send regular heartbeats without needing to set that up manually as part of every script/program.
This PR provides a
mavactiveclass for managing an active mavlink connection, which: