问题
I am logging IMU Information from a DJI Drone via the iOS DJI UXSDKDemo. Using the method below, I am able to receive a log of the four desired values (IMU State, IMU Count, Gyroscope, and Accelerometer). When I run the app connected to a drone, however, the logs are stored, the logs from these flights list each of the four values as zero. The drone I am connecting the app to is not flying, yet even when I move the drone around, the values do not change.
Do I need to import any files to the DefaultLayoutViewController.m other than DefaultLayoutViewController.h?
Is my methodology incorrect?
- (void)showAlertViewWithMessage:(NSString *)message
{
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController* alertViewController = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertViewController addAction:okAction];
UIViewController *rootViewController = [[UIApplication sharedApplication] keyWindow].rootViewController;
[rootViewController presentViewController:alertViewController animated:YES completion:nil];
//Printing Keys to Log; download logs from the page for this app on Itunes
DJIFlightControllerKey *IMUStateForLog = [DJIFlightControllerKey keyWithParam:DJIFlightControllerParamIMUState];
// Will get called once to get current value of the key
[[DJISDKManager keyManager] getValueForKey:IMUStateForLog withCompletion:^(DJIKeyedValue * _Nullable value, NSError * _Nullable error) {
}];
// Called only when the value for the key changes
[[DJISDKManager keyManager] startListeningForChangesOnKey:IMUStateForLog withListener:self andUpdateBlock:^(DJIKeyedValue * _Nullable oldValue, DJIKeyedValue * _Nullable newValue) {
NSLog(@"%@", IMUStateForLog);
NSLog(@"%@", DJIFlightControllerParamIMUState);
}];
DJIFlightControllerKey *IMUsCountForLog = [DJIFlightControllerKey keyWithParam:DJIFlightControllerParamIMUsCount];
// Will get called once to get current value of the key
[[DJISDKManager keyManager] getValueForKey:IMUsCountForLog withCompletion:^(DJIKeyedValue * _Nullable value, NSError * _Nullable error) {
}];
// Called only when the value for the key changes
[[DJISDKManager keyManager] startListeningForChangesOnKey:IMUsCountForLog withListener:self andUpdateBlock:^(DJIKeyedValue * _Nullable oldValue, DJIKeyedValue * _Nullable newValue) {
NSLog(@"%@", IMUsCountForLog);
NSLog(@"%@", DJIFlightControllerParamIMUsCount);
}];
DJIFlightControllerKey *IMUStateGyroscopeStateForLog = [DJIFlightControllerKey keyWithParam:DJIFlightControllerParamIMUStateGyroscopeState];
// Will get called once to get current value of the key
[[DJISDKManager keyManager] getValueForKey:IMUStateGyroscopeStateForLog withCompletion:^(DJIKeyedValue * _Nullable value, NSError * _Nullable error) {
}];
// Called only when the value for the key changes
[[DJISDKManager keyManager] startListeningForChangesOnKey:IMUStateGyroscopeStateForLog withListener:self andUpdateBlock:^(DJIKeyedValue * _Nullable oldValue, DJIKeyedValue * _Nullable newValue) {
NSLog(@"%@", IMUStateGyroscopeStateForLog);
NSLog(@"%@", DJIFlightControllerParamIMUStateGyroscopeState);
}];
DJIFlightControllerKey *IMUStateAccelerometerStateForLog = [DJIFlightControllerKey keyWithParam:DJIFlightControllerParamIMUAccelerometerState];
// Will get called once to get current value of the key
[[DJISDKManager keyManager] getValueForKey:IMUStateAccelerometerStateForLog withCompletion:^(DJIKeyedValue * _Nullable value, NSError * _Nullable error) {
}];
// Called only when the value for the key changes
[[DJISDKManager keyManager] startListeningForChangesOnKey:IMUStateAccelerometerStateForLog withListener:self andUpdateBlock:^(DJIKeyedValue * _Nullable oldValue, DJIKeyedValue * _Nullable newValue) {
NSLog(@"%@", IMUStateAccelerometerStateForLog);
NSLog(@"%@", DJIFlightControllerParamIMUAccelerometerState);
}];
});
}
EDIT/UPDATE: I implemented the suggested changes. Values are now printing, but they occur infrequently and seem different than the expected output of the accelerometer and gyroscope sensors. Shouldn't the accelerometer and gyroscope be outputting three values (x,y,z)? The code and a screenshot of the log can be found below. Any suggestions?
- (void)viewDidLoad
{
[super viewDidLoad];
//Please enter your App Key in the info.plist file.
[DJISDKManager registerAppWithDelegate:self];
//Printing Keys to Log; download logs from the page for this app on Itunes
//GYROSCOPE
DJIFlightControllerKey *IMUStateGyroscopeStateForLog = [DJIFlightControllerKey keyWithParam:DJIFlightControllerParamIMUStateGyroscopeState];
// Will get called once to get current value of the key
[[DJISDKManager keyManager] getValueForKey:IMUStateGyroscopeStateForLog withCompletion:^(DJIKeyedValue * _Nullable value, NSError * _Nullable error) {
}];
// Called only when the value for the key changes
[[DJISDKManager keyManager] startListeningForChangesOnKey:IMUStateGyroscopeStateForLog withListener:self andUpdateBlock:^(DJIKeyedValue * _Nullable oldValue, DJIKeyedValue * _Nullable newValue) {
NSLog(@"LOG: GYROSCOPE: %ld", newValue.integerValue);
}];
//ACCELEROMETER
DJIFlightControllerKey *IMUStateAccelerometerStateForLog = [DJIFlightControllerKey keyWithParam:DJIFlightControllerParamIMUAccelerometerState];
// Will get called once to get current value of the key
[[DJISDKManager keyManager] getValueForKey:IMUStateAccelerometerStateForLog withCompletion:^(DJIKeyedValue * _Nullable value, NSError * _Nullable error) {
}];
// Called only when the value for the key changes
[[DJISDKManager keyManager] startListeningForChangesOnKey:IMUStateAccelerometerStateForLog withListener:self andUpdateBlock:^(DJIKeyedValue * _Nullable oldValue, DJIKeyedValue * _Nullable newValue) {
NSLog(@"LOG: ACCELEROMETER: %ld", newValue.integerValue);
}];
}
回答1:
You are trying to log the key not the actual data that is being passed back in the completion block. E.X:
[[DJISDKManager keyManager] startListeningForChangesOnKey:IMUStateForLog withListener:self andUpdateBlock:^(DJIKeyedValue * _Nullable oldValue, DJIKeyedValue * _Nullable newValue) {
NSLog(@"%@", IMUStateForLog);
NSLog(@"%@", DJIFlightControllerParamIMUState);
}];
should look something like this:
[[DJISDKManager keyManager] startListeningForChangesOnKey:IMUStateForLog withListener:self andUpdateBlock:^(DJIKeyedValue * _Nullable oldValue, DJIKeyedValue * _Nullable newValue) {
NSLog(@"%d", newValue.integerValue);
}];
The value associate with the key you start listening on will be returned inside of the DJIKeyedValue class.
来源:https://stackoverflow.com/questions/50802931/data-values-logged-remain-unchanged-dji-uxsdkdemo