Skip to content

Instantly share code, notes, and snippets.

@jknthn
Last active July 19, 2018 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jknthn/8c1d246908ee3139c9e5842279742560 to your computer and use it in GitHub Desktop.
Save jknthn/8c1d246908ee3139c9e5842279742560 to your computer and use it in GitHub Desktop.
@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