Please select Into the mobile phone version | Continue to access the computer ver.
Waypoints in swift - how to execute a mission
67 0 5-25 07:49
Uploading and Loding Picture ...(0/1)
United Kingdom


So i have some code to execute a waypoint mission, the code runs and it seems to get loaded to the drone but nothing happens. Any help understanding what im doing wrong as well as how i can fix that would be greatly appreciated.

func waypointMission() -> DJIWaypointMission? {

           /// Define a new object class for the waypoint mission
           let mission = DJIMutableWaypointMission()
           print("mission activated")
           mission.maxFlightSpeed = 15 // user can speed up flight by holding the stick up this is the limit of the added acceleration
           mission.autoFlightSpeed = 8 // the flight speed the drone will travel at
           mission.finishedAction = .goHome // when the mission is finished the drone will return home
        mission.headingMode = .auto
           mission.flightPathMode = .normal
           mission.rotateGimbalPitch = false /// Change this to True if you want the camera gimbal pitch to move between waypoints
           mission.exitMissionOnRCSignalLost = true
           mission.gotoFirstWaypointMode = .pointToPoint
           mission.repeatTimes = 0

           /// Keep listening to the drone location included in latitude and longitude
         guard let droneLocationKey = DJIFlightControllerKey(param: DJIFlightControllerParamAircraftLocation) else {
            return nil
       guard let droneLocationValue = DJISDKManager.keyManager()?.getValueFor(droneLocationKey) else {
               return nil
           let droneLocation = droneLocationValue.value as! CLLocation
           let droneCoordinates = droneLocation.coordinate
           /// Check if the returned coordinate value is valid or not
           if !CLLocationCoordinate2DIsValid(droneCoordinates) {
               return nil
           mission.pointOfInterest = droneCoordinates

        let loc1 = CLLocationCoordinate2D(latitude: pointList[0].position.latitude, longitude: zeusPointList[0].position.longitude)
           let waypoint1 = DJIWaypoint(coordinate: loc1)

           waypoint1.altitude = 2.0 /// The altitude which the drone flies to as the first point and should be of type float
           waypoint1.heading = 0 /// This is between [-180, 180] degrees, where the drone moves when reaching a waypoint. 0 means don't change the drone's heading
           waypoint1.actionRepeatTimes = 1 /// Repeat this mission just for one time
           waypoint1.actionTimeoutInSeconds = 60
           // waypoint1.cornerRadiusInMeters = 5
           waypoint1.turnMode = .clockwise /// When the drones changing its heading. It moves clockwise
           waypoint1.gimbalPitch = 0 /// This is between [-90, 0] degrees, if you want to change this value, then change rotateGimbalPitch to True. The drone gimbal will move by the value when the drone reaches its waypoint
           waypoint1.speed = 0.5 /// Note that this value does not make the drone move with speed 0.5 m/s because this is an error from the firmware and can't be fixed. However, we need to trigger it to be able to change the next one

        let loc2 = CLLocationCoordinate2DMake(pointList[1].position.latitude, zeusPointList[1].position.longitude)
           let waypoint2 = DJIWaypoint(coordinate: loc2)
           waypoint2.altitude = 15.0 /// should be of type float
           waypoint2.heading = 0
           waypoint2.actionRepeatTimes = 1
           waypoint2.actionTimeoutInSeconds = 60
           waypoint2.cornerRadiusInMeters = 5
           waypoint2.turnMode = .clockwise
           waypoint2.gimbalPitch = 0
           /// Chnage the velocity of the drone while moving to this waypoint
           waypoint2.speed = 0.5


        if let error =  DJISDKManager.missionControl()?.waypointMissionOperator().load(mission) {
        DJISDKManager.missionControl()?.waypointMissionOperator().addListener(toUploadEvent: self, with: DispatchQueue.main){
            error in

           print("running mission", mission)
           return DJIWaypointMission(mission: mission)


5-25 07:49
Use props
You need to log in before you can reply Login | Register now

Credit Rules