2016-09-21 7 views
0

iPhoneの速度と角度をGyro + Accelerometerで取得したい。ここにGPSは必要ありません。歩いている人がiPhoneを持っていれば、人々の動き情報を得ることはできますか?iPhoneのGyro + Accelerometerで何が得られますか?

どのようにこの問題にアプローチする必要がありますか?

答えて

0
#import <UIKit/UIKit.h> 
#import <CoreMotion/CoreMotion.h> 




@interface ViewController : UIViewController{ 
     CMMotionManager *motionManager; 
     NSOperationQueue *operationQueue; 
     NSTimer *timer; 
    } 

@property (weak, nonatomic) IBOutlet UILabel *accelerationX; 
@property (weak, nonatomic) IBOutlet UILabel *accelerationY; 
@property (weak, nonatomic) IBOutlet UILabel *accelerationZ; 
@property (weak, nonatomic) IBOutlet UILabel *pitchLabel; 
@property (weak, nonatomic) IBOutlet UILabel *yawLabel; 
@property (weak, nonatomic) IBOutlet UILabel *rollLabel; 
@end 

//.m の#import "ViewController.h"

@interface ViewController() 

@end 

@implementation ViewController 
@synthesize accelerationX; 
@synthesize accelerationY; 
@synthesize accelerationZ; 
@synthesize rollLabel; 
@synthesize pitchLabel; 
@synthesize yawLabel; 

#define degrees(x) (180 * x/M_PI) 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    motionManager = [[CMMotionManager alloc]init]; 
    motionManager.deviceMotionUpdateInterval = 1; 
    [motionManager startDeviceMotionUpdates]; 
    timer = [NSTimer scheduledTimerWithTimeInterval:(1) target:self selector:@selector(read) userInfo:nil repeats:YES]; 

    if([motionManager isGyroAvailable]){ 
     if(![motionManager isGyroActive]){ 
      [motionManager setGyroUpdateInterval:1.0]; 
      [motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMGyroData *gyroData, NSError *error){ 
       accelerationX.text = [[NSString alloc]initWithFormat:@"%0.2f", gyroData.rotationRate.x ]; 
       accelerationY.text = [[NSString alloc]initWithFormat:@"%0.2f", gyroData.rotationRate.y ]; 
       accelerationZ.text = [[NSString alloc]initWithFormat:@"%0.2f", gyroData.rotationRate.z ]; 
      }]; 
     } 
    } 
    else{ 
     NSLog(@"No Gyro"); 
    } 
} 


- (void)read{ 
    CMAttitude *attitude; 
    CMDeviceMotion *motion = motionManager.deviceMotion; 
    attitude = motion.attitude; 

    yawLabel.text = [NSString stringWithFormat:@"%f", degrees(attitude.yaw)]; 
    pitchLabel.text = [NSString stringWithFormat:@"%f", degrees(attitude.pitch)]; 
    rollLabel.text = [NSString stringWithFormat:@"%f", degrees(attitude.roll)]; 


} 
+0

ありがとう:)しかし、それはそれに対処する方法を、device.Ifの人々の移動情報は、iPhoneを運ぶことです人の動き情報として? –

関連する問題