0
\$\begingroup\$

I am working on an android app built in Unity that would allow the users to track their movements by just using the data coming from the device sensors. I have read about similar issues already and I am aware that this approach doesn't really give any good results in practice, due to the inaccuracy of the sensors, but I still need to measure the performance of this method for research purposes.

My implementation makes use of the Unity function InvokeRepeating to fetch the acceleration values at a certain rate and to then calculate the velocity and displacement by using a two step integration:

private readonly float dt = 0.001f;
private void Start()
{
    //...
    Input.gyro.enabled = true;
    Input.gyro.updateInterval = 0.001f;
    InvokeRepeating("AccelerationSample", 0.0f, dt);
}

private void AccelerationSample()
{
    Vector3 data = Input.gyro.userAcceleration * 9.81f; //Fetch the current acceleration
    lastAccel = data * kFilteringFactor + lastAccel * (1.0f - kFilteringFactor); //Apply Kalman filter
    totalAccel += data - lastAccel; //Accumulate the acceleration value

    vel = initVel + (totalAccel * dt); //Calculate the current velocity
    initVel = vel; //Update the initial velocity for the next frames

    distance += vel * dt; //Calculate the distance from the velocity value
}

The raw acceleration values are multiplied by 9.81f to match the real world acceleration (since the values coming from the gyroscope are normalized) and are filtered through a Kalman filter to reduce noise. The acceleration values are accumulated in order to take into consideration both the positive and negative parts of acceleration that the gyroscope provides when the device moves. The velocity and displacement values are then calculated using simple physics formulae.

This approach gives decent results when considering acceleration and velocity only. Though the displacement value does not seem to be updating as fast as I expected, and sometimes the calculations go completely off. Also, when the acceleration goes back to zero after any movement, the evaluated velocity does not go down to zero as well, therefore I need to find some conditions under which I can safely reset its value.

I hope I was able to properly describe the issue and that some of you might help me to revise my implementation and/or give me any hints on how I should go about the problem.

\$\endgroup\$
3
  • \$\begingroup\$ It's impossible tell with only internal forces the difference between zero velocity and any constant velocity due to the equivalence principle. You would need something like camera data to track your position. If you're okay with innaccuracy and just want something usable, you can try making the velocity exponential decay over time at some rate, like air resistance, but that would depend on your use case? What specifically are you using this for? \$\endgroup\$ Commented Jul 19, 2020 at 7:41
  • \$\begingroup\$ Thanks for your answer @qwyxivi. I am working on building an AR app that doesn't rely on camera data to track the user position, so that even featureless environments are not a problem. The idea was to solely rely on the device sensors to track movements in all directions and to use that information to place objects in the virtual map of the real world. \$\endgroup\$ Commented Jul 19, 2020 at 12:52
  • \$\begingroup\$ Ah, yeah, that's pretty much just not possible. If you load your app while your device is moving slightly, it will think that velocity is zero. The integration errors also grow exponentially over time. \$\endgroup\$ Commented Jul 19, 2020 at 17:26

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.