dji-sdk / Mobile-SDK-iOS

DJI Mobile SDK for iOS: http://developer.dji.com/mobile-sdk/
Other
577 stars 256 forks source link

DJI Remote Controller did Update State problem!!?? #409

Closed alzin closed 3 years ago

alzin commented 3 years ago

I need help in triggering an action when a change in the sticks of the remote controller of the drone is held. Actually, I want to stop the timeline mission of the drone automatically when a user starts playing with the sticks.

I think I need to keep listening to the sticks values of the drone and I am trying to listen to (DJI Remote Controller did Update State) but I can't make it happened. I don't know maybe because I miss initializing something or I need to use a different method!?

 func remoteController(_ rc: DJIRemoteController, didUpdate state: DJIRCHardwareState) {
        print("Right Stick vertical position is \(state.rightStick.verticalPosition) and horizontal position \(state.rightStick.horizontalPosition)")
        print("Left Stick Value is \(state.leftStick.verticalPosition) and horizontal position \(state.leftStick.horizontalPosition)")
    }

Working Environment:

macOS Big Sur Xcode 12.2 Swift 5

dji-dev commented 3 years ago

Agent comment from Luce Luo in Zendesk ticket #41507:

Dear Customer,

Thank you for contacting DJI. Sorry, but have you ensure you have set the delegate first? The update callback will work after it.

Thanks,

Luce Luo DJI Developer Support
inline-94991270.png

alzin commented 3 years ago

Thank you for your prompt answer and support!

I was actually setting the delegate but it was at the beginning of the program in the viewDidLoad function which returned nil for the Remote Controller in the following function

class ViewController: DJIRemoteControllerDelegate {

func fetchRemoteController() -> DJIRemoteController? {
        if !(DJISDKManager.product() != nil){
            return nil
        }
        if DJISDKManager.product() is DJIAircraft {
            return (DJISDKManager.product() as! DJIAircraft).remoteController
        }
        return nil
    }

and then after the timeline mission has started I call the previous function and get the delegate of the controller correctly

let rem = self.fetchRemoteController()
rem?.delegate = self
dji-dev commented 3 years ago

Agent comment from Luce Luo in Zendesk ticket #41507:

Dear Customer,

Thank you for contacting DJI. The code is right but not sure the root cause. Can you please fill in the below form with more detail? We will handle it soon after we received the detail. https://formcrafts.com/a/dji-developer-feedback-en

Thanks,

Luce Luo DJI Developer Support