I'm having a really bad time trying to use the DJI-SDK for iOS in Swift.
This SDK is written in Objective-c and uses a key - value system to store values and send commands to the drone, so if y need to tell the drone to enable the virtual sticks you need to execute something like this:
DJISDKManager.keyManager()?.setValue(true as NSNumber, for: enableVirtualStickModeKey!, withCompletion: { (error) in......
This is pretty straightforward because our value is a Bool
cast to NSNumber
, the problems begin when I need to send struct values like a position of the virtual stick (Objective-c struct), this is an example of a value to make the drone ascend at 1 m/s:
var controlData = DJIVirtualStickFlightControlData()
controlData.verticalThrottle = 1
controlData.pitch = 0
controlData.roll = 0
controlData.yaw = 0
DJISDKManager.keyManager()?.setValue(controlData, for: virtualSticksKey!, withCompletion: { (error) in..
But the SDK fails with an error trying to set the values. I wrote to the DJI support team and the answer was that they hope the community can help me solve the problem....
The question is what type of cast I need to make to translate this DJIVirtualStickFlightControlData
object to an Objective-C compatible type?
This is the DJIVirtualStickFlightControlData
definition from DJIFlightControllerBaseTypes.h
typedef struct
{
float pitch;
float roll;
float yaw;
float verticalThrottle;
} DJIVirtualStickFlightControlData;
And this is the definition of the setValue method from DJIKeyManager.h
/**
* Performs a set on a settable key, changing attributes on the connected product.
*
* @param value A value object relevant to the given key
* @param key A valid settable key
* @param completion A set completion block.
*/
- (void)setValue:(id)value
forKey:(DJIKey *)key
withCompletion:(DJIKeyedSetCompletionBlock)completion;