- Home /
Linear acceleration Mobile
I am getting slightly confused with linear acceleration. I am trying to create an AR application and need to track the linear movement of a mobile device, I have tried converting the linear force into force on the axis over time but nothing I try seems to work. It seems that the linear acceleration within unity (with gravity removed) is still recording rotation, is this correct?
Here is a little segment of the code:
//Work out the velocity of X on the users acceleration
fl_Vx += (v3_PrevAccel.x + Input.gyro.userAcceleration.x) / 2.0f * Time.deltaTime;
fl_Vx = fl_Vx * Time.deltaTime;
This is just for getting the X axis it is later added to the gameobject via a translate, although it has been added as a transform.position as well but to no avail either way.
I have searched around a bit before putting this code together.
I am aware that any solution will not be perfect but if I could just have a hand sorting something out, even if there are some inaccuracies, it would be truly appreciated.
Heya Dave,
Firstly, I apologise if I post this reply in the wrong place. I tried to add a comment but don't have permissions and so have hit 'Add Reply'.
I have tried Vuforia myself already and to be honest, it's terrible. It's extremely restrictive and only works via image recognition and nothing else. Even if you manage to remove the Image Target (which I did) it just causes everything to drift as it tries to recognise the area and fails to do it accurately. I moved onto writing the AR app without Vuforia or Image Recognition as it is more suited to the company I work for (and their clients) purpose.
So, would I be correct in stating then that the input.gyroUserAcceleration is used to calculate the speed in which the device is rotated? Whilst the input.Gyro is used to calculate the current rotation of the device? Is there nothing else within the device that can be used to calculate the linear movement?
Also, the question that was specific to Unity was about what data exactly the gyro.UserAcceleration brought back. Apart from this, is there any other call to a mobile device that might be able to bring back something more suitable? I know that a 9-axis I$$anonymous$$U designed to give people real world positioning uses 3-axis Gyroscope, 3-axis Accelerometer and 3-axis magnetometers. Is there no way to do this in mobile with Unity's calls?
So if I understand what you are doing correctly, you are trying to calculate the position of the phone using only the gyro, no reference point from the camera? Be aware that the positional accuracy of this will be very low and the inaccuracies will increase over time. You may be able to get good rotational and velocity accuracy though.
The Google talk on sensor fusion is quite useful for this. You can get pretty good accuracy with respect to rotations and velocity by combining several sensors together. There's probably 3 readings that are useful (using Android as an example, but iOS will be similar):
ASENSOR_TYPE_GYROSCOPE ===> https://docs.unity3d.com/ScriptReference/Gyroscope-rotationRate.html ASENSOR_TYPE_ACCELERO$$anonymous$$ETER ==> https://docs.unity3d.com/ScriptReference/Gyroscope-userAcceleration.html ASENSOR_TYPE_$$anonymous$$AGNETIC_FIELD ==> https://docs.unity3d.com/ScriptReference/Compass-magneticHeading.html
Since we do expose all of that information, so you may be able to use sensor fusion techniques to improve the accuracy. This project looks quite interesting (not Unity specific, but maybe the code will be helpful): http://x-io.co.uk/open-source-ahrs-with-x-imu/
Here's another link which seems to have talk on this: https://groups.google.com/forum/#!topic/android-developers/GOm9yhTFZa$$anonymous$$
Thank you Dave for the information. I will look into this and comment again if there are any further questions. Also, if this proves to be the information required then I shall vote your answer as correct :)
Thanks again for the help :)
Answer by Dave-Hampson · Aug 08, 2016 at 05:03 PM
What you are describing, integrating motion using only the gyro, is very difficult. If you want something to search for try the term 'dead reckoning' which describes what you are trying to do.
The reason why this will be very inaccurate is because by converting force into velocity, and then velocity into position you are integrating twice, and any inaccuracies will be magnified.
It's a very complex topic but this is a good talk on it, Sensor Fusion / Google Tech Talks: https://www.youtube.com/watch?v=C7JQ7Rpwn2k
This is a related topic: https://en.wikipedia.org/wiki/Simultaneous_localization_and_mapping
And you might also want to check out http://www.vuforia.com/ , which is a popular augmented reality SDK.
Also, I don't think that anything in the question is specific to Unity, so you could try searching or asking on StackExchange.
Your answer
