0

I am trying to connect JRC JJ1000 drone using dronekit + python. when executing the connect command:

dronekit.connect('com3', baud=115200, heartbeat_timeout=30)

I am getting the following error:

ERROR:dronekit.mavlink:Exception in MAVLink input loop
Traceback (most recent call last):
  File "C:\Python37\lib\site-packages\dronekit\mavlink.py", line 211, in mavlink_thread_in
    fn(self)
  File "C:\Python37\lib\site-packages\dronekit\__init__.py", line 1371, in listener
    self._heartbeat_error)
dronekit.APIException: No heartbeat in 5 seconds, aborting.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37\lib\site-packages\dronekit\__init__.py", line 3166, in connect
    vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout)
  File "C:\Python37\lib\site-packages\dronekit\__init__.py", line 2275, in initialize
    raise APIException('Timeout in initializing connection.')
dronekit.APIException: Timeout in initializing connection.

I left no store unturned but no progress. I also tried both Python 2.7 and 3.7 with same result.

Abdulkarim Kanaan
  • 1,703
  • 4
  • 20
  • 32

1 Answers1

0

I have been getting the same error. I am using some custom code in a docker container to run simulations with dronekit and ArduPilot. The error is intermittent. So far it seems like the only way to get the error to stop is to:

  • Close all docker containers.
  • Open windows task manager and wait for vmmem to lower memory usage (5-10m).
  • Try again.

Maybe the problems are related somehow. To me it seems like the connection might be in use by a previous instance and it was not properly close. Since waiting for vmmem to free up resources appears to fix it. I would prefer a better solution if anyone finds one!

We are using python code like this to connect:

from dronekit import connect
 ...
# try to connect 5 times
while connected == False and fails < 5:
    try:
        vehicle = connect(connection_string, wait_ready=True)
    except:
        fails += 1 
        time.sleep(3)
        print("Failed to connect to local mavlink sleeping for 3 seconds")
    else: 
        connected = True

Where the connection_string is of the form:

"tcp:host:port"

Also, the documentation states "If the baud rate is not set correctly, connect may fail with a timeout error. It is best to set the baud rate explicitly." Are you sure that you have the correct baud rate?

Soenhay
  • 3,958
  • 5
  • 34
  • 60