Dronekit python vehicle connection timeout

5.3k views Asked by At

we are having a bit of trouble getting Dronekit working with our copter. Thus far we have tested everything using SITL and it all works fine, however this success has not transferred across to the real thing very well.

Our setup is: Windows GCS running Mavproxy (Master via COM9, UDP outputs for the Dronekit script and Mission Planner) and a basic Dronekit script (Takeoff and land). Please see the diagram for a clearer explanation.

enter image description here

We use the following command when running MAVProxy: mavproxy.exe --master=com9,57600 --out=udp:127.0.0.1:14550 --out=udp:127.0.0.1:14551 --console

The issue we are having is connecting to the vehicle (http://python.dronekit.io/guide/connecting_vehicle.html), we are able to connect to the drone and get some board information. However then we do not receive a heartbeat message for 30 seconds, leading to a timeout.

>>> APM:Copter V3.5.2 (4322ffda)
>>> PX4: 1d6bf64c NuttX: 1a99ba58
>>> Frame: QUAD
>>> PX4v3 0020002E 30365110 35323931

Traceback (most recent call last):
  File "C:/Users/simon/PycharmProjects/uas_lol/test_mission.py", line 32, in <module>
    vehicle = connect(connection_string, wait_ready=True, baud=57600, heartbeat_timeout=120)
  File "C:\Python27\lib\site-packages\dronekit\__init__.py", line 2849, in connect
    vehicle.wait_ready(True)
  File "C:\Python27\lib\site-packages\dronekit\__init__.py", line 2199, in wait_ready
    timeout)
dronekit.APIException: wait_ready experienced a timeout after 30 seconds.

Process finished with exit code 1

We can bypass the timeout by setting wait_ready=False. Using this we can connect to the vehicle and arm the drone. When it comes to taking off, it only works some of the time. We find it is more likely to work (takes off) when we reset MAVProxy.

I would like to confirm that connecting to the drone using udp 127.0.0.1:14550 with Mission Planner works perfectly.

Any insight as to what we may be doing incorrectly would be greatly appreciated, thank you!

1

There are 1 answers

1
SCTaylor On

Turns out the issue was that because we were connected over serial telemetry at a baud rate of 57600 it takes ~2 minutes to download the parameters and Dronekit times out after 30 seconds.

According to the documentation you can set the timeout using heartbeat_timeout=180 (http://python.dronekit.io/automodule.html#dronekit.connect). However this did not actually solve the problem as it was still timing out after 30 seconds.

It looks like 30 seconds may be coded into the library, changing 30 to 180 in the following line solved my issue. https://github.com/dronekit/dronekit-python/blob/754ce6223dd26179045eaa394d5df0a5f787ebb2/dronekit/init.py#L2216