我正在进行研究以使设备上下移动。我真正需要的是,当用户通过车辆移动时,我想确定设备是否持续上下(在刚性道路上)。我试着用Core motion陀螺仪做这件事。
self.motionManager = [[CMMotionManager alloc] init];
//Gyroscope
if([self.motionManager isGyroAvailable])
{
/* Start the gyroscope if it is not active already */
if([self.motionManager isGyroActive] == NO)
{
/* Update us 2 times a second */
[self.motionManager setGyroUpdateInterval:1.0f / 2.0f];
/* Add on a handler block object */
/* Receive the gyroscope data on this block */
[self.motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue]
withHandler:^(CMGyroData *gyroData, NSError *error)
{
NSString *x = [[NSString alloc] initWithFormat:@"X: %.02f",gyroData.rotationRate.x];
self.xAxisLabel.text = x;
NSString *y = [[NSString alloc] initWithFormat:@"Y: %.02f",gyroData.rotationRate.y];
self.yAxisLabel.text = y;
NSString *z = [[NSString alloc] initWithFormat:@"Z: %.02f",gyroData.rotationRate.z];
self.zAxisLabel.text = z;
}];
}
}
最好的方法是什么?如何用陀螺仪解决这个问题?