dronekit-python

Drone-kit function for getting x, y, and z position relative to a start point or take off location?


During a flight, say with a pixhawk, I want to save the current location of the drone in reference to its initial start location. Ideally that would be the x, y, and z positions in meters. I understand that you can save the lat, lon, or IMU/velocity readings using dronekit, then calculate the position. It would be awesome, however, to be able to just call a function that calculates the x, y, and z for you so there is no post-processing.


Solution

  • The following was satisfactory for my purposes (I believe you would need a GPS but not positive):

    from dronekit import connect
    vehicle = connect("Connection String", baud=57600)
    metersNorth = vehicle.location.local_frame.north # used for the y position
    metersEast = vehicle.location.local_frame.east # used for the x position
    altitude = vehicle.location.local_frame.down # used for the z position
    

    Or in my case I had a rangefinder facing down

    z = vehicle.rangefinder.distance