2017-02-05 9 views
0

DJIWaypointMissionを開始しようとしていて、 "startMissionExecutionWithCompletion"を呼び出すとエラーが発生しています。私は明らかにprepareMissionを使用して無人機にミッションをアップロードしました。DJI SDK "ホームポイントはまだ記録されていません。"エラーコード:-5010

私に与えるエラーは、「ホームポイントはまだ記録されていません」です。私は、ホームポイントを設定する方法のドキュメントを見て、何も見つからなかったので、DJIMissionManagerオブジェクトのリストされたメソッドとDJIWayPointObjectを無駄にスキャンしました。私はまた無人機の現在の状態から取られた "aircraftLocation"を追加しようとしました。

以下はコードです。

import UIKit 
import MapKit 
import CoreLocation 
import DJISDK 
import Foundation 

class FlyToPointsViewController: DJIBaseViewController, DJIFlightControllerDelegate, DJIMissionManagerDelegate { 

    @IBOutlet weak var mapView: MKMapView! 

    var mission: DJIWaypointMission? = nil 
    var flightController: DJIFlightController?=nil 
    var missionCoordinates=[CLLocationCoordinate2D]() 
    var allSteps = [DJIWaypoint]() 
    var missionManager: DJIMissionManager?=nil 
    var currentState: DJIFlightControllerCurrentState?=nil 

    override func viewDidAppear(animated: Bool) { 
     let alertController = UIAlertController(title: "Hello Team", message: 
      "There are quite a few easter eggs hidden away in here. Hopefully you find them and have a good laugh. Sorry I couldn't make it to test, the mountains are calling. But I put alot of time into this so hopefully it works as expected. I didn't add a return to home functionality to make this a bit spicy for ya so make sure your last point is near you other wise you're gonna do a bit of walking... Cheers ", preferredStyle: UIAlertControllerStyle.Alert) 
     alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil)) 
     self.presentViewController(alertController, animated: true, completion: nil) 

    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 


     //initialize our aircraft 
     mapView.delegate=self 

     let aircraft: DJIAircraft? = self.fetchAircraft() 
     if aircraft != nil { 
      //makes the view controller watch for particular functions like the flight controller one below 
      aircraft!.delegate = self 
      aircraft!.flightController?.delegate = self 
     } 
     else{ 
      print("aircraft not found") 
     } 

     self.missionManager=DJIMissionManager.sharedInstance() 
     self.missionManager?.delegate=self 

     //initialize core location to put mapp on our location 
     let manager = CLLocationManager() 
     if CLLocationManager.authorizationStatus() == .NotDetermined { 
      manager.requestAlwaysAuthorization() 
     } 


     //start uploading location into manager object so we can use .location method 
     if CLLocationManager.locationServicesEnabled() { 
      manager.startUpdatingLocation() 
     } 

     //let location = manager.location!.coordinate; //get ipads current location and turn it into a coordinated 

     let location = CLLocationCoordinate2DMake(40.0150, -105.2705) 

     let region = MKCoordinateRegionMakeWithDistance(location, 7000, 7000) //create a square region using center point and size of square 
     mapView.region = region //tells the mapview to center itself around this region 

     // Do any additional setup after loading the view. 


    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 
    override func viewWillDisappear(animated: Bool) { 

     let aircraft: DJIAircraft? = self.fetchAircraft() 
     if aircraft != nil { 
      if aircraft!.flightController?.delegate === self { 
       aircraft!.flightController!.delegate = nil 
      } 
     } 

    } 



    @IBAction func revealRegionDetailsWithLongPressOnMap(sender: UILongPressGestureRecognizer) { 
     if sender.state != UIGestureRecognizerState.Began { return } 
     let touchLocation = sender.locationInView(mapView) 
     let locationCoordinate = mapView.convertPoint(touchLocation, toCoordinateFromView: mapView) 
     self.missionCoordinates.append(locationCoordinate) 

     print("Tapped at lat: \(locationCoordinate.latitude) long: \(locationCoordinate.longitude)") 
     let annotation = CustomMissionPressLocation(location: locationCoordinate) 
     mapView.addAnnotation(annotation) 
    } 

    //Mark: - Functions Called from Button Presses 
    @IBAction func clearCoordinates(sender: AnyObject) { 

     self.missionCoordinates=[] 
     mapView.removeAnnotations(mapView.annotations) 

    } 


    @IBAction func startMission(sender: AnyObject) { 
     if (!self.missionCoordinates.isEmpty){ 
      print("start Mission Attempted") 
      self.mission = DJIWaypointMission() 
      self.mission!.autoFlightSpeed=10 
      self.mission!.maxFlightSpeed=15 
      self.mission!.exitMissionOnRCSignalLost=true 
      let waypoint = DJIWaypoint(coordinate: (self.currentState?.aircraftLocation)!) 

      waypoint.altitude=15 
      waypoint.speed=10 
      waypoint.heading=0 
      waypoint.actionRepeatTimes = 1 
      waypoint.actionTimeoutInSeconds = 60 
      waypoint.cornerRadiusInMeters = 5 
      waypoint.turnMode = DJIWaypointTurnMode.Clockwise 
      self.mission!.addWaypoint(waypoint) 

      for locations in self.missionCoordinates{ 
       let waypoint = DJIWaypoint(coordinate: locations) 
       waypoint.altitude=15 
       waypoint.speed=10 
       waypoint.heading=0 
       waypoint.actionRepeatTimes = 1 
       waypoint.actionTimeoutInSeconds = 60 
       waypoint.cornerRadiusInMeters = 5 
       waypoint.turnMode = DJIWaypointTurnMode.Clockwise 

       self.mission!.addWaypoint(waypoint) 
      } 
      let waypointStep = DJIWaypointStep(waypointMission: self.mission!) 


     self.startWayPointMission() 
     } 

     else{ 
      let alertController = UIAlertController(title: "Mission Error", message: 
       "you haven't added any waypoints ya dingus", preferredStyle: UIAlertControllerStyle.Alert) 
      alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil)) 
      self.presentViewController(alertController, animated: true, completion: nil) 

     } 
    } 

    //avoids a bunch of knuckleheads from sending the drone to china 
    func missionIsntTooFar()-> Bool{ 
     let startLoc=self.currentState?.aircraftLocation 
     let locations = self.missionCoordinates 
     //let startLoc=locations[0] 

     for locs in locations{ 
      let distance = MKMetersBetweenMapPoints(MKMapPointForCoordinate(startLoc!), MKMapPointForCoordinate(locs)) 
      if distance > 4000{ 
       return false 
      } 
     } 
     return true 
    } 
    func startWayPointMission() { 
     if self.missionIsntTooFar(){ 
      self.missionManager?.prepareMission(self.mission!, withProgress: nil, withCompletion: {[weak self] 
       (error: NSError?) -> Void in 
       if error == nil { 

        print("uploaded") 

        print(String(self?.missionManager?.isMissionReadyToExecute)) 
        self?.missionManager?.startMissionExecutionWithCompletion({[weak self] 
         (error: NSError?)->Void in 

         if error == nil{ 
          print("mission started") 
         } 
         else{ 
          print("error: \(error!)") 
         } 
         }) 
       } 
       else { 
        self?.showAlertResult("mission upload failed \(error!)") 
       } 
       }) 
     } 

     else{ 
      mapView.removeAnnotations(mapView.annotations) 

      let alertController = UIAlertController(title: "Mission is too far", message: 
       "you're trying to fly the drone too far ya knucklehead", preferredStyle: UIAlertControllerStyle.Alert) 

      alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil)) 
      self.presentViewController(alertController, animated: true, completion: nil) 
     } 

    } 

    //Mark: - Flight Controller Delegate Methods 

    func flightController(fc: DJIFlightController, didUpdateSystemState state: DJIFlightControllerCurrentState) { 
     self.flightController=fc 
     self.currentState=state 
    } 

    /* 
    // MARK: - Navigation 

    // In a storyboard-based application, you will often want to do a little preparation before navigation 
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
     // Get the new view controller using segue.destinationViewController. 
     // Pass the selected object to the new view controller. 
    } 
    */ 

} 
extension FlyToPointsViewController: MKMapViewDelegate{ 
    func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 
     let annotationView = DroneAnnotationView(annotation: annotation, reuseIdentifier: "Attraction") 
     annotationView.canShowCallout = false //we're going to customize the callout 
     return annotationView 
    } 

} 

私は数時間立ち往生していましたが、誰かがこれを以前に見ていたと思っていました。いつものように、私が問題を解決したら、私はこことDJIのフォーラムに解決策を掲載します。

私は夜でもそれを呼んでいます。だから、二つのことが

A)

self.flightController?.setHomeLocationUsingAircraftCurrentLocationWithCompletion(nil) 


self.mission!.finishedAction=DJIWaypointMissionFinishedAction.GoHome 

B)

間違っていたように見え

乾杯

+0

HmmmかなりクールなdjiにはAPIがあります。 –

+0

そうです。実際にはかなり強力です。あなたが本当にそれに乗りたいなら、あなたは何千ものために穀物を買うことができます。そしてあなたは機内のコンピュータとガイダンスシステムをコーディングすることができます。 また、Pythonでコーディングできる3DRソロに行くことができ、簡単にアクセス可能な入力と出力を備えたプログラマブルなオンボードコンピュータが付属しています –

答えて

0

もドローンを使用すると、ミッションをアップロードする前に離陸していなければなりませんしたがって、電話

 self.flightController?.takeoffWithCompletion({[weak self] 
ミッションをアップロードしようとする前に

P.S.何らかの理由で、それが有効な任務であるために少なくとも2つのウェイポイントを与える必要があります。

いいえお返事

0

航空機の原点を手動で設定する必要はありませんでした。しかし、無人機が十分なGPS修正を得てそれ自体を設定するまで待つ必要があります。

DJIFlightControllerDelegate didUpdate:stateメソッドを実装すると、state.homeLocationがまだ設定されているかどうかを確認できます。

また、離陸前に無人機にミッションをアップロードしても、回転機を回転させないでください。あなたがミッションを始めたとき、それはあなたのために行います。

関連する問題