question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation doesn't clearly state what happens after an abort

See original GitHub issue

By @hamishwillee’s suggestion, I’m opening this because I was trying to figure out what happens after a connection abort (i.e. heartbeat_timeout is exceeded), and the documentation does not make it clear. After looking through dronekit/init.py, I see on lines 1099-1102:


                if self._heartbeat_error and self._heartbeat_error > 0 and time.time(
                ) - self._heartbeat_lastreceived > self._heartbeat_error:
                    raise APIException('No heartbeat in %s seconds, aborting.' %
                                       self._heartbeat_error)

Looking at dronekit/mavlink.py, I can see that the exception will cause the handler thread to exit:

            try:
                while True:
                    # Downtime
                    time.sleep(0.05)

                    # Loop listeners.
                    for fn in self.loop_listeners:
                        fn(self)

            except APIException as e:
                errprinter('>>> ' + str(e.message))
                self._alive = False
                self.master.close()
                self._death_error = e
                return

I think the documentation could be improved by stating that the abort will cause the connection to permanently close (while a heartbeat_warning will not), and that if this behavior is not desired, to set the timeout to a large value. If an abort occurs, @hamishwillee suggested that the only recourse would be a reconnect, and the documentation should state this. Also, in the case of an abort, I’m not sure how to detect it from a script (to go about doing a reconnect).

One other issue, is that a reconnect would issue a new vehicle object, but all the decorated message/attribute listeners on the top level (say in a module) would have already been initialized, and would not be updated. Meaning if you expect a reconnect, you would need to re-declare all your decorated handlers with the new vehicle object (probably inside an initialization function).

Edit to illustrate my point:

# Is only called when the module is imported, cannot be updated...
@vehicle.on_attribute('location')
def listener(...)
    ...
def initialize(vehicle):
    # Called each time we call initialize. Sets up listeners on new vehicle
    @vehicle.on_attribute('location') 
    def listener(...)
         ...

It might also be worth considering if it should be possible to disable it completely (say, pass in a timeout of -1).

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Evidlocommented, Jul 25, 2017

Here’s a working solution, but too much of a hack in my opinion:

from dronekit import connect
from time import sleep

def last_heartbeat_callback(vehicle, attr_name, last_heartbeat):
    if last_heartbeat > 5:
        print('last_heartbeat > 5, reconnecting')
        vehicle._handler.master.close()
        pixhawk_connect()

def pixhawk_connect():
    vehicle = connect("tcp:localhost:14550", heartbeat_timeout=50)
    vehicle.add_attribute_listener('last_heartbeat', last_heartbeat_callback)

pixhawk_connect()

while True:
    sleep(1)
0reactions
Evidlocommented, Jul 25, 2017

Has anything changed here? I haven’t found a decent way to detect an abort so that I can reconnect to the Pixhawk if it loses power. Ideally there would be a vehicle.aborted attribute that I could attach a listener to.

Here’s one failed attempt at a solution:

from dronekit import connect
from time import sleep

def last_heartbeat_callback(vehicle, attr_name, last_heartbeat):
    if last_heartbeat > 5:
        print('last_heartbeat > 5, reconnecting')
        vehicle.close()
        pixhawk_connect()

def pixhawk_connect():
    vehicle = connect("tcp:localhost:14550", heartbeat_timeout=50)
    vehicle.add_attribute_listener('last_heartbeat', last_heartbeat_callback)

pixhawk_connect()

while True:
    sleep(1)

But I get

>>> Exception in attribute handler for last_heartbeat
>>> cannot join current thread

on vehicle.close(), probably because I’m trying to close vehicle from inside its own callback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

19-1392 Dobbs v. Jackson Women's Health Organization (06 ...
Held: The Constitution does not confer a right to abortion; Roe and Casey are overruled; and the authority to regulate abortion is returned ......
Read more >
Abortion, Pregnancy Loss & Your Rights at Work
Have questions about your legal rights at work related to abortion, miscarriage, or stillbirth? This fact sheet can help. ... We understand it...
Read more >
Abortion: What to Expect
The clinic will provide more detail about what to expect and how long you ... Once the abortion procedure is complete, you will...
Read more >
Michigan Legislature - Section 333.17015
(a) "Abortion" means the intentional use of an instrument, drug, or other substance or device to terminate a woman's pregnancy for a purpose...
Read more >
HEALTH AND SAFETY CODE CHAPTER 171. ABORTION
INFORMED CONSENT REQUIRED. A person may not perform an abortion without the voluntary and informed consent of the woman on whom the abortion...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found