访问 swift 中的状态信息 - DJI Mobile SDK iOS

Accessing state information in swift - DJI Mobile SDK iOS

我不知道如何获取简单的状态数据,例如当前的万向节俯仰角。

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

Class GimbalState has member 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状态委托函数获取当前云台俯仰角

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)
  }
}