Testing Drone Connection and Arming problem


Hi, I am trying to run following script.

from dronekit import connect, VehicleMode, LocationGlobalRelative, APIException
import time
import socket
#import exceptions
import math
import argparse

def connectMyCopter():
parser = argparse.ArgumentParser(description=‘commands’)
args = parser.parse_args()

connection_string = args.connect
baud_rate = 19600

vehicle = connect(connection_string, baud=baud_rate, wait_ready=True)

def arm():
while vehicle.is_armable==False:
print(“Waiting for vehicle to become armable…”)
print(“Yoooo vehicle is now armable”)

while vehicle.armed==False:
    print("Waiting for drone to become armed..")

print("Vehicle is now armed.")
print("OMG  props are spinning. LOOK OUT.....")

vehicle = connectMyCopter()
print(“End of script”)

Using following command to run
pi@raspberrypi:~ $ python ./test.py --connect /dev/ttyAMA0

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/python3.7/dist-packages/dronekit/mavlink.py”, line 211, in mavlink_thread_in
File “/usr/local/lib/python3.7/dist-packages/dronekit/init.py”, line 1371, in listener
dronekit.APIException: No heartbeat in 30 seconds, aborting.
Traceback (most recent call last):
File “./test.py”, line 35, in
vehicle = connectMyCopter()
File “./test.py”, line 16, in connectMyCopter
vehicle = connect(connection_string, baud=baud_rate, wait_ready=True)
File “/usr/local/lib/python3.7/dist-packages/dronekit/init.py”, line 3166, in connect
vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout)
File “/usr/local/lib/python3.7/dist-packages/dronekit/init.py”, line 2275, in initialize
raise APIException(‘Timeout in initializing connection.’)
dronekit.APIException: Timeout in initializing connection.

Any suggestions?


Please write out your script as it was used. It shows numerous indent problems.


Hi, copy and paste is changing the indents and quotes. I assure you there is no syntax error. I took this code from Caleb’s video on youtube.


I see there is a missing returned vehicle object at the end of the connectMyCopter() function -

return vehicle

I’m also not sure why there is a baud rate = 19600 statement. Caleb states if you are using a Pixhawk to set it to 57600. But I use a Pixhawk and I leave it out and run it in my run command :

python test.py --connect /dev/ttyAMA0,57600


Thank you for your comments. It is very helpful.


10 points @jax200

closed #7