Reputation: 21
I want to get the update of the Compass of my P4 RTK with my Mobile SDK for iOS, but I am not getting any output in the terminal.
I am using SwiftUI on Xcode.
This is the code I am using.
if let locationKey = DJIFlightControllerKey(param: DJIFlightControllerParamCompassHeading) {
DJISDKManager.keyManager()?.startListeningForChanges(on: locationKey, withListener: self, andUpdate: { (oldValue: DJIKeyedValue?, newValue: DJIKeyedValue?) in
if (newValue != nil) {
print("Compass: \(newValue!.doubleValue)")
}
})
}
If I unterstand the code startListeningForChanges right, I should get an print output, when I rotate the drone?
Upvotes: 2
Views: 134
Reputation: 903
Please try to get the compass value by implementing DJICompassDelegate.didUpdateSensorState
, e.g.
class CompassDelegate: DJICompassDelegate {
var sensorValue: Float = 0.0
...
func compass(_ compass: DJICompass, didUpdateSensorState state: DJICompassState) {
if self.sensorValue != state.sensorValue
&& state.index == 0 { // depending on your drone model there might be multiple compasses as far as I understood
self.sensorValue = state.sensorValue
}
}
}
Somewhere in your code where you have your instance of DJIFlightController you need to set an instance of this compass delegate, e.g.
myFlightController.compass?.delegate = myCompassDelegate
Upvotes: 0