简体   繁体   English

DJI Waypoint 任务监听器

[英]DJI Waypoint mission listeners

I need to create/upload/start waypoint mission on one button.我需要一键创建/上传/启动航点任务。 When user press button drone should move up for certain number of point based on current position.当用户按下按钮时,无人机应根据当前位置向上移动一定数量的点。 User can stop mission and again start new one.用户可以停止任务并重新开始新的任务。 My logic here is next:我的逻辑是:

  1. I initialize mission with points我用积分初始化任务
  2. Load mission加载任务
  3. Add Listeners to mission operator将侦听器添加到任务操作员
  4. Upload mission上传任务
  5. Mission starts on listener任务从听众开始
missionOperator.addListener(toUploadEvent: self, with: DispatchQueue.main) { (event) in
    if event.currentState == .readyToExecute {
        self.startMission()
    }
}

I'm reading documentation for days and trying to understand how this thing work, but I'm missing something obviously.我正在阅读文档好几天并试图了解这件事是如何工作的,但我显然错过了一些东西。 Listeners are created on waypoint mission operator, but if I create listeners before loading mission they are not called.侦听器是在航点任务操作员上创建的,但是如果我在加载任务之前创建侦听器,则不会调用它们。 If I create listeners every time I load mission, startMission() is called multiple times (first time is called ones, but after one mission is stopped or finished, next time startMission() gets called two times)如果我每次加载任务时都创建侦听器,则 startMission() 被多次调用(第一次被调用,但在一个任务停止或完成后,下一次 startMission() 被调用两次)

So, I guess that my questions would be: What is right moment to add listeners and to remove them since I'm calling startMission() from listeners?所以,我想我的问题是:什么时候添加侦听器并删除它们,因为我从侦听器调用 startMission()? Actually what is appropriate way to init/upload/start mission on one button, and be able to do that multiple times?实际上,什么是一键初始化/上传/启动任务的合适方法,并且能够多次执行此操作?

You need to remove the upload listener when the the upload succeeded and the event state is readyToExecute.当上传成功且事件状态为readyToExecute时,您需要移除上传监听器。 Also when the event contains an error, or the state is readytoupload/notsupported/disconnected.此外,当事件包含错误或状态为准备上传/不支持/断开连接时。 Pretty much in every case except when it's still in the state 'uploading'.几乎在所有情况下,除非它仍处于“上传”状态。

When you start the mission, add a listener for execution events, and one for finished.当您开始任务时,为执行事件添加一个侦听器,并为完成事件添加一个侦听器。 Remove those again when the mission is stopped/cancelled, has an error, or finishes successfully.当任务停止/取消、出现错误或成功完成时,再次删除它们。

Even though you use Swift, I suggest looking at the more complete Objective C sample code, which includes examples of several different types of missions.即使您使用 Swift,我还是建议您查看更完整的 Objective C 示例代码,其中包括几种不同类型任务的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM