简体   繁体   中英

DJI sdk get RTK information

I am trying to get the gps information from the RTK in DJI M600 Pro by using an ios app, I have looked at DJI Mobile SDK API reference, and I have found some RTK API . When the drone is starting up, the property "isRTKBeingUsed" should be "YES" ,but I can't get the result.

Any help would be greatly appreciated! Here is my code:

#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

TLDR: You are using the RTK delegate method the wrong way.

didUpdateState: is a delegate method. You need to pass a delegate object to your RTK object. When data comes from the aircraft, didUpdateState will be called. You don't have to do it manually.

Furthermore, you shouldn't init your own RTK object:

1/ Once you have confirmation the SDK has registered (delegate method of DJISDKManager), get the product

- (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/ Verify it's a DJIAircraft class

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/ Get the RTK object from there:

DJIRTK *rtk = aircraft.flightController.RTK;

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

4/ Set the delegate to RTK (a class that implemented DJIRTKDelegate - assuming self here)

rtk.delegate = self;

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

5/ Get the data in the delegate method like you did.

- (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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM