Skip to content

Instantly share code, notes, and snippets.

@jknthn jknthn/Waypoints.swift
Last active Jul 19, 2018

Embed
What would you like to do?
@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
You can’t perform that action at this time.