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’)
parser.add_argument(’–connect’)
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…”)
time.sleep()
print(“Yoooo vehicle is now armable”)
print("")
vehicle.armed=True
while vehicle.armed==False:
print("Waiting for drone to become armed..")
time.sleep(1)
print("Vehicle is now armed.")
print("OMG props are spinning. LOOK OUT.....")
vehicle = connectMyCopter()
print(vehicle)
arm()
print(“End of script”)
Using following command to run
pi@raspberrypi:~ $ python ./test.py --connect /dev/ttyAMA0
output:
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
fn(self)
File “/usr/local/lib/python3.7/dist-packages/dronekit/init.py”, line 1371, in listener
self._heartbeat_error)
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?