Reputation: 1163
I have been trying to get heading values using the getOrientation() method.
boolean success = SensorManager.getRotationMatrix(rot, incl, accel, magnet);
if (success) {
// Compute orientation
float orientation[] = new float[3];
SensorManager.getOrientation(rot, orientation);
}
These values vary wildly, even if I keep the phone steady and walk with it in a steady position.
I then tried to change the reference of my acceleration values from the phone to the world axis:
// Compute world acceleration
float wAccel[] = new float[4];
float newAccel[] = new float[]{accel[0],accel[1],accel[2], 0};
android.opengl.Matrix.multiplyMV(wAccel, 0, rot, 0, newAccel, 0);
magnetLine += "W" + LOGSEPARATOR +
tsString + LOGSEPARATOR +
wAccel[0] + LOGSEPARATOR +
wAccel[1] + LOGSEPARATOR +
wAccel[2] + "\n";
}
I then used values from the X and Y axis on an atan2 function to determine the angle of the vector. Even if varying in a different manner, these values still display strange behavior (sometimes the value is constant, other times it displays a periodical behavior, as if following the footsteps).
I have seen some instances of people calling remapCoordinate system for situations somewhat similar to this. Is this what I am missing?
Upvotes: 0
Views: 593
Reputation: 7846
Here's a couple of things that you could do:
Sensor.TYPE_GRAVITY
instead of Sensor.TYPE_ACCELEROMETER
. Sensor.TYPE_GRAVITY
is meant to try and filter out movements, and just leave you with the gravity vector.onAccuracyChanged(Sensor sensor, int accuracy)
method of the SensorEventListener
interface. I've had the same problem, and in my case it was happening when Sensor.TYPE_MAGNETIC_FIELD
was becoming SensorManager.SENSOR_STATUS_UNRELIABLE
.remapCoordinateSystem()
is to do with making 90 degree rotations in your co-ordinate system, e.g. swapping the x with z axis etc. If you were e.g. making a compass which displayed the direction of true north, then you'd need that to take account of whether your device was in portrait or landscape mode etc. However, the measurements from the sensors don't depend on portrait/landscape, so if they're varying wildly then your problem lies elsewhere.
Also note android compass seems unreliable , some people have found that the compass in Android devices isn't very good. However, that post was about 2 years ago, so hopefully things are better now :-).
Upvotes: 1