DJI SDK获取RTK信息

时间:2018-07-12 04:25:40

标签: ios objective-c dji-sdk

我正在尝试使用ios应用从DJI M600 Pro中的RTK获取gps信息,查看了DJI Mobile SDK API参考,并找到了一些RTK API。无人机启动时,属性“ isRTKBeingUsed”应为“ YES”,但我无法得到结果。

任何帮助将不胜感激!这是我的代码:

#import "ViewController.h"
#import <DJISDK/DJISDK.h>
#import "DJIAppActivationManager_InternalTesting.h"
#import<DJISDK/DJIRTK.h>        

#define WeakRef(__obj) __weak typeof(self) __obj = self
#define WeakReturn(__obj) if(__obj ==nil)return;

void ShowResult(NSString *format, ...)
{...
}

@interface ViewController ()<DJIAppActivationManagerDelegate, DJISDKManagerDelegate,DJIRTKDelegate>     
...
...
@property (weak, nonatomic) IBOutlet UILabel *isusing;        
@property(strong, nonatomic) DJIRTK * rtk1;                  
@property(strong, nonatomic) DJIRTKState * rtkstate1;  

@end

@implementation ViewController

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self registerApp];
    [self updateUI];

    self.rtk1 = [[DJIRTK alloc] init];
    self.rtkstate1 = [[DJIRTKState alloc] init];
    [self rtk:_rtk1 didUpdateState:_rtkstate1];  


}

- (void)viewDidLoad {
    [super viewDidLoad];
}


-(void) rtk:(DJIRTK *)rtk didUpdateState:(DJIRTKState *)state      
{
    self.shifoushiyong.text = [NSString stringWithFormat:@"%d",state.isRTKBeingUsed];  

}



- (void)registerApp
{
    [DJISDKManager registerAppWithDelegate:self];
}

-(void)updateUI 
{
  ...   
}

...

@end

1 个答案:

答案 0 :(得分:2)

TLDR:您使用的RTK委托方法错误。

didUpdateState:是一个委托方法。您需要将一个委托对象传递给您的RTK对象。当数据来自飞机时,didUpdateState将被调用。您不必手动执行。

此外,您不应该初始化自己的RTK对象:

1 /确认SDK已注册(DJISDKManager的委托方法)后,获取产品

- (void)appRegisteredWithError:(NSError *_Nullable)error {
  DJISDKManager.product
  // continue here
}

https://developer.dji.com/api-reference/ios-api/Components/SDKManager/DJISDKManager.html#djisdkmanager_product_inline

2 /确认它是DJIAircraft类

if ([[DJISDKManager.product class] isKindOf:[DJIAircraft class]) {
    // Continue here
}

https://developer.dji.com/api-reference/ios-api/Products/Aircraft/DJIAircraft.html?search=djiaircraft&i=0&

3 /从那里获取RTK对象:

DJIRTK *rtk = aircraft.flightController.RTK;

https://developer.dji.com/api-reference/ios-api/Components/FlightController/DJIFlightController.html#djiflightcontroller

4 /将委托设置为RTK(实现DJIRTKDelegate的类-在此假设自己)

rtk.delegate = self;

https://developer.dji.com/api-reference/ios-api/Components/RTK/DJIRTK.html#djirtk_protocol_inline

5 /像以前一样在委托方法中获取数据。

- (void)rtk:(DJIRTK *_Nonnull)rtk didUpdateState:(DJIRTKState *_Nonnull)state {
 // Show me the data
}

https://developer.dji.com/api-reference/ios-api/Components/RTK/DJIRTK.html#djirtk_updatertkstate_inline