Augmented Reality Code Example Using a Gyro

Morning

I hunted around StackOverFlow for about an hour and found many code examples (mostly github) for creating Augmented Reality applications that display where the second location refers to your current location (for example, in New York).

However, I noticed that none of them uses the gyro functionality provided in the iPhone 4, which gives end users a much smoother character.

Does anyone know if such an example code example exists?

Greetings

Charlie

+6
iphone augmented-reality gyroscope
source share
3 answers

Unfortunately, I do not know the code.

A problem common to all AR applications is that you need to know the orientation of your device. You can do this with atan2 and the accelerometer, but it has an unholy amount of noise (as shown in the Apple AccelerometerGraph example). If you try to fix this with an adaptive low-pass filter, you will reduce the noise, but you will also make it less responsive.

The gyro has no noise, but the error accumulates fast enough so that you constantly reset the accelerometer. It seems like a good turn of the object, but not for replacing the compass.

0
source share

You can definitely use CoreMotion to get data from the gyro. The main approach would be to get the CMAttitude.rotationMatrix and multiply its inverse (transpose) by the reference matrix that you originally installed. The sample Teapot project on developer.apple.com shows a basic approach to working with CoreMotion.

For a real augmented reality application, you will need to create a model using OpenGL ES. I personally found v1.1 more reliable in iOS by trying GL ES 2.0. The Kettle sample also uses GLES 1.1.

Using a gyroscope is much more accurate and "smooth" than using a Magneotmeter to get a rotary device around its reference axis. The trick is how to initially calibrate the reference matrix to get the true β€œtitle” of the device and place the GL ES model objects in the correct position around the camera. Once you have achieved this, you can rotate your model in 3D by multiplying the GL viewMatrix by the back of CMAttitude.rotationMatrix.

Finally, if you intend to support iPhone 3Gs, then be sure to check the gyroAvailable CMMotionManager property and provide an alternative implementation using a magnetometer.

+3
source share

You can try using instance methods of CMMotionManager

startDeviceMotionUpdatesToQueue:withHandler: or startGyroUpdatesToQueue:withHandler:

  [CMMotionManagerObject startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^ (CMDeviceMotion *devMotion, NSError *error) { CMAttitude *currentAttitude = devMotion.attitude; xRotation = currentAttitude.roll*180/M_PI; yRotation = currentAttitude.pitch*180/M_PI; zRotation = currentAttitude.yaw*180/M_PI; }]; 

If you use startGyroUpdatesToQueue:withHandler: you can get the result through the gyroData property

+3
source share

All Articles