I am using LG Optimus 2x smartphone(Gyroscope and Accelerometer sensor) for positioning.
I want to get correct rotation angles from gyroscope that can be used later on for body to earth coordinate transformation. My question is that
How I can measure and remove the drift in gyro sensor.
The one way is to take the average of gyro samples (when mobile is in static condition) for some time and subtracting from current sample, which is not good way.
When the mobile is in rotation/motion how to get the drift free angles?
Basically gyros drift over long time periods. Whereas accelerometers have no drift but tend to be unstable. By combining information from both sensors using a Kalman filter you can obtain a accurate attitude. For some this less complex you could also use a Complementary Filter.
See this post for more info: Combine Gyroscope and Accelerometer Data
As far as I know, either the Kalman filter or something similar is implemented in the SensorManager. Check out Sensor Fusion on Android Devices: A Revolution in Motion Processing.
You are trying to solve a problem that is already solved.
I am the author of a compass application that integrates data from magnetic and gyroscope sensors (steady compass). I have tested this application mostly on a LG Optimus black (the device that you can see on the video) running Android 2.2, so I am going to share my experiences:
Be careful with LG phones: According to the Android API, gyroscope will return data in rad/s. The LG Optimus Black with Froyo gives readings in degrees/s. The update to Android 2.3 has just been released for such phone. I have to test whether the new version behaves according to the specifications.
What Android version does your phone have? Have you tested any application using gyroscope? Did you get the expected results?