Last active
July 19, 2018 05:12
-
-
Save jknthn/8c1d246908ee3139c9e5842279742560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@objc private func initializeMission() { | |
// 1. | |
if mission.points.count < 2 { | |
print("Not enough waypoints") | |
return | |
} | |
// 2. | |
if let mission = djiMission { | |
mission.removeAllWaypoints() | |
} else { | |
djiMission = DJIMutableWaypointMission() | |
} | |
// 3. | |
mission.pointsData().forEach { number, point, waypoint in | |
let waypoint = DJIWaypoint(coordinate: point.coordinate) | |
waypoint.altitude = 40.0 | |
djiMission.add(waypoint) | |
} | |
// 4. | |
djiMission.finishedAction = DJIWaypointMissionFinishedAction.noAction | |
djiMission.autoFlightSpeed = 2 | |
djiMission.maxFlightSpeed = 4 | |
djiMission.headingMode = .auto | |
djiMission.flightPathMode = .normal | |
// 5. | |
if let error = djiMission.checkParameters() { | |
print("Waypoint Mission parameters are invalid: \(error.localizedDescription)") | |
return | |
} | |
// 6. | |
if let error = missionOperator.load(djiMission) { | |
print(error.localizedDescription) | |
} | |
// 7. | |
missionOperator.addListener(toUploadEvent: self, with: DispatchQueue.main) { error in | |
print("Upload") | |
if error.currentState.rawValue == 5 { | |
self.state = .flying | |
self.startMission() | |
} | |
} | |
// 8. | |
missionOperator.uploadMission() { error in | |
if let error = error { | |
print("Upload error") | |
print(error.localizedDescription) | |
} else { | |
print("Upload finished") | |
self.state = .flying | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment