Combine Gyroscope with accelerometer to get heading
Asked Answered
S

3

6

I'm using an Android device to get the heading(azimuth, or yaw angle).

Android API used the Accelerometer value + the mganetic field to compute a matrix rotation, the azimuth is then extracted form that matrix (aka SensorManager.getOrientation(...)) But the result is very inaccurate! especially if the phone is perturbed by some magnetic stuff.

And then I have the Gyroscope, If I integrate the value of the gyro trough time, I'm able to get an actual Angle, but like everybody knows :p, this is subject to drift... after 10 seconds even tough I'm not moving the angle drifted of 10°...

So here I have in one side the result of the accel + magneto, it's quite crap near magnetic field and on the other side I have the result of the gyro that are really good, but drift over time...

So my question is, is there an easy or smart way to combine the two results together to get a kind of "robust" heading estimation? I say easy because I know there is kalman filters.. but even tough i read the theory 50 times I can't get a damn thing :).

Thank you!

Septimal answered 8/11, 2011 at 14:44 Comment(12)
There's a reason that TYPE_ORIENTATION is deprecated, and that is that it is very inaccurate :) You should be using the Gyroscope to detect movement only, and not static positions. The accelerometer is more suited to this purpose, although you are going to have to do a bit of trig. Could you edit your question to be clear about exactly you want to do? You might also check the documentation - developer.android.com/reference/android/hardware/…Compartment
I second that. As for " is there an easy or smart way to combine the two results together ?" this is already done by the sensor manager, check out the documentation Pheonixblade9 refers to.Mufinella
The Sensor Manager doesn't not combine the gyroscope and the accelerometer. It uses the accelerometer and the magnetic field to compute a rotation matrix and from that it get the heading (aka SensorManager.getOrientation(..)). So to refer at what Pheonix said, my question is How to combine the result of SensorManager.getOrientation with the integrated value of the gyro.Septimal
Combine how??? It is completely unclear what you want to do. If you want to add them, try adding them together. That should "combine them" :P /sarcasmCompartment
Combine how... yes phoenix you are starting to understand what's my question even tough it's pretty clear if you read my initial post... If you don't have the skill to answer or understand this question thanks to pass your way :)Septimal
It's not a question of skill, you are not communicating what you want to do. "Combining sensor data" could mean many, many, many things. What are you trying to do with this data? You can perform all sorts of fancy DSP stuff, convolution, multiplication, transforms... the point is, what do you want with it?Compartment
@Pheonixblade9 - I think Alexis is asking if there is any way to use both the sensor manager data and the gyroscope data to calculate the device's orientation and get a result that is more accurate than what the sensor manager or gyroscope alone could provide.Cythiacyto
Ah, well that is simple. If you have two sensors that give different types of data, if you try to combine the two, you will get a less accurate signal. That is, if you have two theoretical sensors A and B, and sensor A has an error of 2, and sensor B has an error of 3, if you combine the two you have a possible error of 1 <= error <= 5. This means that you can't be certain if you're getting an error or not. OP should use the available sensor data from the SensorManager.Compartment
@Pheonixblade9 - I think that error analysis would only apply if you were averaging the calculated orientation from both sensors. There might be more sophisticated techniques. For example, maybe the gyroscope tends to drift over time, but over short time spans is very accurate. So, if from one reading to the next, the sensor manager orientation values jumps wildly, but the gyroscope orientation doesn't change, you might want to assume the orientation has not changed, and wait for the next sensor manager reading before deciding to change the orientation.Cythiacyto
I guess I am not sure why the OP doesn't just use sensor manager - I have never had problems getting very accurate readings from the Android tutorials myself. I don't see what the problem or purpose is hereCompartment
Check out this answer. It links to another answer suggesting a Complementary Filter.Cythiacyto
Yes I know, complementary filter, I alreay had a look at that, but as far as I understood this filter only correct the pitch and roll error. Not the yawSeptimal
S
1

TO make it short:

It is not possible to combine Gyroscope + accelerometer TO GET THE AZIMUTH (I precise) Simply because the accelerometer can't sense acceleration on the XY axis..

A method would be to fuse the Gyroscope with the Compass but that won't work really good if there is magnetic pertubation

Septimal answered 6/12, 2011 at 19:27 Comment(0)
M
4

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.

Mufinella answered 9/11, 2011 at 8:50 Comment(12)
Sorry Ali but the video you are linking show a guy working at MIT, and that have developped exactly what I would like to do (almost, because he did way much more stuff). This is not included in Android in anyway... Maybe in a couple years ? But I would like to understand How he did it....Septimal
@Septimal What does the SensorManager do then? What you wrote earlier: "The Sensor Manager doesn't not combine the gyroscope and the accelerometer. It uses the accelerometer and the magnetic field to compute a rotation matrix and from that it get the heading (aka SensorManager.getOrientation(..))." is not true. Where did you find this erroneous description?Mufinella
developer.android.com/reference/android/hardware/…, float[]) So you do that SensorManager.getRotationMatrix(inR, I2,gravity2, geomag); // you pass the accel + magnetic and it computes the RotationMatrix and then you do SensorManager.getOrientation(inR,orientation) // you pass the rotationmatrix and return the orientation... No gyrosocpe involveSeptimal
You need developer.android.com/reference/android/hardware/… It gives you the orientation as a quaternion but you can convert that to a rotation matrix or to whatever you need. They API provides what you need.Mufinella
This type if I understood correctly only use the accelerometer + compass (google.com/codesearch#uX1GffpyOZk/services/sensorservice/…) I don't understand why they don't include the use of gyro, it would be some much more accurate.... But thanks anyway, I'm gonna give a try with that type and try to extract the good angle from the returned matrixSeptimal
@Alexis: have you any any success yet?Whitfield
the TYPE_ORIENTION is quit crap. For the moment I'm using a Complemntary Filter (compass+ gyro) it's ok but if there is magnetic pertubation it is a disaster :)Septimal
SensorManager does not implement any sort of filtering (I refer to magnetic, acceleration and gyroscope sensors), including Kalman filter.Integrand
@Integrand Did you check the video? If I understand correctly he is talking about the SensorManager.Mufinella
Yes. I have seen this video several times. I saw it for the first time when I was looking information about Kalman filters for my application (Steady Compass). I have spent many hours working with these topics, and even I had to write my own implementation of Kalman filter for my application. This is why I can confirm that SensorManager only gives you raw values for magnetic, acceleration and gyroscope sensors.Integrand
@Integrand Hmm, interesting. If it is so then the LINEAR_ACCELERATION in the API does not make any sense. Which version of the API did you check? Which hardware did you check?Mufinella
I agree that the new sensors do not make any sense until we have a detailed specification about their behavior. Have a look at this (coming from a Google developer). groups.google.com/forum/#!topic/android-developers/GOm9yhTFZaM In fact, I am expecting changes in future versions relating to these new sensors.Integrand
S
1

TO make it short:

It is not possible to combine Gyroscope + accelerometer TO GET THE AZIMUTH (I precise) Simply because the accelerometer can't sense acceleration on the XY axis..

A method would be to fuse the Gyroscope with the Compass but that won't work really good if there is magnetic pertubation

Septimal answered 6/12, 2011 at 19:27 Comment(0)
I
1

It seems to have a very generalized confusion about gyroscope sensor. I have recently answered a similar question here, so I recommend to anybody interested in these topics to have a look at that question and answer.

I have used the described technique in this application (a compass which integrates gyroscope readings to improve results). The result is not perfect, but is much better in general than other compasses.

Integrand answered 11/12, 2011 at 15:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.