I’m trying to connect to the drone using a simple dronekit python script but I keep getting the error. I searched online for possible solutions but to no avail.
from dronekit import connect, VehicleMode, LocationGlobalRelative, APIException
from pymavlink import mavutil
import time
import socket
import exceptions
import argparse
def connectQuad():
parser = argparse.ArgumentParser(description='Commands')
parser.add_argument('--connect')
args = parser.parse_args()
connection_string= args.connect
print 'Connecting to vehicle on: %s' % args.connect
vehicle = connect(connection_string, wait_ready=True)
return vehicle
vehicle = connectQuad()
pi@navio:~/drone-kit $ python connect_quad.py --connect 127.0.0.1:14550
Connecting to vehicle on: 127.0.0.1:14550
WARNING:dronekit:Link timeout, no heartbeat in last 5 seconds
ERROR:dronekit.mavlink:Exception in MAVLink input loop
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/dronekit/mavlink.py", line 211, in mavlink_thread_in
fn(self)
File "/usr/local/lib/python2.7/dist-packages/dronekit/__init__.py", line 1371, in listener
self._heartbeat_error)
APIException: No heartbeat in 30 seconds, aborting.
Traceback (most recent call last):
File "connect_quad.py", line 18, in <module>
vehicle = connectQuad()
File "connect_quad.py", line 15, in connectQuad
vehicle = connect(connection_string, wait_ready=True)
File "/usr/local/lib/python2.7/dist-packages/dronekit/__init__.py", line 3166, in connect
vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout)
File "/usr/local/lib/python2.7/dist-packages/dronekit/__init__.py", line 2275, in initialize
raise APIException('Timeout in initializing connection.')
dronekit.APIException: Timeout in initializing connection.
Hi there Polina, I seem to be having this same problem with even the simplest Dronekit script on my real hardware. I am wondering if there is a timetable for a solution? I’m currently running the Emlid 2019-11-28 release. emlidtool reports Kernel: 4.19.83-emlid-v7l+ If it helps I’m running this on a Raspberry Pi 4. I do have a spare Pi 3 that I could downgrade to if there is an image available? Even so I hate to rebuild my Drone if at all possible. Is there an earlier Pi 4 release that doesn’t have this problem and is available?
Problem Solved – Ok, I solved this problem by pulling the master branch from the repository and building it locally. I then set my locally built arducopter image to be ardupilot firmware controlled by the service as described in the Emlid documentation. Dronekit Vehicle.connect methods no longer timeout. Apparently the firmware bundled with the Pi Buster image has a bug that has been fixed in the master branch.
To get you up and running quickly here are my notes. This assumes you’re using the latest Pi build from Emlid (Buster) since I think the service invocation steps may be different in the different Linux OS versions.
• On Raspberry Pi in pi user home directory
• Create a directory
• git clone GitHub - ArduPilot/ardupilot: ArduPlane, ArduCopter, ArduRover, ArduSub source
○ This clones the master or use a different branch
• cd ardupilot
• git submodule update --init --recursive
• ./waf list_boards
• ./waf configure --board=navio2 --debug
○ --debug optional
• ./waf --targets bin/arducopter
• Executable arducopter in ~/src/???/ardupilot/build/navio2/bin/arducopter
• To use this custom binary
• Note this doesn’t remove the existing/installed version but I suppose you could take that route too
○ modify /etc/systemd/system/ardupilot.service to point to the version you’ve built (uncomment execution)
○ Add options to /etc/default/ardupilot for ARDUPILOT_OPTS
○ Use systemctl to start the modified ardupilot service
§ pi@navio: ~ sudo systemctl start ardupilot && sudo systemctl enable ardupilot
getting the same error.
I’ve tried using solar’s fix by building from source and then modifying ardupilot.service to point to the new version/build.
Any help on this would be highly appreciated
Okay…managed to get it working now. Did what solar has mentioned earlier, I edited ardupilot.service to point to the binary, now I can’t connect to Mission Planner but dronekit works.
@curiosityrover i’m facing the same error , when i fix the IP of my GCS in the arducopter config the misson planner works well but i have a problem in dronekit , and when i dont make a changement in arducopter config (with 127.0.0.1:14550) the dronekit works fine and the misson planner doesn’t connect
The new Navio2 image is out now with the fix for the Dronekit connection issue. We’d be grateful if you checked it out to see if everything works as expected for you.