Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 49571e0

Browse files
committed
Skydio support
1 parent e1d7cb3 commit 49571e0

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

playground/getTarget.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ def inputNumber(message, lowerBound, upperBound):
221221
222222
"""
223223
def resolveTarget(y, x, z, azimuth, theta, elevationData, xParams, yParams):
224-
decimal.getcontext().prec = 50
224+
# jpl.nasa.gov/edu/news/2016/3/16/how-many-decimals-of-pi-do-we-really-need
225+
decimal.getcontext().prec = 30
225226
y = decimal.Decimal(y)
226227
x = decimal.Decimal(x)
227228
z = decimal.Decimal(z)

playground/parseImage.py

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
from PIL import Image
3737
from PIL import ExifTags
3838

39-
# XML
40-
# read-only
41-
import xml.sax as sax
4239
# write and mangle
43-
# tutorialspoint.com/xml-parsing-in-python
44-
import xml.etree.ElementTree as ET
40+
# eli.thegreenplace.net/2012/03/15/processing-xml-in-python-with-elementtree
41+
# try:
42+
# import xml.etree.cElementTree as ET # C implementation, much faster
43+
# except ImportError:
44+
# import xml.etree.ElementTree as ET
45+
4546

4647

4748
# unused :(
@@ -116,7 +117,7 @@ def parseImage():
116117

117118
sensData = None, None, None, None, None
118119
target = None
119-
try:
120+
if True:
120121
#from stackoverflow.com/a/14637315
121122
# if XMP in image is spread in multiple pieces, this
122123
# approach will fail to extract data in all
@@ -156,32 +157,26 @@ def parseImage():
156157
print(f'skipping {thisImage}', file=sys.stderr)
157158
continue
158159
elif make == "SKYDIO":
159-
print(f'ERROR with {thisImage}, Mfr. \'{make}\' not compatible with this program', file=sys.stderr)
160-
print(f'skipping {thisImage}', file=sys.stderr)
161-
# sensData = handleSKYDIO(xmp_str)
162-
# if sensData is not None:
163-
# y, x, z, azimuth, theta = sensData
164-
# target = resolveTarget(y, x, z, azimuth, theta, elevationData, xParams, yParams)
165-
# else:
166-
# print(f'ERROR with {thisImage}, couldn\'t find sensor data', file=sys.stderr)
167-
# print(f'skipping {thisImage}', file=sys.stderr)
168-
# continue
160+
sensData = handleSKYDIO(xmp_str)
161+
if sensData is not None:
162+
y, x, z, azimuth, theta = sensData
163+
target = resolveTarget(y, x, z, azimuth, theta, elevationData, xParams, yParams)
164+
else:
165+
print(f'ERROR with {thisImage}, couldn\'t find sensor data', file=sys.stderr)
166+
print(f'skipping {thisImage}', file=sys.stderr)
167+
continue
169168
elif False: # your drone make here
170169
# <----YOUR HANDLER FUNCTION HERE---->
171170
pass
172171
elif False: # your drone make here
173172
# <----YOUR HANDLER FUNCTION HERE---->
174173
pass
175174
else:
176-
print(f'ERROR with {thisImage}, Mfr. \'{make}\' not compatible with this program', file=sys.stderr)
175+
print(f'ERROR with {thisImage}, xmp data not found!', file=sys.stderr)
177176
print(f'skipping {thisImage}', file=sys.stderr)
178177
continue
179-
else:
180-
print(f'ERROR with {thisImage}, xmp data not found!', file=sys.stderr)
181-
print(f'skipping {thisImage}', file=sys.stderr)
182-
continue
183178

184-
except:
179+
else:
185180
print(f'ERROR with filename {thisImage}, skipping...', file=sys.stderr)
186181
continue
187182
#
@@ -293,28 +288,29 @@ def handleDJI( xmp_str ):
293288
def handleSKYDIO( xmp_str ):
294289
# Skydio has multiple frame of reference tags with same children
295290
# (i.e. "Yaw", "Pitch", etc.)
296-
# will need to parse as XML :(
297-
elements = ["drone-skydio:AbsoluteAltitude=",
298-
"drone-skydio:Latitude=",
299-
"drone-skydio:Longitude="
300-
"drone-skydio:Yaw=" # name collision :(
291+
# will need to parse differently :(
301292

302-
]
303293

294+
element = "drone-skydio:CameraOrientationNED"
295+
values = xmp_str[xmp_str.find(element) + len(element) : xmp_str.find(element) + len(element) + 100]
296+
theta = float(values.split('\"')[3])
297+
azimuth = float(values.split('\"')[5])
304298

305-
dict = xmp_parse( xmp_str, elements)
306-
if dict is None:
307-
return None
299+
theta = abs(theta)
308300

309-
# print(xmp_str)
301+
elements = ["drone-skydio:Latitude=",
302+
"drone-skydio:Longitude=",
303+
"drone-skydio:AbsoluteAltitude="]
304+
gpsDict = xmp_parse( xmp_str, elements)
310305

311-
y = dict["drone-skydio:Latitude="]
312-
x = dict["drone-skydio:Longitude="]
313-
z = dict["drone-dji:AbsoluteAltitude="]
306+
y = gpsDict["drone-skydio:Latitude="]
307+
x = gpsDict["drone-skydio:Longitude="]
308+
z = gpsDict["drone-skydio:AbsoluteAltitude="]
314309

315-
# azimuth = dict[
316-
# theta = abs(
317-
return None
310+
if y is None or x is None or z is None or azimuth is None or theta is None:
311+
return None
312+
else:
313+
return (y, x, z, azimuth, theta)
318314

319315
"""takes a xmp metadata string and a list of keys
320316
return a dictionary of key, value pairs

0 commit comments

Comments
 (0)