Search code examples
iosiphonecore-motionmotionuiaccelerometer

How to get Acceleration Time & Acceleration Magnitude in iPhone


Currently I'm trying to use CMAcceleration to get accelerometer values for x,y& z axis is it possible to get Acceleration Time & Acceleration Magnitude with this x,y & z values.When i checked the developer forum i can't find any delegates / methods to get this two.Guide me to find the values. Using the following code:

    int updatesensorFrequencyInterval = [sensorFrequencySliderTxt.text intValue];
self.motionManager.accelerometerUpdateInterval = updatesensorFrequencyInterval;
self.motionManager.gyroUpdateInterval = updatesensorFrequencyInterval;
[self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
                                         withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
                                             [self outputAccelertionData:accelerometerData.acceleration];
                                             if(error){
                                                 NSLog(@"%@", error);
                                             }
                                         }];

Solution

  • The x,y,z values of CMAccelerometerData acceleration struct are magnitudes in m/s^2.

    CMAccelerometerData is a subclass of CMLogItem, so it inherits the timestamp property which provides the NSTimeInterval since the phone was booted. This can be used to measure elapsed time between any pair of samples.