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 using DJIStick class as a reference from the documentation but I could not handle that correctly!
I have achieved listening to the change in the sticks using the following logic:
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 } }
let remote = self.fetchRemoteController()
remote?.delegate = self
Now, the following function should be triggered automatically when a change occurs the sticks
func remoteController(_ rc: DJIRemoteController, didUpdate state:
DJIRCHardwareState) {
if state.rightStick.verticalPosition > 0 || state.rightStick.verticalPosition < 0 || state.rightStick.horizontalPosition > 0 || state.rightStick.horizontalPosition < 0 || state.leftStick.verticalPosition > 0 || state.leftStick.verticalPosition < 0 || state.leftStick.horizontalPosition > 0 || state.leftStick.horizontalPosition < 0 {
print("Detected move in Sticks while mission is started so stop the mission")
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)")
}
}