Hello, I want to hang a low-pass filter on the gyroscope so that it does not drift. But at the output from the filter, I get NaN . I can not understand why this is happening.
Here I did like this: http://wiki.unity3d.com/index.php?title=Low_Pass_Filter
Here is my code:
private Quaternion filteredQuarternion; float lowPassFactor = 0.5f; bool init = true; void Update() { Quaternion cameraRotation = new Quaternion(Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w); filteredQuarternion = lowPassFilterQuaternion(filteredQuarternion, cameraRotation, lowPassFactor , init); init = false; this.transform.localRotation = filteredQuarternion; } Quaternion lowPassFilterQuaternion(Quaternion intermediateValue, Quaternion targetValue, float factor, bool init) { if (init){ intermediateValue = targetValue; } intermediateValue = Quaternion.Lerp(intermediateValue, targetValue, factor); return intermediateValue; } But on my output, that is, all the fields of the filteredQuarternion object are equal to NaN .
Help please, what am I doing no so? Maybe I misunderstood or missed something.