# 'goto\_location'

**URL:** <https://discuss.px4.io/t/goto-location/16598>\
**Category:** MAVSDK\
**Created:** [May 5, 2020, 1:56pm UTC](https://discuss.px4.io/t/goto-location/16598 "2020-05-05T13:56:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KatrijnChys](https://discuss.px4.io/letter_avatar_proxy/v4/letter/k/b782af/32.png) [@KatrijnChys](https://discuss.px4.io/u/KatrijnChys)\
**Post date:** [May 5, 2020, 1:56pm UTC](https://discuss.px4.io/t/goto-location/16598/1 "2020-05-05T13:56:35Z")

</div>

Hello

I’m in my third bachelor engineering technology. For my bachelorsassignment we have to write code for an autonomous flight test.  
We’re supposed to write a mission using some specific functions. One of the functions we miss is a ‘goto\_location’ function.  
Right now I’m trying to convert the distance in degree’s between two coördinates into a distance in meters but I still get some errors.  
I am using following code:  
`  
import math  
“”“radius of the Earth”""  
r = 6373.0  
class Waypoint():  
def **init** (self, lat, lon):  
self.lat = lat  
self.lon = lon

```auto
async def distancelat(self, wp1, wp2):
    """LATITUDE"""
    self.wp1 = wp1
    self.wp2 = wp2
    lat1rad = math.radians(wp1.lat)
    lat2rad = math.radians(wp2.lat)

    # change in coordinates
    dlon = 0
    dlat = lat2rad - lat1rad
    # Haversine formula
    a1 = math.sin(dlat / 2) **2 + math.cos(lat1rad) * math.cos(lat2rad) * math.sin(dlon / 2)** 2
    c1 = 2 * math.atan2(math.sqrt(a1), math.sqrt(1 - a1))
    distancelat = float(r * c1*1000)
    return distancelat

async def distancelon(self, wp1, wp2):
    """LONGITUDE"""
    self.wp1 = wp1
    self.wp2 = wp2
    lon1rad = math.radians(wp1.lon)
    lon2rad = math.radians(wp2.lon)
    lat1rad = math.radians(wp1.lat)
    lat2rad = math.radians(wp2.lat)

    # change in coordinates
    dlon = lon2rad - lon1rad
    dlat = 0
    # Haversine formula
    a = math.sin(dlat / 2) **2 + math.cos(lat1rad) * math.cos(lat2rad) * math.sin(dlon / 2)** 2
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    distancelong = float(r * c*1000)
    return distancelong

```

`

By using using the offboard function ‘set\_position\_ned’ I try to make the drone fly to it’s new location.

`wp1 = Waypoint(47.3977395, 8.5455929) wp2 = Waypoint(47.398039859999997, 8.5455725400000002) mnorth = Waypoint.distancelat(wp1, wp2) meast = Waypoint.distancelon(wp1, wp2) await drone.offboard.set_position_ned( (PositionNedYaw(mnorth, meast, -5, 0)))`

When trying to complete the mission I get the errors ‘no RC and no offboard’. Another error I get is that parameter ‘wp2’ is ‘‘unfilled’’.

Is there any way i can solve this? Is there an easier option?

Hope to hear from you soon and thanks in advance  
Katrijn Chys

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [May 5, 2020, 4:17pm UTC](https://discuss.px4.io/t/goto-location/16598/2 "2020-05-05T16:17:23Z")

</div>

Goto is coming with the next release, we’ve been working on syncing the C++ and Python API as well as other languages.

> [@KatrijnChys](#):
>
> When trying to complete the mission I get the errors ‘no RC and no offboard’.

Do you have RC? And have you made sure to send one offboard setpoint before doing start?

> [@KatrijnChys](#):
>
> Another error I get is that parameter ‘wp2’ is ‘‘unfilled’’.

Where do you get that one? I have never seen that.
