How do I get absolute acceleration in unity? - unity3d

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.

Related

Get distance height with accelerometer

I have searched for hours now and still didn't find a definitive answer to my problem.
The scenario is this: the user throw an iPhone as high as he can and I want to measure the height that the iPhone has done.
I want to use the accelerometer with Core Motion and I successfully implemented a simple system that gives me the acceleration on the 3 axis. This is an acceleration though.
Based on my physics knowledge, the formula to calculate the maximum height is (V0^2)/2*g where V0 is the starting velocity.
I have the acceleration velocity though.
Any idea how can I convert the acceleration to velocity or directly get the velocity from my accelerometer?
I know it's not a completely programming related question, but I just want to have some help on this :)
First of all there is alredy an app that does exactly what you are up to: Send Me To Heaven. You won't find it in Apple's App Store because it never passed the review, guess why ;-)
As you stated you only have access to accelerations. h = v02/(2*g) is correct. To get the starting velocity v0 you need to integrate the acceleration numerically over the time. The trickiest part will be to find necessary and sufficient conditions to determine the time interval [t1, t2]. When did the acceleration phase start and when did it stop.
Another thing to consider is to avoid cheating users who just perform a rotation around there axis for a couple of seconds, then simulate the flying phase. There you might consider the landing phase too: when the user grabs the device you should register a strong deceleration.
However, don't expect this app to ever get in the store and at Google Play the competitors were faster.
Problems:
There's a number of problems physics impose on you (other than the velocity), to get the result.
The angle of the throw, relative to the direction of gravity. You cant know the relative vertical distance, unless you know this angle.
Orientation of reference throughout the throw (you cannot deduct the speed from the acceleration, from the device itself, unless you account for the changes in rotation while the phone accelerates).
However! You can decide to assume certain things, which will make these annoying problems go away!
Reasonable assumption:
The device is caught again, at the same relative height it was thrown.
This assumption reduce the problem to a much simpler one, in which we only really need to find the duration of time, where the device is in free fall, in order to determine the relative height of the throw.
All you have to do:
To determine if the device is in free fall, is relatively easy, since the total gravity would be near 0 m/s^2.
However, there's still one smallish problem to this, because the accelerometer is probably not located at the center of mass of the phone, so it will experience a constant acceleration (if the phone rotates around itself) in exactly one particular direction, throughout the free fall.
The maths of determining the height of a vertical throw, based on the airtime duration is left as an exercise to the reader :-)

accelerometers uses- smartphone

It is known that the raw accelerometer data is combination of both linear acceleration and gravity. In order to isolate them w need to apply appropriate filters. I would like to know the real time applications where we would need only "gravity" or only "linear acceleration".
Gravity is used when you are trying to figure out the orientation of the phone. In other words, when you are trying to figure out how the user holds the phone. It is good for tilt games, for example you use the phone to drive a car, etc.
Linear acceleration is used when you are trying to figure out how the phone is shaken. It good for shaking games.
I highly recommend this video. In particular, between 4:15-6:10 and staring from 33:30 you see demos.

Android/ iOS how to determine small changes in distance using sensors?

I have been doing a bit of research, but I cannot seem to find a way to determine small distances (centimeters and meters) using the sensors in Android or iOS devices.
Bluetooth appears too inaccurate and require more than one device, GPS only works over larger variations in distance, and small variations in rotation seem to make using the accelerometer nearly impossible.
Is there a method that I am unaware of that would allow me to do such a thing? I am familiar with Calculus, so using Integrals to determine distance based on changes in time and velocity/ acceleration is not a problem for me, I just do not know how to determine those things.
Thank you.
There's no sensor in these devices which is able to give you the desired accuracy without exterior help.
If your use case allows for a bit of external setup, here are some ideas:
You could use the camera and computer vision to calculate device movement. You could, for example, use ARToolkit to measure the distance to a visual tag fixed to a wall. In close distances you can get pretty high accuracy (mm) using this technique.
Another idea would be to measure the distance to a solid object, like a wall, by emitting a short audio signal using the speaker and measure the time until the echo arrives at the microphone. This would be more of a research project, though.
You CAN use the accelerometer to measure distance travelled
(if ONLY absolute displacement is involved).
Have the user hold the device flat and walk from pointA to pointB.
The user presses a "Start" button in ur app as he starts from A and
presses an "End" button in ur app as he reaches B.
Calculate the double-intergral of AccelX & AccelY seperately over time
between the 2 button presses. These will be distX & distY respectively.
Total displacement will be sqrt( (distXsquared) + (distY squared) ).
GoodLUCK!!
Regards
CVS#2600Hertz
Just as a thought experiment, you should be able to do this using a combination of the accelerometer and the compass on each device.
However, whether the accuracy of these sensors is enough for what you want to do...well I think you'd just have to try it.

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.

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.