Python - fly to a waypoint given by GPS coordinates

Is there a MAVSDK-Python example code to fly to a waypoint given by GPS coordinates ?

Something like this ?

1 Like

Yes, thanks a lot…

But this code makes the drone flying sideways not straight ahead, anyone have an idea to make the drone turn around and flight straight ahead ?

Like this image

You can change line 37. The last parameter of the goto_location() method is the yaw angle, in degrees. Or you can add a new line before that first rotates the UAV and then goto_location as line 37.

1 Like

Great, but is there an easy way to calculate the Yaw angle directly ?

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

I could do it using latitude_deg and longitude_deg from drone.telemetry.position()
Thanks all

async for position_info in drone.telemetry.position():
current_latitude = position_info.latitude_deg
current_longitude = position_info.longitude_deg

yaw_angle = math.degrees(math.atan((destination_longitude - current_longitude) / (destination_latitude - current_latitude)))

if destination_latitude < current_latitude:
yaw_angle += 180