How to find global direction using sensors? - accelerometer

I use an AR glass. It has some sensors such as gyroscope, accelerometer, imuOrientation and magnetometer.
I try to find real world direction(south, north etc) and position(looks sky or ground). How can I get them?

You have magnetometer so you can use it get directions. You may need to combine it with gyroscope. It will also be handy to get position

Related

How do I get absolute acceleration in unity?

I want to define a coordinate system when unity starts based on the phone, but then have that stay constant forever on after, so that when I then measure acceleration, it disregards how the phone is tilted (where it is facing) and instead just measures how it is moved. Is there an api for this? The normal Input.acceleration or gyro doesn't work.
Using Gyroscope.userAcceleration; is the possible solution. It measures the acceleration that user provides to the device i.e, it discards the effect of gravity.

Detecting the user's spinning motion

I have been experimenting with the Core Motion framework to detect a user spinning around, say on a merry-go-round, holding an iphone in his hand.
There are ways to detect the device motion around its own axes, but what is a good way to detect the iPhone spinning in circles?
Thanks
You can use the gyroscope. Take a look here: Gyroscope example
You have to remind that it is only availble on iPhone4 and iPhone4S.
There is one degenerate case where you can run into trouble, only magnetometer (compass) can help in that particular case.
If you put the device (a) on the desk in stationary position then (b) on a perfectly horizontal turntable rotating slowly you will get the same qualitative sensor readings. Both the gyro and the accelerometer readings are constant in the two cases, although the readings quantitatively differ. The sad part is: gyro bias error can render case (a) to look like (b) and vice-versa. In this particular case you need a compass to cancel the gyro drift. Case (a) is typical for a phone.
Apart from this degenerate case, gyroscopes and accelerometers with sensor fusion are sufficient to track arbitrary rotations of the device.

How to get velocity from variable accelerometer(in simple linar motion)?

I want compute the current iphone motion velocity anytime based on accelerometer, the accelerometer is variable. Anyone can give any idea?
It's basically impossible. The only way is to integrate the acceleration, but that magnifies the inaccuracy of the iPhone's not very accurate accelerometer, and because you don't have an independent orientation sensor (the iPhone uses gravity to figure that out!), you can't distinguish lateral acceleration from tilting the phone.
How people do this in the real world is to measure velocity using something else like GPS, and use the accelerometer to interpolate.

iPhone 4 Gyroscope/GPS versus Accelerometer/GPS/Compass

I am about to use iPhone 4's gyroscope/GPS on a game, to detect rotation and translation. As far as I know, the gyroscope can be used to detect rotations in all 3 axis.
But rotations, at least on the horizontal plane can be detected with the compass, tilts can be detected with the accelerometer and positions with the GPS.
Can a combination of compass/accelerometer/GPS create the same level of detection of gyroscope/GPS? (I am thinking of allowing this combination for people without iPhone 4).
Will this work perfectly?
The precision of the gyroscope and accelerometer sensors is much greater than the precision of the compass and GPS. The compass and GPS are for finding out where the device is on the globe, and the gyroscope and accelerometer are good for finding out where the device has moved in the last few milliseconds.
Therefore it depends upon what you're trying to control with the device's movement. Trying to simulate a gyroscope input to control a 3D simulation (like the Jenga game Jobs showed in the keynote that introduced the iPhone 4) will not work perfectly with just the compass/accelerometer/GPS. Figuring out if the device is pointed at the grocery store on the west side of the street instead of the furniture store on the east side of the street in an augmented reality game will work perfectly with just the compass/accelerometer/GPS.

Transform device orientation to world frame in objective c

I'd like to transform the yaw, pitch and roll of the iPhone from the body frame to the world frame, i.e. azimuth, pitch and roll. On Android this is easily done with the
SensorManager.remapCoordinateSystem(), SensorManager.getOrientation methods as detailed here: http://blog.mysticlakesoftware.com/2009/07/sensor-accelerometer-magnetics.html
Are similar methods available for the iPhone or can someone point me in the right direction how to do this transformation?
Thanks
The accelerometer is good enough to get gravity direction vector in device coordinate system. That is in case when device calms down.
The next step for full device orientation is to use CLLocationManager and get the true north vector in device coordinate system.
With the normalized true north vector and gravity vector you can easily get all other directions using the dot and cross vectors product.
The accelerometer (UIAccelerometer) will give you a vector from the device's accelerometer chip straight down. If you can assume that the device is being held fairly steady (i.e., that you're not reading acceleration from actual movement), then you can use simple trig (acos(), asin()) to determine the device's orientation.
If you're worried that the device might be moving, you can wait for several accelerometer readings in a row that are nearly the same. You can also filter out any vector with a length that's ± TOLERANCE (as you define it) from 1.0
In more general terms, the device has no way of knowing its orientation, other than by "feeling gravity", which is done via the accelerometer. The challenges you'll have center around the fact that the accelerometer feels all acceleration, of which gravity is only one possible source.
If you're targeting a device with a gyroscope (iPhone 4 at the time of writing), the CoreMotion framework's CMMotionManager can supply you with CMDeviceMotion updates. The framework does a good job of processing the raw sensor data and separating gravity and userAcceleration for you. You're interested in the gravity vector, which can define the pitch and roll with a little trig. To add yaw, (device rotation around the gravity vector) you'll also need to use the CoreLocation framework's CLLocationManager to get compass heading updates.