Skip to content

Commit

Permalink
Bug fixes and few UI enhancements.
Browse files Browse the repository at this point in the history
Removed debugging printf's from various functions.

Fixed #38 where we were not catching correct drone model info for
anafiusa thermal vs color image.  We changed the getMatchingDrone
function to use a width ratio rather than linear distance.

Fixed #40 where we break apart MGRS coordinates by gzd, square
identifier, easting, and northing to make easier to read.

Fixed #39 ; was actually fixed by issue #35.

Checkpoint before adding API privacy manifest and version 2.6
  • Loading branch information
rdkgit committed Apr 28, 2024
1 parent c0d6414 commit a518279
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 57 deletions.
8 changes: 4 additions & 4 deletions OpenAthenaIOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = OpenAthenaIOS/OpenAthenaIOS.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 894;
DEVELOPMENT_TEAM = S9737SV7NZ;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = OpenAthenaIOS/Info.plist;
Expand Down Expand Up @@ -745,7 +745,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = OpenAthenaIOS/OpenAthenaIOSRelease.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 894;
DEVELOPMENT_TEAM = S9737SV7NZ;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = OpenAthenaIOS/Info.plist;
Expand Down Expand Up @@ -781,7 +781,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 894;
DEVELOPMENT_TEAM = S9737SV7NZ;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
Expand All @@ -801,7 +801,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 842;
CURRENT_PROJECT_VERSION = 894;
DEVELOPMENT_TEAM = S9737SV7NZ;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
filePath = "OpenAthenaIOS/DroneImage.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "1357"
endingLineNumber = "1357"
startingLineNumber = "1359"
endingLineNumber = "1359"
landmarkName = "resolveTarget(dem:altReference:)"
landmarkType = "7">
</BreakpointContent>
Expand Down
38 changes: 28 additions & 10 deletions OpenAthenaIOS/DebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class DebugViewController: UIViewController, UIScrollViewDelegate {
targetWidth: vc.theDroneImage!.theImage!.size.width)
vc!.theDroneImage!.ccdInfo = ccdInfo
foundCCDInfoString = "Found CCD info for drone make/model \(ccdInfo!.makeModel)<br>"
foundCCDInfoString += "Lens type: \(ccdInfo!.lensType)<br>"
foundCCDInfoString += "Comment: \(ccdInfo!.comment)<br>"
foundCCDInfoString += "Thermal?: \(ccdInfo!.isThermal)<br>"
}
catch {
print("No CCD info for drone image, using estimates")
Expand Down Expand Up @@ -249,51 +252,66 @@ class DebugViewController: UIViewController, UIScrollViewDelegate {
self.htmlString += "<br><b>Altitude Data:</b><br>"
do {
let alt = try vc.theDroneImage!.getAltitude()
let altStr = roundDigitsToString(val: alt, precision: 0)
if app.settings.unitsMode == .Metric {
self.htmlString += "Altitude: \(alt)m<br>"
self.htmlString += "Altitude: \(altStr)m<br>"
}
else {
self.htmlString += "Altitude: \(app.metersToFeet(meters: alt))ft<br>"
let altFt = app.metersToFeet(meters: alt)
let altFtStr = roundDigitsToString(val: altFt, precision: 0)
self.htmlString += "Altitude: \(altFtStr)ft<br>"
}
}
catch { htmlString += "Altitude: missing<br>"}
do {
let relAlt = try vc.theDroneImage!.getRelativeAltitude()
let relAltStr = roundDigitsToString(val: relAlt, precision: 0)
if app.settings.unitsMode == .Metric {
self.htmlString += "Relative altitude: \(relAlt)m<br>"
self.htmlString += "Relative altitude: \(relAltStr)m<br>"
}
else {
self.htmlString += "Relative altitude: \(app.metersToFeet(meters: relAlt))ft<br>"
let relAltFt = app.metersToFeet(meters: relAlt)
let relAltFtStr = roundDigitsToString(val: relAltFt, precision: 0)
self.htmlString += "Relative altitude: \( relAltFtStr)ft<br>"
}
}
catch { self.htmlString += "Relative altitude: not preseent<br>" }
do {
let altFromRel = try vc.theDroneImage!.getAltitudeViaRelative(dem: vc.dem!)
let altFromRelStr = roundDigitsToString(val: altFromRel, precision: 0)
if app.settings.unitsMode == .Metric {
self.htmlString += "Drone altitude via relative alt: \(altFromRel)m<br>"
self.htmlString += "Drone altitude via relative alt: \(altFromRelStr)m<br>"
}
else {
self.htmlString += "Drone altitude via relative alt: \(app.metersToFeet(meters: altFromRel))ft<br>"
let altFromRelFt = app.metersToFeet(meters: altFromRel)
let altFromRelFtStr = roundDigitsToString(val: altFromRelFt, precision: 0)
self.htmlString += "Drone altitude via relative alt: \(altFromRelStr)ft<br>"
}
}
catch { self.htmlString += "Drone altitude via relative alt: unable to calculate<br>"}
do {
let altAboveGround = try vc.theDroneImage!.getAltitudeAboveGround()
let altAboveGroundStr = roundDigitsToString(val: altAboveGround, precision: 0)
if app.settings.unitsMode == .Metric {
self.htmlString += "Altitude above ground: \(altAboveGround)m<br>"
self.htmlString += "Altitude above ground: \(altAboveGroundStr)m<br>"
}
else {
self.htmlString += "Altitude above ground: \(app.metersToFeet(meters: altAboveGround))ft<br>"
let altAboveGroundFt = app.metersToFeet(meters: altAboveGround)
let altAboveGroundFtStr = roundDigitsToString(val: altAboveGroundFt, precision: 0)
self.htmlString += "Altitude above ground: \(altAboveGroundStr)ft<br>"
}
}
catch { self.htmlString += "Altitude above ground: not present<br>" }
do {
let altFromAboveGround = try vc.theDroneImage!.getAltitudeViaAboveGround(dem: vc.dem!)
let altFromAboveGroundStr = roundDigitsToString(val: altFromAboveGround, precision: 0)
if app.settings.unitsMode == .Metric {
self.htmlString += "Drone altitude via above ground alt: \(altFromAboveGround)m<br>"
self.htmlString += "Drone altitude via above ground alt: \(altFromAboveGroundStr)m<br>"
}
else {
self.htmlString += "Drone altitude via above ground alt: \(app.metersToFeet(meters: altFromAboveGround))ft<br>"
let altFromAboveGroundFt = app.metersToFeet(meters: altFromAboveGround)
let altFromAboveGroundFtStr = roundDigitsToString(val: altFromAboveGroundFt, precision: 0)
self.htmlString += "Drone altitude via above ground alt: \(altFromAboveGroundFtStr))ft<br>"
}
}
catch {
Expand Down
58 changes: 35 additions & 23 deletions OpenAthenaIOS/DroneImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public class DroneImage {
let md = CGImageSourceCopyPropertiesAtIndex(src!,0,nil)! as NSDictionary
let md2 = CGImageSourceCopyMetadataAtIndex(src!,0,nil)

print("updateMetaData: md is \(md)")
print("updateMetaData: md2 is \(md2)")
//print("updateMetaData: md is \(md)")
//print("updateMetaData: md2 is \(md2)")

metaData = md.mutableCopy() as! NSMutableDictionary
rawMetaData = md2
Expand Down Expand Up @@ -326,7 +326,7 @@ public class DroneImage {
var alt = 0.0
var gpsInfo: NSDictionary

print("getAltitude: starting with 0.0")
//print("getAltitude: starting with 0.0")

if metaData == nil {
print("getAltitude: no metadata, bugging out")
Expand All @@ -341,21 +341,21 @@ public class DroneImage {

if metaData!["drone-dji:AbsoluteAltitude"] != nil {
alt = (metaData!["drone-dji:AbsoluteAltitude"] as! NSString).doubleValue
print("getAltitude: drone-dji:AbsoluteAltitude \(alt)")
//print("getAltitude: drone-dji:AbsoluteAltitude \(alt)")
//return alt
}
if metaData!["drone:AbsoluteAltitude"] != nil {
alt = (metaData!["drone:AbsoluteAltitude"] as! NSString).doubleValue
print("getAltitude: drone:AbsoluteAltitude \(alt)")
//print("getAltitude: drone:AbsoluteAltitude \(alt)")
//return alt
}
if metaData!["drone-skydio:AbsoluteAltitude"] != nil {
alt = (metaData!["drone-skydio:AbsoluteAltitude"] as! NSString).doubleValue
print("getAltitude: drone-skydio:AbsoluteAltitude \(alt)")
//print("getAltitude: drone-skydio:AbsoluteAltitude \(alt)")
//return alt
}

print("getAltitude: \(alt), now going to make corrections")
//print("getAltitude: \(alt), now going to make corrections")

// for parrot, what about Camera:AboveGroundAltitude XXX ?

Expand All @@ -368,7 +368,7 @@ public class DroneImage {
// if alt is still 0.0, grab here
var altFromExif = false
if alt == 0.0 {
print("getAltitude:0.0, falling back to GPS")
//print("getAltitude:0.0, falling back to GPS")

if metaData!["{GPS}"] == nil {
print("getAltitude: no gps meta data, bugging out")
Expand All @@ -382,26 +382,26 @@ public class DroneImage {
alt = gpsInfo["Altitude"] as! Double
altFromExif = true

print("getAltitude: gps altitude is \(alt)")
//print("getAltitude: gps altitude is \(alt)")

// re autel drones, check altitude ref for 1 meaning below sea level XXX
if gpsInfo["GPSAltitudeRef"] != nil {
let ref = gpsInfo["GPSAltitudeRef"] as! Int
print("getAltitude: GPSAltitude ref is \(ref)")
//print("getAltitude: GPSAltitude ref is \(ref)")
if ref == 1 {
alt = -1.0 * alt
}
}
if gpsInfo["AltitudeRef"] != nil {
let ref = gpsInfo["AltitudeRef"] as! Int
print("getAltitude Altitude ref is \(ref)")
//print("getAltitude Altitude ref is \(ref)")
if ref == 1 {
alt = -1.0 * alt
}
}
if metaData!["exif:GPSAltitudeRef"] != nil {
let ref = (metaData!["exif:GPSAltitudeRef"] as! NSString).intValue
print("getAltitude: GPS exif:GPSAltitudeRef is \(ref)")
//print("getAltitude: GPS exif:GPSAltitudeRef is \(ref)")
if ref == 1 {
alt = -1.0 * alt
}
Expand All @@ -413,7 +413,7 @@ public class DroneImage {
throw DroneImageError.NoMetaGPSData
}

print("getAltitude: alt is now \(alt)")
//print("getAltitude: alt is now \(alt)")

// look for metadata drone:RtkAlt or drone:RtkAlt ?
// despite RtkAlt, we still think DJI is reporting
Expand Down Expand Up @@ -444,11 +444,11 @@ public class DroneImage {
// drone-dji:AltitudeType=RtkAlt

if xmlStringCopy?.lowercased().contains("rtkflag") == true {
print("getAltitude: xmlstringcopy rtkflag is true")
//print("getAltitude: xmlstringcopy rtkflag is true")
rtkFlag = true
}

print("getAltitude: rtkFlag is \(rtkFlag)")
//print("getAltitude: rtkFlag is \(rtkFlag)")

// now, depending on drone type/make, convert from EGM96 to WGS84 if necessary
var offset:Double = 0.0
Expand All @@ -462,7 +462,7 @@ public class DroneImage {
// DJI, autel if tag rtkflag then its already in WGS84

if rtkFlag == true {
print("getAltitude: rtkFlag so already in WGS84")
//print("getAltitude: rtkFlag so already in WGS84")
return alt // already in WGS84
}

Expand All @@ -473,7 +473,7 @@ public class DroneImage {
// 10/15/2023 looks like most parrot exif data is NOT in WGS84
if altFromExif == true && !make.lowercased().contains("parrot") &&
!make.lowercased().contains("autel") {
print("getAltitude: altFromExif, already in WGS84")
//print("getAltitude: altFromExif, already in WGS84")
return alt // already in WGS84
}

Expand Down Expand Up @@ -1347,6 +1347,8 @@ public class DroneImage {
var degAzimuth, degTheta: Double
var azimuthOffset, thetaOffset: Double

//print("resolveTarget: starting ******")

// azimuth is direction of aircraft's camera 0 is north, increase clockwise
// which is reported as Yaw degree
// theta is angle of depression (pitch) of aircraft's camera; positive value
Expand All @@ -1357,19 +1359,19 @@ public class DroneImage {
try degAzimuth = getGimbalYawDegree()
try degTheta = getGimbalPitchDegree()

print("resolveTarget: got az and theta")
//print("resolveTarget: got az and theta")

// corrected or uncorrected versions of getRayAnglesFromImagePixel

(azimuthOffset,thetaOffset) = try getRayAnglesFromImagePixelCorrected(x: theImage!.size.width * targetXprop,
y: theImage!.size.height * targetYprop)

print("resolveTarget: azOff \(azimuthOffset), thetaOff \(thetaOffset)")
//print("resolveTarget: azOff \(azimuthOffset), thetaOff \(thetaOffset)")

degAzimuth += azimuthOffset
degTheta += thetaOffset

print("resolveTarget: degAz \(degAzimuth) degTheta \(degTheta)")
//print("resolveTarget: degAz \(degAzimuth) degTheta \(degTheta)")

// convert to radians
radAzimuth = degAzimuth.radians
Expand All @@ -1389,7 +1391,7 @@ public class DroneImage {
try alt = getAltitudeViaRelative(dem: dem)
}

print("resolveTarget: lat: \(lat) lon: \(lon) alt: \(alt)")
print("resolveTarget: starting lat: \(lat) lon: \(lon) alt: \(alt)")
}
catch {
print("resolveTarget: missing metadata at the start")
Expand Down Expand Up @@ -1451,26 +1453,34 @@ public class DroneImage {
// meters of acceptable distance between constructed line and datapoint. somewhat arbitrary
var THRESHOLD: Double = post_spacing_meters / 16.0

print("resolveTarget: setting THRESHOLD \(THRESHOLD)")

var curLat = lat
var curLon = lon
var curAlt = alt
var groundAlt: Double
do {
try groundAlt = dem.getAltitudeFromLatLong(targetLat: curLat, targetLong: curLon)
//print("resolveTarget: groundAlt is \(groundAlt)")
print("resolveTarget: groundAlt is \(groundAlt)")
}
catch {
throw error
}

if (curAlt < groundAlt) {
print("curAlt \(curAlt) < groundAlt \(groundAlt) while resolving target")
print("resolveTarget: curAlt \(curAlt) < groundAlt \(groundAlt) while resolving target")
throw DroneImageError.BadAltitude
//throw ElevationModuleError.RequestedValueOOBError
}

var altDiff = curAlt - groundAlt

//print("resolveTarget: entering while loop, altDiff is \(altDiff)")

while altDiff > THRESHOLD {

//print("resolveTarget: altDiff \(altDiff) > \(THRESHOLD)")

do {
try groundAlt = dem.getAltitudeFromLatLong(targetLat: curLat, targetLong: curLon)
}
Expand All @@ -1487,6 +1497,8 @@ public class DroneImage {

(curLat,curLon) = DroneImage.inverse_haversine(lat1: curLat, lon1: curLon, d: horizScalar*INCREMENT, radAzimuth: radAzimuth, alt: avgAlt)

//print("resolveTarget: iterate curr lat,lon \(curLat),\(curLon)")

} // while altDiff > threshold

// when loop ends, curY, curX, curZ are closeish to target
Expand Down
6 changes: 3 additions & 3 deletions OpenAthenaIOS/DroneImageDJI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DroneImageDJI: DroneImage
var alt = 0.0
var gpsInfo: NSDictionary

print("getAltitudeDJI: invoked")
//print("getAltitudeDJI: invoked")

let superAlt = try super.getAltitude()

Expand All @@ -37,10 +37,10 @@ public class DroneImageDJI: DroneImage

if metaData!["drone-dji:AbsoluteAltitude"] != nil {
alt = (metaData!["drone-dji:AbsoluteAltitude"] as! NSString).doubleValue
print("getAltitudeDJI: drone-dji:AbsoluteAltitude \(alt)")
//print("getAltitudeDJI: drone-dji:AbsoluteAltitude \(alt)")
}

print("getAltitudeDJI: alt is \(alt) now going to make corrections")
//print("getAltitudeDJI: alt is \(alt) now going to make corrections")

// for DJI drones, look for this flag bug ignore RtkAlt in drone-dji:AltitudeType=RtkAlt
var rtkFlag = false
Expand Down
Loading

0 comments on commit a518279

Please sign in to comment.