Reputation: 53
I am trying to implement "dead reckoning" using IMU in my Unity project. Currently I can't get good results: the velocity gets negative, so the character moves backwards, or the character sometimes comes forth and back after moving IMU just forward. I suspect the frequency of script being called is not as high as IMU data sending frequency or my script is incorrect. Is there a way to make the method/script called more often? Or is there something I'm doing wrong in the code:
/// <summary>
/// This is the coroutine called in the start Method. It keeps running in the background and keeps track of the user making steps.
/// </summary>
/// <returns>WaitForSeconds</returns>
IEnumerator StepcounterLeft()
{
float prev_zVel = 0;
float prev_zAcc = 0;
for (var a = 0; a < 1;)
{
yield return new WaitForSeconds(0.0001f);
float zAcc = (float)vn100l.CurrentMeasurements.LinearAccelerationBody.Z;
float zVel = prev_zVel + (prev_zAcc + ((zAcc - prev_zAcc)/2.0f)*Time.deltaTime);
if (zVel > -0.1 && zVel < 0.1)
zVel = 0;
speed = zVel / 10;
prev_zVel = zVel;
prev_zAcc = zAcc;
if ((zAcc > -0.1 && zAcc < 0.1) && (prev_zAcc > -0.1 && prev_zAcc < 0.1))
prev_zVel = 0;
}
}
Upvotes: 1
Views: 488
Reputation: 53
Making a new thread through System.Threading provided speed of 0.001 seconds. To read all the values from accelerometer I would need speed of 0.000008 seconds, but seems like this is as fast as it can reach.
Upvotes: 0