Cannot get values using DJIGigibalParamAttitudeInDegrees
501 1 2022-7-21
Uploading and Loding Picture ...(0/1)
o(^-^)o
djiuser_J6OicdGZq6EN
lvl.1

Japan
Offline

I am developing an AR application using DJI.
As the title says, I am unable to get the values using DJIGigibalParamAttitudeInDegrees.
Version used:
  • Mac OS: Monterey 12.4
  • Xcode: 10.3
  • Swift 5.6.1
  • iOS: 11.0
  • DJI SDK iOS: 4.16.1

I was able to do the following:
  • Register DJI Mobile SDK and build the application using API key.
  • Get the drone's attitude using a listener.

To get the drone's attitude, I wrote the following code based on the sample code and it worked.

let aircraftAttitudeKey = DJIFlightControllerKey(param: DJIFlightControllerParamAttitude)
DJISDKManager.keyManager()?.startListeningForChanges(on: aircraftAttitudeKey!, withListener: self, andUpdate: {(oldValue: DJIKeyedValue?, newValue: DJIKeyedValue?) in
if newValue != nil {
    let aircraftaAttitudes = newValue!.value! as! DJISDKVector3D                    
    self.rollLabel.text = "Roll: \(aircraftaAttitudes.x)"
    self.pitchLabel.text = "Pitch: \(aircraftaAttitudes.y)"
    self.yawLabel.text = "Yaw: \(aircraftaAttitudes.z)"               
  }
)

In the same way, I'm trying to get the gimbal's attitude with the following code, but it does not work.

let gimbalAttitudeKey = DJIGimbalKey(param: DJIGimbalParamAttitudeInDegrees)
DJISDKManager.keyManager()?.startListeningForChanges(on: gimbalAttitudeKey!, withListener: self, andUpdate: {(oldValue: DJIKeyedValue?, newValue: DJIKeyedValue?) in
if newValue != nil {
    let gimbalAttitudes = newValue!.value! as! DJIGimbalAttitude
    self.gRollLabel.text = "Roll: \(gimbalAttitudes.roll)"
    self.gPitchLabel.text = "Pitch: \(gimbalAttitudes.pitch)"
    self.gYawLabel.text = "Yaw: \(gimbalAttitudes.yaw)"
  }
})



2022-7-21
Use props
tropical fish
lvl.1

Japan
Offline

I wanted to solve this problem, so I also submitted this to a Github issue.
https://github.com/dji-sdk/Mobile-SDK-iOS/issues/531

As a result, I found that I could get the Gimbal's attitude after writing the following code.

class DroneConnectionView: ..., DJIGimbalDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        let gimbal = fetchGimbal()
        if gimbal != nil {
            gimbal?.delegate = self
        }
    }
    func fetchGimbal() -> DJIGimbal? {
        guard let product = DJISDKManager.product() else {
            return nil
        }
        if product is DJIAircraft || product is DJIHandheld {
            return product.gimbal
        }
        return nil
    }
    func gimbal(_ gimbal: DJIGimbal, didUpdate state: DJIGimbalState) {
        self.RollLabel.text = "Roll: \(state.attitudeInDegrees.roll)"
        self.PitchLabel.text = "Pitch: \(state.attitudeInDegrees.pitch)"
        self.YawLabel.text = "Yaw: \(state.attitudeInDegrees.yaw)"
    }
}


Thank you ;)

BTW, I realized I titled this post incorrectly.  
I'll post the correct title so that people with the same problem can easily search for it.  

'Cannot get values using DJIGimibalParamAttitudeInDegrees'


2022-7-28
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules