I am using android 2.3 on Nexus S and want to get orientation from gyroscop开发者_JS百科e sensor events. As gyro gives angular velocity how to use this for getting device orientation ?
Also is there any way we can get pure linear accelerations on phone's axis, without gravity vector. I expected this from Linear acceleration sensor event but just found a post and referred android source as well for Sensor which currently uses only accelerometer.
So what's the best way to combine the readings from both hardware to get pure accelerations without gravity inclusions ?
Thanks.
Why do you specifically want to get orientation using the gyro, the supplied getOrientation(), or getRotation() in later [2.2+] API, should be a simpler way. In any case the gyro is only useful for detecting changes in angular orientation, so it can't tell you which way is up, if that's what you mean by 'orientation'.
But you can get your approximate change in angle from angular velocity in the same way you would get change in position from linear velocity: change in angle = time interval x angular velocity.
Gravity is equivalent to an acceleration, so there is no way to tell them apart from 'inside the phone', you will just have to subtract it out in the way described by the documentation.
精彩评论