Skip to content

Commit aa6ae75

Browse files
wsilva32mrpollo
authored andcommitted
adds a method to LocationLocal that returns distance from home, in me… (#679)
* adds a method to LocationLocal that returns distance from home, in meters * Return 3D distance to home if `down` is known, otherwise return 2D distance * also, rename `distance` to `distance_home`
1 parent 7604bd9 commit aa6ae75

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

dronekit/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ def __init__(self, north, east, down):
184184
def __str__(self):
185185
return "LocationLocal:north=%s,east=%s,down=%s" % (self.north, self.east, self.down)
186186

187+
def distance_home(self):
188+
"""
189+
Distance away from home, in meters. Returns 3D distance if `down` is known, otherwise 2D distance.
190+
"""
191+
192+
if self.north is not None and self.east is not None:
193+
if self.down is not None:
194+
return math.sqrt(self.north**2 + self.east**2 + self.down**2)
195+
else:
196+
return math.sqrt(self.north**2 + self.east**2)
197+
187198

188199
class GPSInfo(object):
189200
"""

0 commit comments

Comments
 (0)