Reputation: 1000
I've been trying to find up (or down, which wouldn't be much harder to find, just multiply up by -1) on android with no good solution. I need a vector pointing up in the same coordinates system than the one used by the accelerometer. This way, I will be able to:
Gravity Sensor: First, I thought of using the gravity sensor, which would've been the simplest solution. But! my device did not have a gravity sensor...
Magnetic Field Sensor: So, I thought of using the magnetic field sensor to find two vectors pointing north at two different positions but with the same orientation, after what I calculated the cross product of both the vectors to try and find a vector pointing up or down. It didn't work (or it seemed like it didn't).
Magnetic Field with Accelerometer: Then, I thought of doing the cross product but, this time, with a vector provided by the magnetic field sensor and one provided by accelerometer. I couldn't find how to, because the accelerometer points a bit downward when the user is accelerating, because of the gravitational pull.
So, I came to the conclusion that I would need to use the orientation sensor to do so, or only to rely on a low-pass filter....
Put simply, how do I determinate what is the vector pointing up in the coordinates system used by the accelerometer if I have these sensors:
Upvotes: 4
Views: 824
Reputation: 876
The magnetic field is not horizontal, which is why your solutions with the magnetometer didn't work. This is called the magnetic dip. Generally speaking if you want to determine the up/down vector you should not rely on the magnetic field because other solutions are easier to implement and more precise.
The two main solutions to find the up/down vector are:
Good luck!
Upvotes: 1
Reputation: 12219
Unfortunately your problem isn't particularly simple. I'm not familiar enough with the Android API and perhaps if you look around you'll find something which attempts to isolate the gravity acceleration from the external device acceleration (I know there are sensor fusion algorithms that do this with some degree of success).
The core of the problem is that the acceleration due to gravity and the local acceleration on the device are indistinguishable (there is no such thing a a gravity sensor). An accelerometer simply records the total acceleration acting on the device, which is the sum of ALL accelerations. It is not trivial to isolate the gravity vector, but the methods I have seen mainly involve using the gyroscope as the magnetometer is simply too inaccurate and contains too much latency.
Instead I suggest that you either assume that the local forces on the device are negligible and therefore your acceleration IS the gravity vector. Or alternatively as you mentioned, use a low pass filter which for most purposes will suffice (and is a common way of defining DOWN for the purposes of sensor fusion and augmented reality).
All the best!
Upvotes: 3