[Gyro] unexpected rotations and offset
Hi,
I recently started a project in Unity 5.0.1 with AR glasses running on Android. I'm facing issues with the built-in gyro.
link:Code of the headtracking class from SDK
Basically, when I start my app everything is fine until Update gets called. From this point, the first "actual" orientation is given by gyro.attitude and it's never a Quat(0,0,0,0) at the beginning. It is always an accurate rotation around x and z axis, and a random rotation around y.
As I said, it happens once Update is called, everything is fine with Start(). If the first angle around y was always the same I would be able to negate it, but I cannot predict it.
Also, I can't add an offset because in Start() gyro.attitude will always returns Quat(0,0,0,0). It's like the gyro is not reading its orientation yet even though gyro.enabled have been set true, thus I cannot set an initial attitude.
Moreover, the gyro rotates around y with a random angle betwen 1° & 180° after one of the following condition is (randomly) met:
- App have started for about 2 or 3 seconds
- Gyro rotated 45° or more
- Angle between attitudes of previous and current frames is high enough
This happens only once, but it shouldn't and I can't figure out why it is doing so, nor how to prevent it.
Can somebody enlighten me on what's wrong and what I should do please? I have tried many fixes, none of them worked, and I couldn't find this kind of issue on the internet.
I also tried to use rotationRateUnbiased instead of attitude, but there are too much reading errors to get a reliable result.
Answer by raynertanxw · May 02, 2016 at 12:20 AM
With regards to the gyroscope not reading its orientation at Start, I get the same problem too. Perhaps a solution would be to have a sort of loading screen, then just before the transition to your actual gyroscope-camera controlled scene have the game read and store the gyroscope quaternion, which should be awake and reading in this loading scene by now. So when you gyroscope scene loads it can read off that initial value as an offset.
Sorry but I have not encountered the other problem about the gyro randomly rotating between 1˚ and 180˚. It could be a device specific thing? Like my device can sometimes have the gyroscope not read until 1-2min after launch.
And I recommend never using rotationRate/rotationRateUnbiased as overtime, I think the errors from rounded off deltas would add up and slowly rotate your gyroscope away, etc. I recommend using gyroscope.attitude
If you would like to use it, my friends and I wrote a free toolset to make setting up the gyroscope easier. You can find it here: https://github.com/Daburu/Daburu-Tools/wiki/API-(DaburuTools.Input) ^ I know our code to be working, just have to set your project to Landscape-Right. We also have a SnapToPoint
function to center the camera (with regards to y-rotational axis). Hope it helps.
Answer by Thugann · May 04, 2016 at 01:37 PM
Hi there, thanks for answering.
My issue have never been encountered anywhere, so I just sent the device back. Hopefully I'll get it back repaired or replaced.
As for the orientation at start, I solved this with a coroutine waiting for 1 second before actually setting the right view.
Thanks for the link, I'll dig into it if I get my device back and still have issues using it. :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612070430im_/https://answers.unity.com/themes/thub/images/avi.jpg)