1 Reply Latest reply on Apr 16, 2018 11:19 AM by JoshDavisNC

    How to get Latitude/Longitude/Altitude programmatically

    JoshDavisNC

      The "Hello world in DroneKit" from 04 Autonomous drone programming in Python · intel-aero/meta-intel-aero Wiki · GitHub  is working correctly for me, and the map on QGroundControl running on my tablet shows the correct location and direction.

       

      I'm trying to run the following Python code to get the geoposition data from the drone.

      ==========================================

      from dronekit import connect, VehicleMode

       

      connection_string = 'tcp:127.0.0.1:5760'

      print("Connecting to vehicle on: {0}".format(connection_string))

      vehicle = connect(connection_string, wait_ready=False)

      print("Get some vehicle attribute values:")

      print(" GPS: {0}".format(vehicle.gps_0))

      print(" Battery: {0}".format(vehicle.battery))

      print(" Last Heartbeat: {0}".format(vehicle.last_heartbeat))

      print(" Is Armable?: {0}".format(vehicle.is_armable))

      print(" System status: {0}".format(vehicle.system_status.state))

      print(" Mode: {0}".format(vehicle.mode.name))

      print(" Global Location: {0}".format(vehicle.location.global_frame))

      print(" Local Location: {0}".format(vehicle.location.local_frame))

      print(" Heading: {0}".format(vehicle.heading))

      print(" Pitch: {0}".format(vehicle._pitch))

       

      vehicle.close()

      print("Completed")

      ==========================================

       

      The output I get is:

      Connecting to vehicle on: tcp:127.0.0.1:5760

      Get some vehicle attribute values:

      GPS: GPSInfo:fix=3,num_sat=9

      Battery: Battery:voltage=12.373,current=0.0,level=100

      Last Heartbeat: 0.11084036796819419

      Is Armable?: False

      System status: STANDBY

      Mode: MANUAL

      Global Location: LocationGlobal:lat=None,lon=None,alt=None

      Local Location: LocationLocal:north=0.0,east=0.0,down=-0.7142958641052246

      Heading: 223

      Pitch: 0.008538215421140194

      Completed

       

      The pitch and heading are correct, but it's not returning anything for latitude, longitude, or altitude. Is there some step I need to perform first before I can get these values, or is there some other way I am supposed to get these values?

       

      Thanks.