Android getrotationmatrix donnant 0 pour toutes les valeurs
-
29-10-2019 - |
Question
J'essaie d'utiliser un champ magnétique et un accéléromètre pour calculer l'orientation. Cependant, l'AZ, Pitch and Roll calculé sont 0. Voici le code:
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
Log.e(TAG, "Sensor Changed");
float[] r = new float[9];
float[] i = new float[9];
float[] accValues = new float[3];
float[] geoVallues = new float[3];
}
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
Log.e(TAG, "Accelerometer Changed");
accValues = event.values.clone();
}
if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
Log.e(TAG, "Magnetif Field Changed");
geoVallues = event.values.clone();
}
if (accValues != null && geoVallues != null) {
SensorManager.getRotationMatrix(r, i, accValues, geoVallues);
float[] v = new float[3];
SensorManager.getOrientation(r, v);
oriView.setText("Orientation:\nAz=" + Math.toDegrees((v[0])) + "\nPitch=" + Math.toDegrees((v[1])) + "\nRoll=" + Math.toDegrees((v[2])));
}
}
Une idée de ce qui ne va pas?
La solution
essaye ça
boolean success = SensorManager.getRotationMatrix(
matrixR,
matrixI,
valuesAccelerometer,
valuesMagneticField);
if(success){
SensorManager.getOrientation(matrixR, matrixValues);
double azimuth = Math.toDegrees(matrixValues[0]);
double pitch = Math.toDegrees(matrixValues[1]);
double roll = Math.toDegrees(matrixValues[2]);
readingAzimuth.setText("Azimuth: " + String.valueOf(azimuth));
readingPitch.setText("Pitch: " + String.valueOf(pitch));
readingRoll.setText("Roll: "+String.valueOf(roll));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow