Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

motion sensor, reading rotations

I have tried this project on both android and ios with little success. There is a good chance that this stuff is just over my head. However I figured I would post my question on here as a last effort.
I'm trying to figure out when a device is rotated or flipped. My app should know when it did a 180, 360 or if the device was flipped vertically.
In an attempt to understand the way its suppose to work I tried downloading two example projects: AccelerometerGraph and CoreMotionTeapot. With these and a mix of other stuff I have figured out I was trying this:

motionManager = [[CMMotionManager alloc] init]; 
motionManager.accelerometerUpdateInterval = 0.01;
motionManager.deviceMotionUpdateInterval = 0.01;
[motionManager startDeviceMotionUpdates];

if (motionManager.gyroAvailable) {
    motionManager.gyroUpdateInterval = 1.0/60.0;
        motionManager.deviceMotionUpdateInterval = 0.01;
    [motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue]
                               withHandler: ^(CMGyroData *gyroData, NSError *error)
     {
         CMRotationRate rotate = gyroData.rotationRate;
         NSLog(@"rotation rate = [%f, %f, %f]", rotate.x, rotate.y, rotate.z);
     }];
} else {
    NSLog(@"No gyroscope on device.");
}

But I do not know how to gather the requested information(horizontal and vertical rotations) from these three values (x ,y, z).

like image 760
owen gerig Avatar asked Nov 13 '22 10:11

owen gerig


1 Answers

What you're attempting is not trivial, but is certainly possible. This video should be very helpful in understanding the capabilities of the device and how to get closer to your goal: http://www.youtube.com/watch?v=C7JQ7Rpwn2k

While he's talking about Android, the same concepts apply to the iPhone.

like image 120
quellish Avatar answered Nov 16 '22 03:11

quellish