菜鸟教程小白 发表于 2022-12-11 20:07:49

ios - DJI 虚拟摇杆控制未正确应用


                                            <p><p>我正在构建一个无人机应用程序,它将发送室内飞行的飞行命令。我正在实现 <a href="https://developer.dji.com/mobile-sdk/documentation/introduction/component-guide-flightController.html#virtual-sticks" rel="noreferrer noopener nofollow">here</a> 中描述的 DJI Mobile SDK 的虚拟摇杆.</p>

<p>试用大疆模拟器教程后发现<a href="https://developer.dji.com/mobile-sdk/documentation/ios-tutorials/SimulatorDemo.html#implementing-virtualstickview" rel="noreferrer noopener nofollow">here</a> ,我为我的应用程序实现了一个精简的非模拟版本。当我在户外测试我的应用程序时,控件始终如一且正确地工作。</p>

<p>但是,当我进入室内时,无论发送什么命令,无人机都只执行 1 个 Action :无人机向左后螺旋桨的方向飞行。即使命令只是转动无人机,无人机也会一直朝这个方向飞行。</p>

<p>任何想法可能会发生什么?我不确定要发布什么代码,因为我的代码可以在户外使用。</p>

<p><strong>更新 #1</strong></p>

<p>这是我的飞行 Controller 设置(在 Swift 中实现):</p>

<pre><code>self.flightController = (DJISDKManager.product() as? DJIAircraft)?.flightController

self.flightController?.rollPitchControlMode = DJIVirtualStickRollPitchControlMode.velocity
self.flightController?.yawControlMode = DJIVirtualStickYawControlMode.angle
self.flightController?.rollPitchCoordinateSystem = DJIVirtualStickFlightCoordinateSystem.body
</code></pre>

<p><strong>更新 #2</strong></p>

<p>更改偏航的代码(带有一些硬编码的数字)。基本上是用来让无人机完全掉头的。</p>

<pre><code>private var turnTime = 0
private var turnTimer: Timer? = nil

func turn() {
    self.turnTimer = Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: (#selector(turnDroneCommand)), userInfo: nil, repeats: true)
}

@objc func turnDroneCommand() {
    self.turnTime += 1

    let data = DJIVirtualStickFlightControlData(pitch: 0, roll: 0, yaw: Float(180), verticalThrottle: 0)

    self.flightController.send(data, withCompletion: { (error) in
      if error != nil {
            // Fire custom error callback
      }
    })

    if self.turnTime &gt;= 7 {
      self.turnTimer?.invalidate()
      self.turnTime = 0
      // Fire custom success callback
    }
}
</code></pre>

<p>我已经实现了一种几乎相同的方法来改变音高。如前所述,两个命令的当前结果没有什么不同。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在与 DJI 的开发人员进行了长时间的反复讨论后,我现在可以提供部分解决方案。</p>

<p><strong>部分解决方案</strong></p>

<p>如果您查看问题更新 #2 中提供的代码,您会注意到以下几行:</p>

<pre><code>self.turnTimer = Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: (#selector(turnDroneCommand)), userInfo: nil, repeats: true)
</code></pre>

<p>和</p>

<pre><code>self.turnTime += 1
...
if self.turnTime &gt;= 7 {
    self.turnTimer?.invalidate()
    self.turnTime = 0
    // Fire custom success callback
}
</code></pre>

<p>timeInterval 参数设置为 0.2 秒。这意味着命令以 5Hz 的频率发送不到 2 秒。根据 DJI 的开发人员的说法,命令需要以 10Hz(或更高,但我尚未验证)的频率发送<strong>更长</strong>然后 2 秒。</p>

<p><strong>突出问题</strong></p>

<p>在执行虚拟摇杆命令之前,Matrice 100 (M100) 仍会向左后螺旋桨“漂移”。 DJI 的开发人员似乎无法使用 M100,也无法自行测试。由于它似乎(基于非常非常有限的测试)是 M100 独有的问题,因此可能不是 Mobile SDK 本身的问题。</p>

<p>我将此标记为答案,以防有人偶然发现另一台 DJI 无人机的“忽略命令”问题。如果找到了漂移的解决方案,我会相应地更新。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - DJI 虚拟摇杆控制未正确应用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/50177654/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/50177654/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - DJI 虚拟摇杆控制未正确应用