快速访问状态信息 - DJI Mobile SDK iOS

安德烈亚斯·吉辛

我无法理解如何获取简单的状态数据,例如当前的万向节间距。

我还没有发现 DJI SDK 和 xcode 中实际工作的东西之间有牢固的联系。SDK 给了我提示,并与 xcode 自动完成一起慢慢前进。

类 GimbalState 有成员 getAttitudeInDegrees(),其描述为:“当前的万向节姿态(以度为单位)。如果万向节与飞机水平并指向北极的前方,则滚转、俯仰和偏航为 0。” - 伟大的!

但是,它不会在 xcode 中自动完成,也不会编译。

测试的其他方法:

var gimbalStateInformation = DJIGimbalState()
    print(gimbalStateInformatoin.attitudeInDegrees.pitch.description)

--> 所有俯仰滚转和偏航值都显示为 0.0

var gimbalStateInformation = DJUGimbalAttitude()
    print(gimbalStateInformatoin.pitch.description)

--> 所有俯仰滚转和偏航值都显示为 0.0

我试图通过密钥获取信息,但是当我运行代码时,我的应用程序崩溃了。

func getGimbalAttitude(){
    // Get the key
    guard let gimbalAttitudeKey = DJIGimbalKey(param: DJIGimbalParamAttitudeInDegrees) else {
        print("Could not create DJIGimbalParamAttitudeInDegrees key")
        return
    }
    // Get the keyManager
    guard let keyManager = DJISDKManager.keyManager() else {
        print("Could not get the key manager, manke sure you are registered")
        return
    }
    // Test if key is available
    let testing = keyManager.isKeySupported(gimbalAttitudeKey)
    self.statusLabel.text = String(testing)    // This comes out true

    // Use key to retreive info
    let gimbalAttitudeValue = keyManager.getValueFor(gimbalAttitudeKey)
    let gimbalAttitude = gimbalAttitudeValue?.value as! DJIGimbalState
    _ = gimbalAttitude.attitudeInDegrees.pitch
// --> Application crashes on the line above
}

我正在为 Mavic Mini 努力。

请概括地告知如何将 DJI Mobile SDK 连接到 Swift,特别是我如何读出当前的云台俯仰值。

布赖恩·克里恩

您可以通过其 didUpdate 状态委托函数访问当前的 Gimbal 音高

import DJISDK
class GimbalController: NSObject, DJIGimbalDelegate {
  let gimbal: DJIGimbal
    init(gimbal: DJIGimbal) {
      self.gimbal = gimbal
      super.init()
      gimbal.delegate = self
    }

    func gimbal(_ gimbal: DJIGimbal, didUpdate state: DJIGimbalState) {
            print(state.attitudeInDegrees.pitch)
    }
}

// create an instance of the custom gimbal controller in some other class
// and pass it the gimbal instance
if let aircraft = DJISDKManager.product() as? DJIAircraft {
  if let gimbal = aircraft.gimbal {
    let gimbalController = GimbalController(gimbal: gimbal)
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章