     fileprivate var paused = false
     
     func cancelMissionSaid() {
-        //need to define DJIWaypointMissionOperator
-        //var oper: DJIWaypointMissionOperator
-        
-        
-        print("Mission Cancelled !")
-        DJISDKManager.missionControl()?.stopTimeline()
+        //stop executing or paused mission
+        if missionState == DJIWaypointMissionState.executing || missionState == DJIWaypointMissionState.executionPaused
+        {
+            missionManager?.stopMission(completion: { (error) in
+                if error != nil {
+                    self.showAlertResult(info: "Stop mission error: " + (error?.localizedDescription)!)
+                }
+                else {
+                    self.showAlertResult(info: "Stop mission successful!" )
+                }
+            })
+        }
+        else {
+            self.showAlertResult(info: "Mission is not in executing or paused state !" )
+        }
+        //DJISDKManager.missionControl()?.stopTimeline()
     }
     func pauseMissionSaid(){
-        print("Mission paused !")
-        DJISDKManager.missionControl()?.stopTimeline()
-        // DJISDKManager.missionControl()?.pauseTimeline()
-        
+
+        if missionState == DJIWaypointMissionState.executing {
+            missionManager?.pauseMission(completion: { (error) in
+                if error != nil {
+                    self.showAlertResult(info: "Pause mission error: " + (error?.localizedDescription)!)
+                }
+                else {
+                    self.showAlertResult(info: "Pause mission successful!" )
+                }
+            })
+        }
+        else {
+            self.showAlertResult(info: "Mission is not in executing state!")
+        }
+        
+        //DJISDKManager.missionControl()?.stopTimeline()
     }
     func resumeMissionSaid(){
-        print("Mission resume !")
-        DJISDKManager.missionControl()?.resumeTimeline()
+        
+        //you can only call when current state is paused
+        if missionState == DJIWaypointMissionState.executionPaused {
+            missionManager?.resumeMission(completion: { (error) in
+                if error != nil {
+                    self.showAlertResult(info: "Resume mission error: " + (error?.localizedDescription)!)
+                }
+                else {
+                    self.showAlertResult(info: "Resume mission successful")
+                }
+            })
+        }
+        else {
+             self.showAlertResult(info: "Mission is not in pause state")
+        }
+    
+        //DJISDKManager.missionControl()?.resumeTimeline()
     }
     func executeMission(){
-        print("Mission executed !")
-        if self.paused {
-            DJISDKManager.missionControl()?.resumeTimeline()
-        } else if self.started {
-            DJISDKManager.missionControl()?.pauseTimeline()
-        } else {
-            DJISDKManager.missionControl()?.startTimeline()
-        }
+        if missionState == DJIWaypointMissionState.readyToExecute {
+            missionState = DJIWaypointMissionState.executing
+            missionManager?.startMission(completion: { (error) in
+                if error != nil {
+                    self.showAlertResult(info: "Execute mission error: " + (error?.localizedDescription)!)
+                }
+                else {
+                    self.showAlertResult(info: "Execute mission successful")
+                }
+            })
+        }
+
     }
     func convertMetersToPoint(m: Double) -> Double{
         var lonO:Double = 0.0

    //flight Controller
    var fc: DJIFlightController?
    var delegate: DJIFlightControllerDelegate?
    var aircraftLocation: CLLocationCoordinate2D? = nil
    
    //change DJIFlightControllerCurrentState to DJIFlightControllerState
    var currentState: DJIFlightControllerState? = nil
    var aircraft: DJIAircraft? = nil
    
    //mission variable
    var missionManager: DJIMissionControl?
    
    var hotpointMission: DJIHotpointMission = DJIHotpointMission()
    var mCurrentHotPointCoordinate: CLLocationCoordinate2D = kCLLocationCoordinate2DInvalid
    var locs: [CLLocationCoordinate2D] = []

                //get drone's location
                var droneLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(0, 0)
                
                //convert CLLocation to CLLocationCoordinate2D
                if let location1: CLLocation = currentState?.aircraftLocation {
                    aircraftLoc = location1.coordinate
                } else {
                    print("no location...")
                }
                
                if ((self.currentState != nil) && CLLocationCoordinate2DIsValid(aircraftLoc!)){
                //if ((self.currentState != nil) && CLLocationCoordinate2DIsValid(aircraftLocation!)){
                    droneLocation = aircraftLoc!
                    
                    //finding GPS location
                    let waypoint: DJIWaypoint = DJIWaypoint(coordinate: droneLocation)
                    waypoint.altitude = ALTITUDE
                    self.waypointMission.add(waypoint)
                }
                var lat: Double = droneLocation.latitude
                var long: Double = droneLocation.longitude
                
                var commLoc: CLLocationCoordinate2D = CLLocationCoordinate2DMake(0, 0)
                
                //is that NSEW direction ?
                if NSEW == true{
                    //if units are in meters
                    //convert all unit to GPS coordinate points
                    if units == "m" || units == "meter" || units == "meters" {
                        if direction == "east" {
                            long = long + convertMetersToPoint(m: distance)
                        }
                        if direction == "west" {
                            long = long - convertMetersToPoint(m: distance)
                        }
                        if direction == "noth" {
                            lat = lat + convertMetersToPoint(m: distance)
                        }
                        if direction == "south" {
                            lat = lat - convertMetersToPoint(m: distance)
                        }
                    }
                }
                else {
                    //if units are in meters
                    //convert all unit to GPS coordinate points
                    if units == "m" || units == "meter" || units == "meters" {
                        if direction == "right" {
                            long = long + convertMetersToPoint(m: distance)
                        }
                        if direction == "left" {
                            long = long - convertMetersToPoint(m: distance)
                        }
                        if direction == "up" {
                            lat = lat + convertMetersToPoint(m: distance)
                        }
                        if direction == "down" {
                            lat = lat - convertMetersToPoint(m: distance)
                        }
                        if direction == "forward" {
                            lat = lat + convertMetersToPoint(m: distance)
                        }
                        if direction == "backward" {
                            lat = lat - convertMetersToPoint(m: distance)
                        }
                    }
                }
                commLoc.latitude = lat
