Combine Gyroscope with accelerometer to get heading - android

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!

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.

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

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.

Related

Kalman filter sensor fusion for FALL detection: Accelerometer + Gyroscope

I am trying to understand the process of sensor fusion and along with it Kalman filtering too.
My goal is to detect Fall of a device using Accelerometer and Gyroscope.
In most of the papers such as this one, It mentions how to overcome drift due to Gyroscope and noise due to Accelerometer. Eventually the sensor fusion provides us with better measurements of Roll, Pitch and Yaw and not better acceleration.
Is it possible to get better 'acceleration results' by sensor fusion and in turn use that for 'Fall detection' ? As only better Roll, Yaw and Pitch are not enough to detect a Fall.
However this source recommends to smoothen Accelerometer (Ax,Ay,Az) and Gyroscope (Gx,Gy,Gz) using Kalman filter individually and using some classification algorithm such as k-NN Algorithm or clustering to detect Fall using supervised learning.
Classification part is not my problem, it is if I should fuse the sensors(3D accelerometer and 3D gyroscope) or smoothen the sensors separately, with my goal of detecting a fall.
Several clarifications
Kalman Filter is typically to perform sensor fusion for position and orientation estimation, usually to combine IMU (accel and gyro) with some no-drifting absolute measurements (computer vision, GPS)
Complimentary filter, which is typically used to have good orientation estimation by combining accel(noisy but non-drifting) and gyro(accurate but drifting) . Using accel and combine with gyro, one can have fairly good orientation estimation. The orientation estimation you can see as primary using the gyro, but corrected using accel.
For the application of Fall detection using IMU, I believe that acceleration is very important. There is no known way to "correct" the acceleration reading, and thinking of this way is likely to be the wrong approach. My suggestion is to use accelerations as one of your inputs to the system, collect a bunch of data simulating the fall situation, you might be surprised that there are a lot of viable signals there.
I dont think you need to use KF to detect fall detection. Using simple Accelerometer will able to detect the fall of device. If you apply low pass filter to smooth accelerometer and check if total acceleration is close to zero (in free fall device is going with -g (9.8 m/s2) acc) for more than certain duration, you can detect as fall.
The issue with above approach is if device is rotating fast then acceleration wont be close to zero. For robust solution, you can implement simple complementary (search for Mahony) filter rather than KF for this application.

Sensor Fusion of Accelerometer and Gyroscope in Unity 3D

I am trying to use the phone as a gun aiming with the gyroscope. I calibrate with the phone or tablet in a certain orientation. This will shoot straight. Then depending on the direction the phone is turned (left/right/up/down.), the gun shoots in that direction.
I am using the gyroscope. And all this works. Except after shooting for about 30 secs, the gyroscope slowly starts drifting towards left or right. So when I go back to the orientation I calibrated with, it doesn't shoot straight anymore. Does anyone have any experience writing a Complementary or Kalman Filter to fuse gyro and accelerometer data to give better results in Unity 3D?
I've found this online - http://www.x-io.co.uk/open-source-ahrs-with-x-imu/. It seems to do exactly what I want. But I am using it wrong. I sometime get better and sometimes get worse results with. Anybody have any experience with it ?
First place, Gyro/accelerometer fusion will stabilize your pitch/roll angles, since gravity indicates in which direction ground is. However, you cannot correct "left/right" drift because actual heading is unknown. Getting proper heading stabilization cannot be achieved with gyro/accelerometer alone: it requires additional information.
The example you provide (Madgwick’s MARG/IMU filter) is a filter that can integrate magnetometers ("north" reference), but it has two requirements for getting good results:
The magnetometer has been properly calibrated.
There are no magnetic field disturbances. This is generally not true if you are indoors, or if you are moving close to power lines or metallic structures.
An alternative is using a video signal to get optical flow information, or detecting if the phone is resting in a fixed position to compensate gyro biases from time to time.

How to/Should I implement a Kalman filter to get accurate Accelerometer data?

I want to get as accurate data from the built in accelerometer in an Android phone as possible. I want to track two dimensional movement in x and y axis and even the small movements must be registered.
When I look at the data from the accelerometer / linear acceleration when the phone is flat on a table it changes a lot when i should be zero.
I have looked at Kalman filters, it seems like a good approach but I am having problems setting up a model.
1. Is a Kalman filter the way to go to get as accurate data as possible from an accelerometer?
2. Will a Kalman filter work? Maybe i have misunderstood but it seems like the acceleration or the velocity must be constant?
3. How do I set up the model for using Kalman filter? I'm having trouble understanding (among other things) what the process noise is?
A Kalman filter applies when all measurements (of acceleration in this case) are equal to the true value plus a measurement error. The measurement error is the process noise. For for the original Kalman filter to apply the noise must be normally distributed, i.e. sometimes the error will be positive, sometimes negative, and on average zero.
If you jerk your android phone quickly back and forth, there'll be large accelerations. I'd suggest recording the accelerometer readings in that kind of action, and reviewing by eye to see whether it looks like there's the readings are indeed subject to some kind of normally distributed process noise. My guess is that the answer will be "No", i.e. I expect they readings when plotted on a graph will be smooth-ish. But if they're not smooth, a Kalman filter could be useful.
If you're trying to use accelerometer readings to work out location, I think your project is doomed to failure. Acceleration is the 2nd derivative of position with respect to time, and I've never heard of anyone being able to integrate the readings with sufficient accuracy to be at all useful.
I have applied a Kalman filter successfully to GPS readings on an Android phone to improve the location estimate. See Smooth GPS data for code that implements a Kalman filter for that. I subsequently wondered whether velocity and perhaps acceleration data could be used to improve the location estimate. Although I never followed up on that idea, see https://dsp.stackexchange.com/questions/8860/more-on-kalman-filter-for-position-and-velocity for the maths that I was considering using.
The optimal way of using all the sensor inputs (GPS, accelerometer, gyroscope, etc) to get a good estimate of location is a very hard (and interesting) problem. To find out more, the key phrase to search for is "Sensor fusion". On this subject, there's an old youtube video at http://www.youtube.com/watch?v=C7JQ7Rpwn2k .
You might find this thread useful. I came across the same issues
We think the variance when lying flat might be an issue with Gimbal lock confusing the calculations but thats just a theory right now. We've also noticed the covariance in each axis alters depending on the orientation of the device, which might be gimbal lock interference too, but again just a theory
Implement a Kalman filter to smooth data from deviceOrientation API

Indoor tracking (IMU + tags)

this is another question about indoor tracking using inertial (smartphone + aceel + gyro)
Firstly, I would like to say that I have read almost every post on stackoverflow talking about this subject.
And I know that to track a position We will have to integrate TWICE the accel and that is very useless in a real life application because of all the drift errors...
But it turned out that I don't need to build a plane or whatever And i don't need to develop an application that have to WORK to be sold or something. I just want to realize a simple Android App that use "theoretical" concept of an Indoor tracking-
What's the possibilities?
What do we need?
Basically my phone is resting on a desk screen facing UP at a known position (0,0) if a push my phone to 2 or 3 meters and then I rotate it and push it again for 2 or 3
meters I the to see after how many meters it becomes to inaccurate an so use a tag tu recalibrate the measurements <--- That's my main question
what do I need ?
- the angle ? (ok integrating the the gyro) (i don't wanna use the compass)
- the accel? (i have)
- the velocity ? (integrating the accel)
- and the position (double accel integration)
The thing that I would like to know is How can I put this number together? Is it the right way to do it? Is there another solution (to resolve my problem, not to track someone really accurately)?
I also looked at the theory of the DCM (If I understood correctly, it will give me the orientation of the phone in 6 axes right? But what's the difference about getting the angle from the Accel or the gyro (pitch, roll etc..) ?
Thank you
Your smartphone probably has a 3-axis gyro, a 3-axis magnetometer and a 3-axis accelerometer. This is enough for a good estimation of attitude. Each has its advantages and disadvantages:
The accelerometers can measure the gravity force, it gives you the attitude of your phone, but in a horizontal position, you can't know where it's pointing. And it's very sensitive to inertial noise.
The gyroscopes are fastest and the most accurate, but its problem is the drift.
The magnetometers don't have drift and they aren't sensitive to inertial forces, but are too slow.
The combination of the three give you all advantages and no disadvantages. You must read the gyro measure faster as you can (this minimizes the drift) and then use the slow and not as accurate measure of magnetometer and accelerometer to correct them.
I leave you some links that may interest you:
A Guide to using IMU: http://www.starlino.com/imu_guide.html
DCM tutorial: http://www.starlino.com/dcm_tutorial.html
I hope I've been helpful and sorry for my bad English.
With the sensors you have, not considering computational power at this point yet, I know of only one method of position / displacement estimation. This would either involve just optical flow with the onboard camera, or the above with addidional info from fused data from accels / gyros (eg. with a Kalman-Filter) to improve accuracy. I guess OpenCV has all you need (including support for Android), so I'd start there.
Start by implementing an attitude-estimator with just accels and gyros. This will drift in yaw-axis (ie. the axis perpendicular to the ground, or rather parallel to gravity vector). This can be done with a Kalman-Filter or other algorithms. This won't be any good for position estimation, as the estimated position will drift tenths of meters away in just a couple of seconds.
Then try implementing optical flow with your camera, which is computationally expensive. Actually this alone could be a solution, but with less accuracy than with additional data from an IMU.
Good luck.
EDIT: I recently found this - it may be helpful to you. If there is not a lot of noise (due to vibration), this would work (I'm on a quadrotor UAV and it unfortunately doesn't work for me).

Accelerometer and Gyrometer Data

I'm using the Android SDK (2.2) with a Droid and I have access to the 3-axis accelerometer and gyrometer.
I apologize in advance if this reveals my ignorance of physics. It has been awhile.
What I don't understand is why the accelerometer is giving different x,y,z values when I tilt the phone. It's standing still, at least, with negligible acceleration and even mostly constant velocity, it's just tilted. I thought that this was the gyrometer's job?
I don't want gravity in the equation...I just want the other forces affecting the phone. Everything had better be 0,0,0 unless I'm moving it faster. I want to know how hard I hit the phone on the table, and the direction and magnitude of the x,y,z forces when I do so. So far, I am confused beyond belief about how to access this with the accelerometer and gyrometer data. I'm trying to take the gyrometer as the direction and the accelerometer as the magnitude. Unfortunately, the data for those aren't really in sync (I have to setup two events to get each pair of data, and they may come at different times), but it might be good enough to just buffer them and assume some sort of synchronization.
Desperate,
Andrew
I'm afraid that's just how accelerometers work, here on earth there will always be 9.8 Gs pointing at the ground.
If you can assume that you have a working compass, just take a vector of length STANDARD_GRAVITY, rotate with the current orientation taken from the magnetometer and subtract this from your accelerometer's vector.
Keep in mind that you should also dampen the values you get back from the accelerometer, use a running average of the last few values.

Categories

Resources